private void EditUser() { if (ctrGridUser.SelectedCells.Count > 0) { int id = (int)ctrGridUser.Rows[ctrGridUser.SelectedCells[0].RowIndex].Cells[4].Value; User user = new User(); foreach (User us in listOfUsers.GetList()) { if (us.Id == id) { user = us; } } UserForm form = new UserForm(user, listOfAwards.GetList()); if (form.ShowDialog() == DialogResult.OK) { user.FirstName = form.FirstName; user.LastName = form.LastName; user.DateOfBirth = form.DateOfBirth; user.Awards = form.ListOfAwards; listOfUsers.Edit(user); DisplayUsers(); } } }
public ActionResult Edit(int id, UserViewModel userModel) { try { var user = users.GetList().FirstOrDefault(u => u.Id == id);// использую такой костыль т.к. в availableRewards возвращался неполный объект var userAwards = awards.GetList().Select(a => AwardViewModel.GetViewModel(a, user.GetAwards())); var checkedAwards = userModel.AvailableRewards.Where(a => a.Checked); var availableAwards = userAwards.Where(a => checkedAwards.Any(aw => aw.Id == a.Id)); var deletedAwards = userAwards.Where(a => !checkedAwards.Any(aw => aw.Id == a.Id)); foreach (var award in availableAwards) { award.Checked = true; users.AddAward(id, award.Id); } foreach (var award in deletedAwards) { award.Checked = false; users.RemoveAward(id, award.Id); } userModel.AvailableRewards = availableAwards.ToList(); users.Edit(userModel.ToUser()); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, FormCollection collection) { try { var editedUser = new User(Convert.ToInt32(collection["Id"]), collection["FirstName"], collection["LastName"], Convert.ToDateTime(collection["DateOfBirth"]), new List <Award>()); for (int i = 5; i < collection.Count; i++) { foreach (Award aw in listOfAwards.GetList()) { if (aw.AwardId == Int32.Parse(collection.AllKeys[i])) { editedUser.Awards.Add(aw); } } } if (editedUser.Id == 0) { listOfUsers.Add(editedUser); } else { listOfUsers.Edit(editedUser); } return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <ActionResult> Edit(User user) { try { if (Utilities.Utilities.IsNullOrEmpty(user.Email) && Utilities.Utilities.IsNullOrEmpty(user.PhoneNumber)) { return(View(user)); } await UsersBL.Edit(user); return(RedirectToAction("Index")); } catch { ModelState.AddModelError("", "Ocurrió un error"); return(View(user)); } }
private void btn_EditUser_Click(object sender, EventArgs e) { var user = dgv_Users.CurrentRow?.DataBoundItem as User; if (user != null) { var form = new UserForm(user.BirthDate, user.LastName, user.FirstName); if (form.ShowDialog() == DialogResult.OK) { user.BirthDate = form.BirthDate; user.LastName = form.LastName; user.FirstName = form.FirstName; userBL.Edit(user); DisplayUsers(); } } }