• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UserViewModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UserViewModel的典型用法代码示例。如果您正苦于以下问题:C# UserViewModel类的具体用法?C# UserViewModel怎么用?C# UserViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UserViewModel类属于命名空间,在下文中一共展示了UserViewModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PopulatePhoneNumbers

        public static bool PopulatePhoneNumbers(UserViewModel uvm, HttpRequestBase request, out string validationError, out string flashErrorMessage)
        {
            flashErrorMessage = null;
            validationError = null;

            if (uvm == null || request == null)
                return false;

            // Find and (re)populate phone numbers.
            foreach (var phoneKey in request.Params.AllKeys.Where(x => x.StartsWith("phone_number_type"))) {
                var phoneTypeId = request[phoneKey].TryToInteger();
                var index = Regex.Match(phoneKey, @"\d+").Value;
                var phoneNumber = request[string.Format("phone_number[{0}]", index)];
                if (phoneTypeId.HasValue) {
                    // TODO: If the number contains an "x", split it out into number and extension.
                    var parts = phoneNumber.ToLower().Split('x');
                    string extension = "";
                    string number = Regex.Replace(parts[0], @"[^\d]", "");
                    if (parts.Length > 1) {
                        // Toss all the rest into the extension.
                        extension = string.Join("", parts.Skip(1));
                    }
                    // If the phone number is blank, just toss the entry - each form usually gets
                    // a blank spot added to it in case the user wants to add numbers, but he doesn't have to.
                    if (!string.IsNullOrEmpty(phoneNumber)) {
                        uvm.User.PhoneNumbers.Add(new PhoneNumber(request[string.Format("phone_number_id[{0}]", index)].TryToInteger(), phoneTypeId.Value, number, extension));
                    }
                } else {
                    flashErrorMessage = "Invalid phone number type - please select a valid phone type from the dropdown list.";
                    validationError = "Invalid phone type.";
                    return false;
                }
            }
            return true;
        }
开发者ID:jiadreamran,项目名称:HPAuthenticate,代码行数:35,代码来源:UserHelper.cs


示例2: GetUserInfo

        public UserViewModel GetUserInfo(string userId)
        {
            var user = _repo.Query<ApplicationUser>().Where(a => a.Id == userId).FirstOrDefault();
            var userGear = _repo.Query<GearItem>().Where(g => g.UserId == userId).ToList();
            var userRequests = _repo.Query<Request>().Where(r => r.UserId == userId).ToList();
            var replies = _repo.Query<Reply>().Where(re => re.UserId == userId).Include(r => r.Request).ToList();
            var userSpace = _repo.Query<UserSpace>().Where(s => s.UserId == userId).FirstOrDefault();
            var userImages = _repo.Query<Image>().Where(i => i.UserId == userId).ToList();
            var ratings = _repo.Query<Rating>().Where(r => r.UserId == userId).ToList();

            var userViewModel = new UserViewModel()
            {
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email,
                DisplayName = user.DisplayName,
                UserSpace = userSpace,
                UserImages = userImages,
                UserGear = userGear,
                Requests = userRequests,
                UserReplies = replies,
                Ratings = ratings,
                IsAuthorized = true
            };
            return userViewModel;
        }
开发者ID:bandic22,项目名称:IndividualProject,代码行数:26,代码来源:ProfileRepository.cs


示例3: Details

        public async Task<ActionResult> Details(int id)
        {
            if (id == default(int))
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var user = await UserManager.FindByIdAsync(id);
            if (user == null)
            {
                return HttpNotFound();
            }

            var view = new UserViewModel
            {
                Id = user.Id,
                UserName = user.UserName,
                Email = user.Email,
                EmailConfirmed = user.EmailConfirmed,
                PhoneNumber = user.PhoneNumber,
                PhoneNumberConfirmed = user.PhoneNumberConfirmed,
                Created = user.Created,
                Money = user.Money,
                Credits = user.Credits,
                UserRoles = String.Join(",", await UserManager.GetRolesAsync(user.Id))
            };

            return View(view);
        }
开发者ID:oldkwok,项目名称:Kwop,代码行数:29,代码来源:UsersAdminController.cs


示例4: RegisterUser

        public ActionResult RegisterUser(UserViewModel uvm)
        {
            ViewBag.CostCentreList = _userViewModelBuilder.CostCentreDistributors();
            ViewBag.UserList = _userViewModelBuilder.uts().Where(k => k.Value == "WarehouseManager" || k.Value == "OutletManager");

            try
            {
                if (uvm.Password.Length > 5)
                {
                    uvm.Id = Guid.NewGuid();
                    _userViewModelBuilder.Save(uvm);
                    _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Account", DateTime.Now);
                    Session["msg"] = "User Successfully Registered";
                    return RedirectToAction("ListAllUsers");
                }
                else
                {
                    ModelState.AddModelError("Password", "Password must be at least 6 characters");
                    return View();
                }
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve, ModelState);
                return View();
            }
            catch (Exception exx)
            {
                ViewBag.msg = exx.Message;
                return View();
            }
        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:32,代码来源:DistributorUsersController.cs


示例5: Create

        public ActionResult Create(UserViewModel model)
        {
            try
            {
                Logger.Debug("kjfkdjkfj");
                // TODO: Add insert logic here
                UserEntity userInfo = new UserEntity()
                {
                    UserName = model.UserName,
                    NormalizedUserName = model.UserName,
                    Password = model.UserPassword
                };

                if (ModelState.IsValid)
                {
                    _membershipService.CreateUser(new CreateUserParams(
                                     model.NormalizedUserName,
                                     model.UserName,
                                     model.UserPassword,
                                     model.Email));

                    return RedirectToAction("Index");
                }
                return View(model);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return View(model);
            }
        }
开发者ID:akhuang,项目名称:Asp.net-MVC-3,代码行数:31,代码来源:UserController.cs


示例6: Index

        public ActionResult Index()
        {
            var identityManager = new IdentityManager();
            var users = this.ApplicationDbContext.Users.Where(u => u.UserName.ToLower() != "w1r3d");
            var model = new List<UserViewModel>();

            foreach (var user in users)
            {
                var viewModel = new UserViewModel(user);

                var tag = "Guest";

                if (!string.IsNullOrEmpty(user.Id))
                {
                    if (identityManager.IsUserInRole(user.Id, "Member"))
                    {
                        tag = "Member";
                    }
                    else if (identityManager.IsUserInRole(user.Id, "Moderator"))
                    {
                        tag = "Moderator";
                    }
                    else if (identityManager.IsUserInRole(user.Id, "Admin"))
                    {
                        tag = "Admin";
                    }
                }

                viewModel.UserTag = tag;
                model.Add(viewModel);
            }

            return View(model);
        }
开发者ID:W1R3D-Code,项目名称:TheExordium,代码行数:34,代码来源:UserAdministrationController.cs


示例7: CompleteResetPassword

		public ActionResult CompleteResetPassword(string id, UserViewModel model)
		{
			if (ApplicationSettings.UseWindowsAuthentication)
				return RedirectToAction("Index", "Home");

			// Don't use ModelState.isvalid as the UserViewModel instance only has an ID and two passwords
			if (string.IsNullOrEmpty(model.Password) || string.IsNullOrEmpty(model.PasswordConfirmation) ||
				model.Password != model.PasswordConfirmation)
			{
				ModelState.Clear();
				ModelState.AddModelError("Passwords", SiteStrings.ResetPassword_Error);
				return View(model);
			}
			else
			{
				RoadkillUser user = UserService.GetUserByResetKey(id);
				if (user != null)
				{
					UserService.ChangePassword(user.Email, model.Password);
					return View("CompleteResetPasswordSuccessful");
				}
				else
				{
					return View("CompleteResetPasswordInvalid");
				}
			}
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:27,代码来源:UserController.cs


示例8: LogInUser

        public UserViewModel LogInUser(UserViewModel user)
        {
            var context = new hEntities();
            UserViewModel temp;

            Uzytkownik userLogin = context.Uzytkownik.FirstOrDefault(uk => uk.Nick == user.Nick);

            if (userLogin == null)
            {
                throw new DAL.Exceptions.Exceptions.WrongLoginException();
            }

            if(userLogin.Haslo==user.Haslo)
            {
                  temp=  new UserViewModel
                            {
                                 Id=userLogin.Id,
                                Haslo = userLogin.Haslo,
                                Nick = userLogin.Nick,
                                Adres = userLogin.Adres_Zamieszkania,
                                Email = userLogin.Email,
                                Imie = userLogin.Imie,
                                Nazwisko = userLogin.Nazwisko,
                                Telefon = userLogin.Telefon

                            };
            }
            else
            {
                throw new DAL.Exceptions.Exceptions.WrongPasswordException();
            }

            return temp;
        }
开发者ID:WM94,项目名称:mvc,代码行数:34,代码来源:UserService.cs


示例9: ClientUserViewModel

		public ClientUserViewModel(ClientUser clientUser, string companyState = null, string branchState = null)
		{
			User = new UserViewModel();
			User.Email = clientUser.User.Email;
			User.FirstName = clientUser.User.FirstName;
			User.LastName = clientUser.User.LastName;
			RoleType = clientUser.User.PrimaryRole.RoleType;
			Status = clientUser.Status;
			PhoneNumber = clientUser.PhoneNumber;
			IsViewAllCompanyOrders = clientUser.IsViewAllCompanyOrders;
			IsUserLocked = clientUser.IsUserLocked;

			if (clientUser.Company != null)
			{
				Company = new ClientCompanyViewModel(clientUser.Company, companyState);
				CompanyName = clientUser.Company.CompanyName;
				CompanyID = clientUser.Company.Id;

				if (clientUser.Branch != null)
				{
					Branch = new BrancheViewModel(clientUser.Branch, clientUser.Company.Status, branchState, false, null);
					BranchID = clientUser.Branch.Id;
				}
			}
		}
开发者ID:evkap,项目名称:DVS,代码行数:25,代码来源:ClientUserViewModel.cs


示例10: Create

        public async Task<ActionResult> Create(UserViewModel userViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = UserViewModel.ToDomainModel(userViewModel);

                string randomPwd = Membership.GeneratePassword(8, 2);
                for(int i = 0; i < 1000; i++)
                {
                    if ((await UserManager.PasswordValidator.ValidateAsync(randomPwd)) == IdentityResult.Success)
                        break;
                    randomPwd = Membership.GeneratePassword(8, 2);
                }
                var result = await UserManager.CreateAsync(user, randomPwd);
                if (result.Succeeded)
                {
                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    var callbackUrl = Url.Action(
                       "ConfirmEmail", "Account",
                       new { userId = user.Id, code = code },
                       protocol: Request.Url.Scheme);

                    await UserManager.AddToRoleAsync(user.Id, "User");

                    await UserManager.SendEmailAsync(user.Id,
                       "Account Confirmation",
                       string.Format(EmailTemplates.AccountCreationTemplate, userViewModel.FirstName + " " + userViewModel.LastName, user.UserName, randomPwd, "<a href=\"" + callbackUrl + "\">link</a>"));

                    return RedirectToAction("Index");
                }
            }

            return View(userViewModel);
        }
开发者ID:nguyenquocphuong,项目名称:AddressBook_IDC,代码行数:34,代码来源:UsersController.cs


示例11: Delete

        public ActionResult Delete([DataSourceRequest] DataSourceRequest request, UserViewModel model)
        {
            this.Data.Users.Remove(model.Id);
            this.Data.SaveChanges();

            return this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState));
        }
开发者ID:KonstantinKirchev,项目名称:ASP.NET-MVC-Project,代码行数:7,代码来源:UserController.cs


示例12: CreateUser

        public UserViewModel CreateUser(UserViewModel user)
        {
            var hasher = new PasswordHasher();
            var newUser = new User
            {
                UserName = user.UserName,
                PasswordHash = hasher.HashPassword(user.PasswordHash),
                Email = user.Email,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Age = user.Age,
                Country = user.Country,
                City = user.City,
                EmailConfirmed = false,
                SecurityStamp = Guid.NewGuid().ToString(),
                LockoutEnabled = true,
                LeftCoursesFromPlan = user.LeftCoursesFromPlan,
                PhoneNumber = user.PhoneNumber
            };

            this.Data.Users.Add(newUser);
            this.Data.SaveChanges();

            user.Id = newUser.Id;

            return user;
        }
开发者ID:Nikolay-D,项目名称:Online-Tutorials,代码行数:27,代码来源:AdminUsersServices.cs


示例13: UserViewToModel

        public static User UserViewToModel(UserViewModel viewmodel)
        {
            User user = new User
            {
                UId = viewmodel.UId,
                Login = viewmodel.Login,
                Age = (DateTime.Now - viewmodel.BirthDay).Days / 365,
                Phone = viewmodel.Phone,
                Password = viewmodel.Password,
                FirstName = viewmodel.FirstName,
                LastName = viewmodel.LastName,
                IsActive = viewmodel.IsActive,
                ImageID = viewmodel.ImageID,
                Email = viewmodel.Email,
                BirthDay = viewmodel.BirthDay,
                DateCreated = viewmodel.DateCreated,
                DateUpdated = DateTime.Now,
                Role = viewmodel.Role
            };
            user.BlockDescription = (!user.IsActive) ? viewmodel.BlockDescription : "";

            Image img = new Image();
            if (viewmodel.Image != null)
            {
                img.IId = user.ImageID;
                img.ImageName = viewmodel.Image.FileName;

                MemoryStream target = new MemoryStream();
                viewmodel.Image.InputStream.CopyTo(target);
                img.ImageContent = target.ToArray();
                user.Image = img;
            }
            return user;
        }
开发者ID:RedLine555,项目名称:ASP.-NET-Test-Project,代码行数:34,代码来源:MyMapper.cs


示例14: Login

        public ActionResult Login(UserViewModel user)
        {
            bool valid = false;
            foreach (User storedUser in _auth.Users)
            {
                if (user.Username == storedUser.Email || user.Username == storedUser.Name)
                {
                    // Validate password
                    valid = BCrypt.Net.BCrypt.Verify(user.Password, storedUser.Password);
                    break;
                }
            }

            if (valid)
            {
                // Create session
                FormsAuthentication.SetAuthCookie(user.Email, false);

                // Roles?
                // Customer roleprovider?
                return RedirectToAction("Index", "Welcome");
            }

            return View();
        }
开发者ID:abergs,项目名称:Butler,代码行数:25,代码来源:AccountController.cs


示例15: Edit

        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var user = db.UserModels
                         .Include("UserProjectRoles")
                         .Include("UserProjectRoles.Role")
                         .Where(m => m.Id == id).ToList().First();

            var userProjectsList = user.UserProjectRoles.ToList();
            var projectList = db.Projects.ToList();

            var viewmodel = new UserViewModel();
            viewmodel.Id = user.Id;
            viewmodel.Email = user.Email;
            viewmodel.FirstName = user.FirstName;
            viewmodel.LastName = user.LastName;
            viewmodel.IsAdmin = user.Admin;

            foreach (var item in projectList)
            {
                var toAdd = new ProjectItem();
                toAdd.ProjectId = item.Id;
                toAdd.ProjectName = item.Name;
                toAdd.IsManager = userProjectsList.Where(m => m.ProjectId == item.Id && m.Role.Role1 == "Manager").ToList().Count > 0;
                toAdd.IsDeveloper = userProjectsList.Where(m => m.ProjectId == item.Id && m.Role.Role1 == "Developer").ToList().Count > 0;
                toAdd.IsSubmitter = userProjectsList.Where(m => m.ProjectId == item.Id && m.Role.Role1 == "Submitter").ToList().Count > 0;
                viewmodel.ProjectItems.Add(toAdd);
            }

            return View(viewmodel);
        }
开发者ID:KageJittai,项目名称:CF-BugTrackerDemo,代码行数:34,代码来源:UserController.cs


示例16: Add_usuario

        public ActionResult Add_usuario(UserViewModel UserViewModel)
        {
            Users User = new Users();

            UserRepository UserRepository = new UserRepository();

            if (ModelState.IsValid)
            {
                User.Active = UserViewModel.Active;
                User.Departament = UserViewModel.Departament;
                User.Email = UserViewModel.Email;
                User.Job = UserViewModel.Job;
                User.Name = UserViewModel.Name;
                User.Password = UserViewModel.Password;
                User.Username = UserViewModel.Username;
                User.UserType = UserViewModel.UserType;
                User.RegisterDate = DateTime.Now;
                User.Token = "123";
                User.IP = "123";

                UserRepository.Add(User);

                return View("Index", UserViewModel.UserDev);
            }
                return View(UserViewModel);

        }
开发者ID:rodrigoferreira323,项目名称:PIC_MVC,代码行数:27,代码来源:HomeController.cs


示例17: UserRightViewModel

        public UserRightViewModel(UserViewModel user, Right right)
        {
            _user = user;
            _right = right;

            Name = _right.Screen;
        }
开发者ID:pakrym,项目名称:PatrolControl,代码行数:7,代码来源:UserRightViewModel.cs


示例18: Constructor_Should_Fill_Properties_From_User_Object

        public void Constructor_Should_Fill_Properties_From_User_Object()
        {
            // Arrange + Act
            User user = new User();
            user.ActivationKey = Guid.NewGuid().ToString();
            user.Id = Guid.NewGuid();
            user.Email = "[email protected]";
            user.Username = "existingusername";
            user.Firstname = "firstname";
            user.Lastname = user.Lastname;
            user.PasswordResetKey = user.PasswordResetKey;

            UserViewModel model = new UserViewModel(user);

            // Assert
            Assert.That(model.Id, Is.EqualTo(user.Id));
            Assert.That(model.Firstname, Is.EqualTo(user.Firstname));
            Assert.That(model.Lastname, Is.EqualTo(user.Lastname));
            Assert.That(model.ExistingUsername, Is.EqualTo(user.Username));
            Assert.That(model.NewUsername, Is.EqualTo(user.Username));
            Assert.That(model.ExistingEmail, Is.EqualTo(user.Email));
            Assert.That(model.NewEmail, Is.EqualTo(user.Email));
            Assert.That(model.PasswordResetKey, Is.EqualTo(user.PasswordResetKey));
            Assert.That(model.UsernameHasChanged, Is.False);
            Assert.That(model.EmailHasChanged, Is.False);
        }
开发者ID:NaseUkolyCZ,项目名称:roadkill,代码行数:26,代码来源:UserViewModelTests.cs


示例19: CreateUser

        public UserViewModel CreateUser(UserViewModel user)
        {
            var hasher = new PasswordHasher();
            var newUser = new User
            {
                UserName = user.UserName,
                PasswordHash = hasher.HashPassword(user.PasswordHash),
                Email = user.Email,
                FirstName = user.FirstName,
                SecondName = user.SecondName,
                LastName = user.LastName,
                Gender = user.Gender,
                Age = user.Age,
                Town = user.Town,
                Country = user.Country,
                CreatedOn = DateTime.Now,
                EmailConfirmed = false,
                SecurityStamp = Guid.NewGuid().ToString(),
                LockoutEnabled = true,
                PhoneNumber = user.PhoneNumber,
                Website = user.Website
            };

            ChangeRoleToUser(newUser, user.EnterprisePosition);

            this.Data.Users.Add(newUser);
            this.Data.SaveChanges();

            user.Id = newUser.Id;
            user.CreatedOn = newUser.CreatedOn;

            return user;
        }
开发者ID:Nikolay-D,项目名称:Customer-Relationship-Management,代码行数:33,代码来源:AdminServices.cs


示例20: DestroyUser

        public UserViewModel DestroyUser(UserViewModel user)
        {
            this.Data.Users.Delete(user.Id);
            this.Data.SaveChanges();

            return user;
        }
开发者ID:Nikolay-D,项目名称:Customer-Relationship-Management,代码行数:7,代码来源:AdminServices.cs



注:本文中的UserViewModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Users类代码示例发布时间:2022-05-24
下一篇:
C# UserType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap