本文整理汇总了C#中EditUserViewModel类的典型用法代码示例。如果您正苦于以下问题:C# EditUserViewModel类的具体用法?C# EditUserViewModel怎么用?C# EditUserViewModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EditUserViewModel类属于命名空间,在下文中一共展示了EditUserViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Edit
public async Task<ActionResult> Edit(EditUserViewModel model)
{
var Db = new ApplicationDbContext();
var user = Db.Users.First(u => u.UserName == model.UserName);
if (ModelState.IsValid)
{
model.PhotoUrl = Utils.SavePhotoFileToDisk(model.Photo, this, user.PhotoUrl, model.IsNoPhotoChecked);
user.PhotoUrl = model.PhotoUrl;
// Update the user data:
user.FirstName = model.FirstName;
user.LastName = model.LastName;
user.Email = model.Email;
Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
await Db.SaveChangesAsync();
if (HttpContext.User.IsInRole("Admin"))
{
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Edit", new { id = user.UserName, Message = ManageMessageId.RegisterSuccess });
}
}
model.PhotoUrl = user.PhotoUrl;
// If we got this far, something failed, redisplay form
return View(model);
}
示例2: Edit
public ActionResult Edit(string id, ManageMessageId? Message = null)
{
var Db = new ApplicationDbContext();
var user = Db.Users.First(u => u.UserName == id);
var model = new EditUserViewModel(user);
ViewBag.MessageId = Message;
return View(model);
}
示例3: EditUser
public ActionResult EditUser(string name, ManageMessageId? Message = null)
{
var user = this.ApplicationDbContext.Users.First(u => u.UserName == name);
var model = new EditUserViewModel(user);
ViewBag.MessageId = Message;
ViewBag.Title = "Edit User";
return View(model);
}
示例4: SaveUser
/// <summary>
/// Saves the user.
/// </summary>
/// <param name="model">The model.</param>
/// <returns>Json status result.</returns>
public ActionResult SaveUser(EditUserViewModel model)
{
var response = GetCommand<SaveUserCommand>().ExecuteCommand(model);
if (response != null)
{
Messages.AddSuccess(UsersGlobalization.SaveUser_CreatedSuccessfully_Message);
return Json(new WireJson { Success = true, Data = response });
}
return Json(new WireJson { Success = false });
}
示例5: Delete
public ActionResult Delete(string id = null)
{
var Db = new ApplicationDbContext();
var user = Db.Users.First(u => u.UserName == id);
var model = new EditUserViewModel(user);
if (user == null)
{
return HttpNotFound();
}
return View(model);
}
示例6: Index
/// <summary>
/// Returns a view model to show all accounts.
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
var Db = new ApplicationDbContext();
var users = Db.Users;
var model = new List<EditUserViewModel>();
foreach (var user in users)
{
var u = new EditUserViewModel(user);
model.Add(u);
}
return View(model);
}
示例7: Index
public ActionResult Index()
{
//var users = UserManager.Users.Cast<List<EditUserViewModel>>().ToList();
var db = new ApplicationDbContext();
var users = db.Users;
var model = new List<EditUserViewModel>();
foreach (var user in users)
{
var u = new EditUserViewModel(user);
model.Add(u);
}
return View(model);
}
示例8: EditUser
public async Task<IActionResult> EditUser(EditUserViewModel viewModel)
{
if (!ModelState.IsValid)
{
return View(viewModel);
}
//Skill associations
var user = GetUser(viewModel.UserId);
user.AssociatedSkills.RemoveAll(usk => viewModel.AssociatedSkills == null || !viewModel.AssociatedSkills.Any(msk => msk.SkillId == usk.SkillId));
if (viewModel.AssociatedSkills != null)
{
user.AssociatedSkills.AddRange(viewModel.AssociatedSkills.Where(msk => !user.AssociatedSkills.Any(usk => usk.SkillId == msk.SkillId)));
}
if (user.AssociatedSkills != null && user.AssociatedSkills.Count > 0)
{
user.AssociatedSkills.ForEach(usk => usk.UserId = user.Id);
}
await _mediator.SendAsync(new UpdateUser { User = user });
var organizationAdminClaim = new Claim(Security.ClaimTypes.UserType, "OrgAdmin");
if (viewModel.IsOrganizationAdmin)
{
//add organization admin claim
var result = await _userManager.AddClaimAsync(user, organizationAdminClaim);
if (result.Succeeded)
{
//mgmccarthy: there is no Login action method on the AdminController. The only login method I could find is on the AccountController. Not too sure what to do here
var callbackUrl = Url.Action(new UrlActionContext { Action = "Login", Controller = "Admin", Values = new { Email = user.Email }, Protocol = HttpContext.Request.Scheme });
await _mediator.SendAsync(new SendAccountApprovalEmail { Email = user.Email, CallbackUrl = callbackUrl });
}
else
{
return Redirect("Error");
}
}
else if (user.IsUserType(UserType.OrgAdmin))
{
//remove organization admin claim
var result = await _userManager.RemoveClaimAsync(user, organizationAdminClaim);
if (!result.Succeeded)
{
return Redirect("Error");
}
}
return RedirectToAction(nameof(Index));
}
示例9: Index
public ActionResult Index()
{
var companies = companyService.GetCompanies();
var roles = roleService.GetRoles();
EditUserViewModel editUser = new EditUserViewModel()
{
Roles = roles.ToList(),
CompanyList = companies.ToList()
};
ViewData["companies"] = companies;
ViewData["EditUser"] = editUser;
return View();
}
示例10: Edit
public ActionResult Edit(string id, ManageMessageId? Message = null)
{
var Db = new ApplicationDbContext();
var user = Db.Users.First(u => u.UserName == id);
var model = new EditUserViewModel(user);
ViewBag.MessageId = Message;
var userprefer = Db.UserPreferences.Where(a => a.UserName == id).Select(x=> new {x.SchoolRefID,x.AcademicYearRefID}).FirstOrDefault();
ViewBag.SchoolID = new SelectList(Db.Schools.AsNoTracking().Select(x => new { x.SchoolID, x.SchoolName }), "SchoolID", "SchoolName",userprefer.SchoolRefID);
ViewBag.AcademicYearID = new SelectList(Db.AcademicYears.AsNoTracking().Where(a => a.SchoolRefID ==userprefer.SchoolRefID).Select(x => new { x.AcademicYearID, x.DisplayYear }), "AcademicYearID", "DisplayYear",userprefer.AcademicYearRefID);
return View(model);
}
示例11: Index
public ActionResult Index(string sortOrder, string searchString)
{
ViewBag.UsernameSortParam = String.IsNullOrEmpty(sortOrder) ? "username_asc" : "";
ViewBag.NameSortParam = sortOrder == "first_asc" ? "first_desc" : "first_asc";
ViewBag.LastSortParam = sortOrder == "last_asc" ? "last_desc" : "last_asc";
var db = new ApplicationDbContext();
var users = from u in db.Users
where u.Status != ApplicationUser.AccountStatus.Disabled
select u;
if (!String.IsNullOrEmpty(searchString))
{
users = users.Where(u => u.LastName.Contains(searchString)
|| u.FirstName.Contains(searchString)
&& u.Status != ApplicationUser.AccountStatus.Disabled);
}
switch (sortOrder)
{
case "username_asc":
users = users.OrderBy(u => u.UserName);
break;
case "first_desc":
users = users.OrderByDescending(u => u.FirstName);
break;
case "last_desc":
users = users.OrderByDescending(u => u.LastName);
break;
case "first_asc":
users = users.OrderBy(u => u.FirstName);
break;
case "last_asc":
users = users.OrderBy(u => u.LastName);
break;
}
var model = new System.Collections.Generic.List<EditUserViewModel>();
foreach (var user in users)
{
var u = new EditUserViewModel(user);
model.Add(u);
}
return View(model);
}
示例12: Index
public ActionResult Index(string userrole = null)
{
List<ApplicationUser> users;
if (userrole != null)
{
users = _accountService.GetUsersByRole(userrole);
}
else
{
users = _accountService.GetAllUsers();
}
var model = new List<EditUserViewModel>();
foreach (ApplicationUser user in users)
{
var u = new EditUserViewModel(user);
model.Add(u);
}
return View(model);
}
示例13: Update
public ActionResult Update([DataSourceRequest]DataSourceRequest request, EditUserViewModel user)
{
if (!ModelState.IsValid)
{
return this.View();
}
var currentUser = this.UserService.GetById(user.Id)
.FirstOrDefault();
if (currentUser == null)
{
return this.View();
}
currentUser.FirstName = user.FirstName;
currentUser.LastName = user.LastName;
currentUser.Email = user.Email;
currentUser.UserName = user.UserName;
this.UserService.UpdateUser(currentUser);
return Json(new[] { user }.ToDataSourceResult(request, ModelState));
}
示例14: Edit
public ActionResult Edit(string id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
ViewBag.ALUMNOS = new SelectList(new PersonasRepository().GetAlumnos(), "ID", "PERSONA_NOMBRE_COMPLETO");
ApplicationUser user = _repo.GetUser(id);
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
var userRoles = UserManager.GetRoles(id);
ViewBag.USER_ROLES = roleStore.Roles.ToList().Select(x => new SelectListItem()
{
Selected = userRoles.Contains(x.Name),
Text = x.Name,
Value = x.Name
});
EditUserViewModel vm = new EditUserViewModel
{
Email = user.Email,
UserName = user.UserName,
USER_PERSONA_ID = user.USER_PERSONA_ID != null ? user.USER_PERSONA_ID.Value : 0,
};
return View(vm);
}
示例15: CreateUser
public ActionResult CreateUser()
{
var model = new EditUserViewModel { IsNewUser = true };
return PartialView("EditUser", model);
}