public async Task <IActionResult> EditTable(EditTableViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var mapped = _mapper.Map <Table>(model); var result = await _tableService.EditTable(mapped); if (result > 0) { return(RedirectToAction(nameof(Tables))); } return(View(model)); }
public async Task <IActionResult> Edit(EditTableViewModel model) { if (ModelState.IsValid) { User user = await _userManager.FindByIdAsync(_userManager.GetUserId(User)); if (User.IsInRole(Convert.ToString(Roles.SuperAdmin))) { user = await _userManager.FindByIdAsync(user.IdOfTheSelectedRestaurateur); } var table = _db.Tables.FirstOrDefault(t => t.Id == model.Id); if (table != null) { table.Capacity = model.Capacity; table.State = model.State; table.Desc = model.Desc; table.Location = model.Location; table.IsSmoking = model.IsSmoking; table.IsQuiet = model.IsQuiet; table.Floor = model.Floor; table.EditedDate = DateTime.Now; table.EditorId = user.Id; if (model.File != null) { await DeleteTableIcon(table); table.IconUrl = await Load(model.Id, model.File); } _db.Entry(table).State = EntityState.Modified; } await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
public IActionResult Edit(int id) { Table table = _db.Tables.FirstOrDefault(t => t.Id == id); if (table != null) { EditTableViewModel model = new EditTableViewModel { Id = table.Id, Capacity = table.Capacity, IconUrl = table.IconUrl, State = table.State, Desc = table.Desc, Location = table.Location, IsSmoking = table.IsSmoking, IsQuiet = table.IsQuiet, Floor = table.Floor, }; return(View(model)); } return(NotFound()); }