public IActionResult Edit(ClientsEditViewModel editModel) { if (GlobalVar.LoggedOnUserId == -1) { return(RedirectToAction("LogInRequired", "Users")); } if (ModelState.IsValid) { if (!ClientExists(editModel.Id)) { return(NotFound()); } Client client = new Client() { Id = editModel.Id, FirstName = editModel.FirstName, LastName = editModel.LastName, Email = editModel.Email, TelephoneNumber = editModel.TelephoneNumber, IsAdult = editModel.IsAdult }; context.Update(client); context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(editModel)); }
public IActionResult Edit(UsersEditViewModel editModel) { if (GlobalVar.LoggedOnUserRights != GlobalVar.UserRights.Admininstrator) { UsersLogInViewModel model1 = new UsersLogInViewModel(); model1.Message = "You dont meet the required permission to do this. Please, log in into account with admin permissions"; return(View("LogIn", model1)); } if (ModelState.IsValid) { if (!UserExists(editModel.Id)) { return(NotFound()); } try { Validate(new Validation_User() { Username = editModel.Username, UserId = editModel.Id }); } catch (InvalidOperationException e) { editModel.Message = e.Message; return(View(editModel)); } User user = _context.Users.Find(editModel.Id); user.Username = editModel.Username; user.FirstName = editModel.FirstName; user.MiddleName = editModel.MiddleName; user.LastName = editModel.LastName; user.EGN = editModel.EGN; user.Email = editModel.Email; user.TelephoneNumber = editModel.TelephoneNumber; if (!String.IsNullOrEmpty(editModel.Password)) { user.Password = editModel.Password; } _context.Update(user); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(editModel)); }
public IActionResult Edit(RoomsEditViewModel editModel) { if (GlobalVar.LoggedOnUserRights != GlobalVar.UserRights.Admininstrator) { return(RedirectToAction("LogInPermissionDenied", "Users")); } if (ModelState.IsValid) { if (!RoomExists(editModel.Id)) { return(NotFound()); } try { Validate(new Validation_Room() { Capacity = editModel.Capacity, Number = editModel.Number }); } catch (InvalidOperationException e) { editModel.Message = e.Message; return(View(editModel)); } Room room = new Room() { Id = editModel.Id, Number = editModel.Number, PriceAdult = editModel.PriceAdult, PriceChild = editModel.PriceChild, Type = (int)editModel.RoomType, Capacity = editModel.Capacity }; _context.Update(room); _context.SaveChanges(); UpdateAllReservationsOverallPriceRelatedToRoom(room.Id); return(RedirectToAction(nameof(Index))); } return(View(editModel)); }
public IActionResult Edit(UsersEditViewModel editModel) { if (GlobalVar.LoggedOnUserRights != GlobalVar.UserRights.Admininstrator) { UsersLogInViewModel model1 = new UsersLogInViewModel(); model1.Message = "Нямате право на това действие. Моля, влезте в акаунта си."; return(View("LogIn", model1)); } if (ModelState.IsValid) { if (!UserExists(editModel.Id)) { return(NotFound()); } try { Validate(new Validation_User() { Username = editModel.Username, UserId = editModel.Id }); } catch (InvalidOperationException e) { editModel.Message = e.Message; return(View(editModel)); } User user = context.Users.Find(editModel.Id); user.Username = editModel.Username; user.FirstName = editModel.FirstName; user.MiddleName = editModel.MiddleName; user.LastName = editModel.LastName; user.EGN = editModel.EGN; user.Email = editModel.Email; user.TelephoneNumber = editModel.TelephoneNumber; if (!String.IsNullOrEmpty(editModel.Password)) { user.Password = editModel.Password; } context.Update(user); context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(editModel)); }