Пример #1
0
        public async Task <Picture> AddComment(int userId, int pictureId, AddCommentDto commentDto)
        {
            try
            {
                var pointOfView = _galleryDbContext.PointsOfView.AsQueryable()
                                  .Where(pOv => pOv.UserId == userId && pOv.PictureId == pictureId).FirstOrDefault();
                var added = pointOfView == null;

                pointOfView = pointOfView ?? new PointOfView()
                {
                    Points        = commentDto.Points,
                    Comment       = commentDto.Comment,
                    PictureId     = pictureId,
                    UserId        = userId,
                    AddedDateTime = DateTime.Now
                };
                pointOfView.Points        = commentDto.Points;
                pointOfView.Comment       = commentDto.Comment;
                pointOfView.AddedDateTime = DateTime.Now;

                if (added)
                {
                    await _galleryDbContext.PointsOfView.AddAsync(pointOfView);
                }

                await _galleryDbContext.SaveChangesAsync();

                return(await GetPicture(pictureId));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Пример #2
0
 public async Task CompleteAsync()
 {
     await context.SaveChangesAsync();
 }