public WatchConfirmationDto Update(Guid id, WatchCreateDto dto) { if (dto.WatcherId == dto.WatchedId) { throw new BusinessException("Can not Watch yourself"); } var Watched = MockedUsers.Users.FirstOrDefault(e => e.Id == dto.WatchedId); var Watcher = MockedUsers.Users.FirstOrDefault(e => e.Id == dto.WatcherId); if (Watched == null || Watcher == null) { throw new BusinessException("User does not exist"); } var Watch = _context.Watches.FirstOrDefault(e => e.Id == id); if (Watch == null) { throw new BusinessException("Watch does not exist"); } Watch.WatcherId = dto.WatcherId; Watch.WatchedId = dto.WatchedId; _context.SaveChanges(); _logger.Log("Watch updated!"); return(_mapper.Map <WatchConfirmationDto>(Watch)); }
public WatchConfirmationDto Create(WatchCreateDto dto) { if (dto.WatcherId == dto.WatchedId) { throw new BusinessException("Can not Watch yourself"); } var Watched = MockedUsers.Users.FirstOrDefault(e => e.Id == dto.WatchedId); var Watcher = MockedUsers.Users.FirstOrDefault(e => e.Id == dto.WatcherId); if (Watched == null || Watcher == null) { throw new BusinessException("User does not exist"); } Watch newWatch = new Watch() { Id = Guid.NewGuid(), WatchedId = dto.WatchedId, WatcherId = dto.WatcherId }; _context.Watches.Add(newWatch); _context.SaveChanges(); _logger.Log("New Watch created!"); return(_mapper.Map <WatchConfirmationDto>(newWatch)); }
public ActionResult Put(Guid id, WatchCreateDto dto) { var entity = _repository.Update(id, dto); return(Ok(entity)); }
public ActionResult Post([FromBody] WatchCreateDto dto) { var entity = _repository.Create(dto); return(Ok(entity)); }