public static Watch ToWatch(this WatchToPutDto watch) { if (watch == null) { return(null); } return(new Watch { Id = watch.Id, Model = watch.Model, Title = watch.Title, Gender = watch.Gender, CaseSize = watch.CaseSize, CaseMaterial = watch.CaseMaterial, BrandId = watch.BrandId, MovementId = watch.MovementId }); }
public async Task <IActionResult> UpdateWatchAsync(long id, WatchToPutDto watchDto) { if (id != watchDto.Id) { throw new BadRequestException($"Watch id {watchDto.Id} does not match the id in the route: {id}.", "id"); } if (watchDto.Id == default(long)) { throw new BadRequestException($"Watch id cannot be 0.", "id"); } var updated = await _watchRepository.UpdateWatchAsync(watchDto.ToWatch()); if (!updated) { return(NotFound($"Watch with id {id} cannot be found.")); } return(NoContent()); }