public async Task <IHttpActionResult> Post(PictureModelFromUser picture) { if (await _pictureService.TryToAddPictureAsync(picture)) { return(Ok()); } return(BadRequest("Such picture already exists")); }
public Picture ToDomainModel(PictureModelFromUser pictureModel) { return(new Picture { Content = pictureModel.Content, WordId = pictureModel.WordId, }); }
public async Task <bool> TryToAddPictureAsync(PictureModelFromUser picture) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { if (await WordHasPicture(picture.WordId)) { return(false); } var pictureToAdd = _pictureMapper.ToDomainModel(picture); uow.PictureRepository.Add(pictureToAdd); return(await uow.SaveAsyncBool()); } }
public async Task <bool> UpdatePictureAsync(PictureModelFromUser picture) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var oldPicture = uow.PictureRepository.GetById(picture.WordId); if (oldPicture == null) { return(false); } oldPicture.Content = picture.Content; oldPicture.WordId = picture.WordId; uow.PictureRepository.Update(oldPicture); return(await uow.SaveAsyncBool()); } }