public async Task <IActionResult> UpdateDepartment(int id, ClockItemForCreationDto clockItemForCreationDto) { int userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); ClockItem clockItemFromRepo = await _repo.GetSingleClockItem(userId, id); _mapper.Map(clockItemForCreationDto, clockItemFromRepo); if (await _repo.SaveAll()) { var clockItemToReturn = _mapper.Map <ClockItemForReturnDto>(clockItemFromRepo); return(CreatedAtRoute("GetClockItem", new { id = clockItemFromRepo.Id }, clockItemToReturn)); } throw new Exception("Updating clock item failed on save"); }
public async Task <IActionResult> AddClockItem(ClockItemForCreationDto clockItemForCreation) { var creator = await _userRepo.GetUser(int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)); var clockItem = _mapper.Map <ClockItem>(clockItemForCreation); clockItem.User = creator; _repo.Add(clockItem); if (await _repo.SaveAll()) { var clockItemToReturn = _mapper.Map <ClockItemForReturnDto>(clockItem); return(CreatedAtRoute("GetClockItem", new { id = clockItem.Id }, clockItemToReturn)); } throw new Exception("Creation of clock item failed on save"); }