本文整理汇总了C#中UserViewModel类的典型用法代码示例。如果您正苦于以下问题:C# UserViewModel类的具体用法?C# UserViewModel怎么用?C# UserViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserViewModel类属于命名空间,在下文中一共展示了UserViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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");
}
}
}
示例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;
}
示例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;
}
}
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}