Exemplo n.º 1
0
 public async Task <IHttpActionResult> Post(PictureModelFromUser picture)
 {
     if (await _pictureService.TryToAddPictureAsync(picture))
     {
         return(Ok());
     }
     return(BadRequest("Such picture already exists"));
 }
Exemplo n.º 2
0
 public Picture ToDomainModel(PictureModelFromUser pictureModel)
 {
     return(new Picture
     {
         Content = pictureModel.Content,
         WordId = pictureModel.WordId,
     });
 }
Exemplo n.º 3
0
 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());
     }
 }
Exemplo n.º 4
0
        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());
            }
        }