public async Task <IActionResult> PutGuestType(int id, GuestTypeViewModel guestType) { if (guestType.Id != id) { throw new Exception(string.Format("Id và Id của khóa học không giống nhau!")); } try { await Task.Run(() => { guestType.DateModified = DateTime.Now; _guestTypeService.Update(guestType); _guestTypeService.SaveChanges(); return(Ok()); }); } catch (DbUpdateConcurrencyException) { if (!GuestTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public bool Update(GuestTypeViewModel guestTypeViewModel) { try { var guestType = Mapper.Map <GuestTypeViewModel, GuestType>(guestTypeViewModel); _guestTypeRepository.Update(guestType); return(true); } catch { return(false); } }
public async Task <ActionResult <GuestTypeViewModel> > PostGuestType(GuestTypeViewModel guestType) { if (guestType != null) { try { await Task.Run(() => { guestType.DateCreated = DateTime.Now; _guestTypeService.Add(guestType); _guestTypeService.SaveChanges(); return(Ok("thêm khóa học thành công!")); }); } catch { throw new Exception(string.Format("Lỗi khi thêm dữ liệu")); } } return(CreatedAtAction("GetGuestType", new { id = guestType.Id }, guestType)); }