public async Task <IActionResult> EditStaff(EditStaffViewModel model) { if (ModelState.IsValid) { var updClientResult = await _dbUsers.ClientUpdateAsync(model); if (!updClientResult.isSuccess) { foreach (var err in updClientResult.errors) { ModelState.AddModelError(string.Empty, err); } return(View()); } var updOrgResult = await _dbOrgStaff.ChangeOrgForStaff(model.Id, model.OrgId); if (!updOrgResult) { ModelState.AddModelError(string.Empty, "Company has not changed."); return(View()); } } return(RedirectToAction(nameof(EditStaff), "ManageUsers", new { id = model.Id })); }
public async Task <IActionResult> EditStaff(string id) { User user = await _userManager.FindByIdAsync(id); if (user == null) { return(NotFound()); } Models.DbModels.Org orgData = await _dbOrgStaff.GetOrgByStaffIdAsync(user.Id); EditStaffViewModel model = new EditStaffViewModel() { Id = user.Id, Name = user.UserName, Email = user.Email, NewPassword = string.Empty, OldPassword = string.Empty, ConfirmNewPassword = string.Empty, OrgId = 0, OrgName = string.Empty }; if (orgData != null) { model.OrgId = orgData.orgId; model.OrgName = orgData.orgName; } return(View(model)); }
public async Task <IActionResult> Edit(string id, EditStaffViewModel model) { if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var staff = await _userManager.FindByIdAsync(model.Id); staff.Forename = model.Forename; staff.MiddleNames = model.MiddleNames; staff.Surname = model.Surname; staff.Email = model.Email; staff.DateOfBirth = model.DateOfBirth; _context.Update(staff); var roles = await _userManager.GetRolesAsync(staff); await _userManager.RemoveFromRolesAsync(staff, roles); await _userManager.AddToRoleAsync(staff, model.Role); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StaffExists(model.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public ViewModelLocator() { _navigationService = new NavigationService(); _dataService = new DataService(new UserRepository(), new MenuRepository(), new DishRepository(), new CustomerRepository(), new DelivererRepository(), new EventRepository(), new IngredientRepository()); CustomerOverviewViewModel = new CustomerOverviewViewModel(_navigationService, _dataService); DelivererOverviewViewModel = new DelivererOverviewViewModel(_navigationService, _dataService); EventOverviewViewModel = new EventOverviewViewModel(_navigationService, _dataService); LoginViewModel = new LoginViewModel(_navigationService, _dataService); MainViewModel = new MainViewModel(_navigationService, _dataService); EditCustomerViewModel = new EditCustomerViewModel(_navigationService, _dataService); EditDelivererViewModel = new EditDelivererViewModel(_navigationService, _dataService); EditEventViewModel = new EditEventViewModel(_navigationService, _dataService); EditStaffViewModel = new EditStaffViewModel(_navigationService, _dataService); NewDelivererViewModel = new NewDelivererViewModel(_navigationService, _dataService); NewDishViewModel = new NewDishViewModel(_navigationService, _dataService); NewEventViewModel = new NewEventViewModel(_navigationService, _dataService); NewMenuViewModel = new NewMenuViewModel(_navigationService, _dataService); NewStaffViewModel = new NewStaffViewModel(_navigationService, _dataService); StaffViewModel = new StaffViewModel(_navigationService, _dataService); }
public async Task <IActionResult> Edit(EditStaffViewModel model) { //ModelState.Remove("No"); 工号不可更改 if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _mainRepository.EditAsync(new Staff { Id = model.Id, No = model.No, Name = model.Name, Gender = (int)model.Gender, OfficePhone = model.OfficePhone, MobilePhone = model.MobilePhone, Position = (int)(model.Position), JobTitle = (int)(model.JobTitle), Education = (int)(model.Education), HiredDate = model.HiredDate }); TempData["globalMessage"] = "成功编辑"; } catch (DbUpdateException /* ex */) { // Log the error(uncomment ex variable name and write a log. ModelState.AddModelError("", "无法保存更改。 " + "请重试, 如果该问题仍然存在 " + "请联系系统管理员。"); } return(View(model)); }
public async Task <IActionResult> Edit(string id) { if (id == null) { return(NotFound()); } var staff = await _context.Users.SingleOrDefaultAsync(m => m.Id == id); if (staff == null) { return(NotFound()); } var roles = await _userManager.GetRolesAsync(staff); string role = ""; foreach (var foundRoles in roles) { role = foundRoles; } var model = new EditStaffViewModel { Forename = staff.Forename, MiddleNames = staff.MiddleNames, Surname = staff.Surname, Email = staff.Email, DateOfBirth = staff.DateOfBirth, Role = role }; ViewData["Roles"] = new SelectList(_context.Roles.Where(r => !r.Name.Equals("Customer")), "Name", "Name"); return(View(model)); }
public async Task <IActionResult> Edit(Guid Id) { if (Id == null) { return(NotFound()); } var staffToEdit = await _mainRepository.QueryByIdAsync(Id); var model = new EditStaffViewModel { Id = staffToEdit.Id, No = staffToEdit.No, Name = staffToEdit.Name, Gender = (Gender)(staffToEdit.Gender), OfficePhone = staffToEdit.OfficePhone, MobilePhone = staffToEdit.MobilePhone, Position = (Position)(staffToEdit.Position), JobTitle = (JobTitle)(staffToEdit.JobTitle), Education = (Education)(staffToEdit.Education), HiredDate = staffToEdit.HiredDate }; return(View(model)); }