Ejemplo n.º 1
0
        public async Task AddPhotoComment(PhotoComment comment)
        {
            logWriter.LogInformation($"{nameof(AddPhotoComment)}({nameof(comment.PhotoId)} = '{comment.PhotoId}', {nameof(comment.UserId)} = '{comment.UserId}', {nameof(comment.Text)} = '{comment.Text}')");

            var photo = await photoRepository.GetPhotoById(comment.PhotoId, Guid.Empty);

            var scoreDelta = scoreCalculator.GetCommentScore(comment);

            var putItemRequest = new PutItemRequest()
            {
                TableName = tableName,
                Item      = Mappers.PhotoComment.ToDbItem(comment)
            };

            try
            {
                await dynamoDbCore.PutItem(putItemRequest);
                await UpdateCommentCountAndScore(photo, 1, scoreDelta);
            }
            catch (Exception ex)
            {
                logWriter.LogError(ex, $"{nameof(AddPhotoComment)}({nameof(comment.PhotoId)} = '{comment.PhotoId}', {nameof(comment.UserId)} = '{comment.UserId}', {nameof(comment.Text)} = '{comment.Text}'):\n{ex.ToString()}");

                throw;
            }
        }
        public async Task AddPhotoComment_PopulatesInputProperly()
        {
            UserId       userId               = new Guid("13999be1-095a-4726-87e9-d11f2103585c");
            PhotoId      photoId              = new Guid("d3f31301-c244-4104-9b83-2ad073a8d2d0");
            string       userName             = "******";
            string       text                 = "not empty";
            PhotoComment observedPhotoComment = null;

            // set up expectation that AddPhotoComment is invoked in the data repository
            commentRepositoryMock
            .Setup(x => x.AddPhotoComment(It.IsAny <PhotoComment>()))
            .Callback <PhotoComment>(x => observedPhotoComment = x)
            .Returns(Task.CompletedTask);

            var service = GetFeedbackService();


            await service.AddPhotoComment(photoId, userId, userName, text);

            observedPhotoComment.ShouldNotBeNull();
            observedPhotoComment.PhotoId.ShouldBe(photoId);
            observedPhotoComment.UserId.ShouldBe(userId);
            observedPhotoComment.UserName.ShouldBe(userName);
            observedPhotoComment.Text.ShouldBe(text);
        }
Ejemplo n.º 3
0
        public List <PhotoComment> VisitPhotoGetComments(GetComments method, JToken data)
        {
            var result     = new List <PhotoComment>();
            var commentors = new List <VkPrincipal>();

            foreach (var item in data["response"]["profiles"])
            {
                var profile = new User();
                profile.Accept(this.ObjectParser, item);
                commentors.Add(profile);
            }
            foreach (var item in data["response"]["groups"])
            {
                var group = new Group();
                group.Accept(this.ObjectParser, item);
                commentors.Add(group);
            }
            foreach (var item in data["response"]["items"])
            {
                var comment = new PhotoComment();
                comment.Accept(this.ObjectParser, item);
                comment.Creator = commentors.SingleOrDefault(x => x.Id == comment.FromId);
                result.Add(comment);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public async Task <Comment> AddComment(string photoId, string albumId, string message, User requestor)
        {
            if (!await _permissionsService.CanComment(requestor, albumId))
            {
                return(null);
            }
            var photo = await _photoService.GetPhoto(photoId);

            var comment = new Comment
            {
                ReactionId   = _guid.NewGuid().ToString(),
                Text         = message,
                Reactor      = requestor,
                ReactionDate = _clock.UtcNow
            };
            var photoComment = new PhotoComment
            {
                Photo   = photo,
                Comment = comment
            };

            photo.PhotoComments.Add(photoComment);
            await _unitOfWork.Photos.Update(photo);

            return(comment);
        }
        public ActionResult createPhotoCommentByID(string content, string photoID, string userID)
        {
            DateTime dateTime = DateTime.Now;
            int      createPhotoCommentFlag = 0;

            PhotoComment photoComment = new PhotoComment();

            photoComment.PhotoCommentContent = content;
            photoComment.PhotoId             = int.Parse(photoID);
            photoComment.UserId           = int.Parse(userID);
            photoComment.PhotoCommentTime = dateTime;

            try {
                entity.PhotoComment.Add(photoComment);
                entity.SaveChanges();
                entity.Entry(photoComment);

                createPhotoCommentFlag = 1;
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                createPhotoCommentFlag = 0;
            }
            var returnJson = new {
                PhotoCommentByID       = photoComment.PhotoCommentId.ToString(),
                createPhotoCommentFlag = createPhotoCommentFlag,
            };

            return(Json(returnJson));
        }
Ejemplo n.º 6
0
        public ResponseModel <string> AddPhotoComment(PhotoCommentModel model)
        {
            ResponseModel <string> response = new ResponseModel <string> {
                Data = ""
            };

            try
            {
                PhotoComment _comment = new PhotoComment();
                _comment.PhotoId   = model.PhotoId;
                _comment.IsActive  = true;
                _comment.CreatedOn = DateTime.Now;
                _comment.Comment   = model.Comment;
                acmContext.PhotoComment.Add(_comment);
                acmContext.SaveChanges();
                response.Status  = true;
                response.Message = "success";
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public async Task AddPhotoComment(PhotoId photoId, UserId userId, string userName, string text)
        {
            logWriter.LogInformation($"{nameof(AddPhotoComment)}({nameof(photoId)} = '{photoId}', {nameof(userId)} = '{userId}', {nameof(userName)} = '{userName}', {nameof(text)} = '{text}')");

            if (string.IsNullOrWhiteSpace(text))
            {
                throw new Exception("Cannot add empty comments.");
            }

            PhotoComment comment = new PhotoComment
            {
                PhotoId     = photoId,
                UserId      = userId,
                UserName    = userName,
                Text        = text,
                CreatedTime = DateTimeOffset.UtcNow
            };

            try
            {
                await commentRepository.AddPhotoComment(comment);
            }
            catch (Exception ex)
            {
                logWriter.LogError(ex, $"{nameof(AddPhotoComment)}({nameof(photoId)} = '{photoId}', {nameof(userId)} = '{userId}', {nameof(userName)} = '{userName}', {nameof(text)} = '{text}'):\n{ex.ToString()}");
                throw;
            }
        }
Ejemplo n.º 8
0
        public ActionResult DeleteConfirmed(int id)
        {
            PhotoComment photoComment = db.PhotoComments.Find(id);

            db.PhotoComments.Remove(photoComment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
 public void VisitPhotoComment(PhotoComment obj, JToken data)
 {
     obj.Id      = data.SafeGetValue <String>("id");
     obj.FromId  = data.SafeGetValue <String>("from_id");
     obj.CanEdit = data.SafeGetValue <Boolean>("can_edit");
     obj.Date    = data.SafeGetValue <Int64>("date").ToDateTimeFromUnixTime();
     obj.Text    = data.SafeGetValue <String>("text");
 }
Ejemplo n.º 10
0
        public PhotoComment CreateComment(PhotoComment comment)
        {
            PhotoCommentPO commentPO = comment.ToPhotoCommentPO();

            commentPO.CreatedOn = DateTime.Now.ToUniversalTime();
            Database.GetCollection <PhotoCommentPO>(Collections.PhotoComments).Save(commentPO);
            return(commentPO.ToPhotoComment());
        }
Ejemplo n.º 11
0
 public ActionResult AddPhotoComment(int id, PhotoComment photoComment)
 {
     photoComment.ApplicationUserID = User.Identity.GetUserId();
     photoComment.PhotoID           = id;
     db.PhotoComments.Add(photoComment);
     db.SaveChanges();
     return(RedirectToAction("Photo", "Home", new { id = id }));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Create a new PhotoComment object.
        /// </summary>
        /// <param name="id">Initial value of Id.</param>
        /// <param name="comment">Initial value of Comment.</param>
        /// <param name="dateTime">Initial value of DateTime.</param>
        public static PhotoComment CreatePhotoComment(global::System.Guid id, string comment, global::System.DateTime dateTime)
        {
            PhotoComment photoComment = new PhotoComment();

            photoComment.Id       = id;
            photoComment.Comment  = comment;
            photoComment.DateTime = dateTime;
            return(photoComment);
        }
Ejemplo n.º 13
0
        public JsonResult Create(PhotoComment comment)
        {
            try {
                MediaClient client = new MediaClient(base.userToken.access_token);
                ApiSingleResponse <Comment> response = client.Comment(comment.id, Server.UrlEncode(comment.text));

                return(Json(new { success = true }));
            } catch { return(Json(new { success = false })); }
        }
Ejemplo n.º 14
0
        public ActionResult DeletePhotoComment(int id)
        {
            PhotoComment photoComment = db.PhotoComments.Find(id);
            int          photoId      = photoComment.PhotoID;

            db.PhotoComments.Remove(photoComment);
            db.SaveChanges();
            return(RedirectToAction("Photo", "Home", new { id = photoId }));
        }
Ejemplo n.º 15
0
        public JsonResult Create(PhotoComment comment)
        {
            try {
                MediaClient client = new MediaClient(base.userToken.access_token);
                ApiSingleResponse<Comment> response = client.Comment(comment.id, Server.UrlEncode(comment.text));

                return Json(new { success = true });
            } catch { return Json(new { success = false }); }
        }
Ejemplo n.º 16
0
 PhotoCommentViewModel MapToPhotoCommentViewModel(PhotoComment photoComment)
 {
     return(new PhotoCommentViewModel()
     {
         Id = photoComment.Id,
         CreatedBy = photoComment.CreatedBy,
         CreatedOn = photoComment.CreatedOn,
         Contents = photoComment.Contents
     });
 }
Ejemplo n.º 17
0
        public PhotoComment CreateComment(PhotoComment comment)
        {
            PhotoComment result = null;

            ServiceSupport.AuthorizeAndExecute(() =>
            {
                result = PhotoRepository.CreateComment(comment);
            });
            return(result);
        }
Ejemplo n.º 18
0
 public void CreateComment(PhotoCommentDTO photoCommentDto)
 {
     using (UnitOfWork unitOfWork = new UnitOfWork(new PhotoManagerDbContext()))
     {
         PhotoComment photoComment = Mapper.Map <PhotoComment>(photoCommentDto);
         photoComment.Created = DateTime.Now;
         photoComment.UserId  = WebSecurityService.GetCurrentUser().UserId;
         unitOfWork.PhotoComments.Add(photoComment);
         unitOfWork.Complete();
     }
 }
        public void FromDbItem_FullyPopulated_ExpectedContent()
        {
            Dictionary <string, AttributeValue> input = GetPopulatedDbItem();
            PhotoComment result = Mappers.PhotoComment.FromDbItem(input);

            result.CreatedTime.ShouldBe(createdTime);
            result.PhotoId.ShouldBe(photoId);
            result.UserId.ShouldBe(userId);
            result.UserName.ShouldBe(userName);
            result.Text.ShouldBe(text);
        }
Ejemplo n.º 20
0
 public static PublicPhotoComment ToPublic(this PhotoComment input)
 {
     return(new PublicPhotoComment
     {
         PhotoId = input.PhotoId,
         UserId = input.UserId,
         UserName = input.UserName,
         Text = input.Text,
         Time = input.CreatedTime.UtcDateTime
     });
 }
Ejemplo n.º 21
0
        public static PhotoComment ToPhotoComment(this PhotoCommentPO po)
        {
            PhotoComment result = new PhotoComment();

            result.Id        = po.Id;
            result.PhotoId   = po.PhotoId;
            result.AlbumId   = po.AlbumId;
            result.Contents  = po.Contents;
            result.CreatedBy = po.CreatedBy;
            result.CreatedOn = po.CreatedOn;
            return(result);
        }
Ejemplo n.º 22
0
        public static PhotoCommentPO ToPhotoCommentPO(this PhotoComment entity)
        {
            PhotoCommentPO result = new PhotoCommentPO();

            result.Id        = entity.Id;
            result.PhotoId   = entity.PhotoId;
            result.AlbumId   = entity.AlbumId;
            result.Contents  = entity.Contents;
            result.CreatedBy = entity.CreatedBy;
            result.CreatedOn = entity.CreatedOn;
            return(result);
        }
Ejemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "Id,Content,DateCreated,PhotoId,UserId")] PhotoComment photoComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(photoComment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PhotoId = new SelectList(db.Photos, "Id", "Title", photoComment.PhotoId);
     ViewBag.UserId  = new SelectList(db.Users, "Id", "UserName", photoComment.UserId);
     return(View(photoComment));
 }
Ejemplo n.º 24
0
        public ActionResult Create([Bind(Include = "Id,Content,DateCreated,PhotoId,UserId")] PhotoComment photoComment)
        {
            if (ModelState.IsValid)
            {
                db.PhotoComments.Add(photoComment);
                db.SaveChanges();
                return(RedirectToAction("Index", "Photos"));
            }

            ViewBag.PhotoId = new SelectList(db.Photos, "Id", "Title", photoComment.PhotoId);
            ViewBag.UserId  = new SelectList(db.Users, "Id", "UserName", photoComment.UserId);
            return(RedirectToAction("Index", "Photos"));
        }
Ejemplo n.º 25
0
        // GET: PhotoComments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhotoComment photoComment = db.PhotoComments.Find(id);

            if (photoComment == null)
            {
                return(HttpNotFound());
            }
            return(View(photoComment));
        }
Ejemplo n.º 26
0
        // GET: PhotoComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhotoComment photoComment = db.PhotoComments.Find(id);

            if (photoComment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PhotoId = new SelectList(db.Photos, "Id", "Title", photoComment.PhotoId);
            ViewBag.UserId  = new SelectList(db.Users, "Id", "UserName", photoComment.UserId);
            return(View(photoComment));
        }
        public ActionResult deletePhotoCommentByID(string commentID)
        {
            int deletePhotoCommentFlag = 0;

            try {
                PhotoComment photoComment = entity.PhotoComment.Single(c => c.PhotoCommentId == int.Parse(commentID));
                entity.PhotoComment.Remove(photoComment);
                entity.SaveChanges();

                deletePhotoCommentFlag = 1;
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                deletePhotoCommentFlag = 0;
            }
            return(Json(new { deletePhotoCommentFlag = deletePhotoCommentFlag }));
        }
Ejemplo n.º 28
0
        void PostComment(string contents)
        {
            if (IsLoadingComments)
            {
                return;
            }

            CanPostComment = false;
            PhotoComment comment = new PhotoComment();

            comment.Contents  = contents;
            comment.CreatedBy = SecurityContext.Current.User.Name;
            comment.PhotoId   = Id;
            comment.AlbumId   = AlbumId;
            PhotoServiceClient svc = new PhotoServiceClient();

            try
            {
                svc.CreateCommentCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        e.Error.Handle();
                    }
                    else
                    {
                        if (_comments != null)
                        {
                            _comments.Insert(0, MapToPhotoCommentViewModel(e.Result));
                        }
                    }
                    CanPostComment  = true;
                    CommentContents = string.Empty;
                    NotifyOfPropertyChange(() => HasComment);
                };
                svc.CreateCommentAsync(comment);
            }
            catch
            {
                CanPostComment = true;
            }
        }
        public async Task DeletePhotoComment(PhotoComment comment)
        {
            var photo = await photoRepository.GetPhotoById(comment.PhotoId, Guid.Empty);

            var deleteCommentRequest = new DeleteItemRequest
            {
                TableName = tableName,
                Key       = Mappers.PhotoComment.ToDbKey(comment)
            };

            try
            {
                await dynamoDbCore.DeleteItem(deleteCommentRequest);
                await UpdateCommentCount(photo, photo.CommentCount - 1);
            }
            catch (Exception ex)
            {
                logWriter.LogError(ex, $"Error in {nameof(DeletePhotoComment)}():\n{ex.ToString()}");
                throw;
            }
        }
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response"> Ответ сервера. </param>
        /// <returns> </returns>
        public static GroupUpdate FromJson(VkResponse response)
        {
            var fromJson = JsonConvert.DeserializeObject <GroupUpdate>(response.ToString());

            var resObj = response["object"];

            switch (fromJson.Type)
            {
            case GroupLongPollUpdateType.MessageNew:
            case GroupLongPollUpdateType.MessageEdit:
            case GroupLongPollUpdateType.MessageReply:
                fromJson.Message = resObj;
                fromJson.UserId  = fromJson.Message.FromId;
                break;

            case GroupLongPollUpdateType.MessageAllow:
                fromJson.MessageAllow = MessageAllow.FromJson(resObj);
                fromJson.UserId       = fromJson.MessageAllow.UserId;
                break;

            case GroupLongPollUpdateType.MessageDeny:
                fromJson.MessageDeny = MessageDeny.FromJson(resObj);
                fromJson.UserId      = fromJson.MessageDeny.UserId;
                break;

            case GroupLongPollUpdateType.PhotoNew:
                fromJson.Photo = resObj;
                break;

            case GroupLongPollUpdateType.PhotoCommentNew:
            case GroupLongPollUpdateType.PhotoCommentEdit:
            case GroupLongPollUpdateType.PhotoCommentRestore:
                fromJson.PhotoComment = PhotoComment.FromJson(resObj);
                fromJson.UserId       = fromJson.PhotoComment.FromId;
                break;

            case GroupLongPollUpdateType.PhotoCommentDelete:
                fromJson.PhotoCommentDelete = PhotoCommentDelete.FromJson(resObj);
                fromJson.UserId             = fromJson.PhotoCommentDelete.DeleterId;
                break;

            case GroupLongPollUpdateType.AudioNew:
                fromJson.Audio = resObj;
                break;

            case GroupLongPollUpdateType.VideoNew:
                fromJson.Video = resObj;
                break;

            case GroupLongPollUpdateType.VideoCommentNew:
            case GroupLongPollUpdateType.VideoCommentEdit:
            case GroupLongPollUpdateType.VideoCommentRestore:
                fromJson.VideoComment = VideoComment.FromJson(resObj);
                fromJson.UserId       = fromJson.VideoComment.FromId;
                break;

            case GroupLongPollUpdateType.VideoCommentDelete:
                fromJson.VideoCommentDelete = VideoCommentDelete.FromJson(resObj);
                fromJson.UserId             = fromJson.VideoCommentDelete.DeleterId;
                break;

            case GroupLongPollUpdateType.WallPostNew:
            case GroupLongPollUpdateType.WallRepost:
                fromJson.WallPost = WallPost.FromJson(resObj);
                fromJson.UserId   = fromJson.WallPost.FromId > 0 ? fromJson.WallPost.FromId : null;
                break;

            case GroupLongPollUpdateType.WallReplyNew:
            case GroupLongPollUpdateType.WallReplyEdit:
            case GroupLongPollUpdateType.WallReplyRestore:
                fromJson.WallReply = WallReply.FromJson(resObj);
                fromJson.UserId    = fromJson.WallReply.FromId;
                break;

            case GroupLongPollUpdateType.WallReplyDelete:
                fromJson.WallReplyDelete = WallReplyDelete.FromJson(resObj);
                fromJson.UserId          = fromJson.WallReplyDelete.DeleterId;
                break;

            case GroupLongPollUpdateType.BoardPostNew:
            case GroupLongPollUpdateType.BoardPostEdit:
            case GroupLongPollUpdateType.BoardPostRestore:
                fromJson.BoardPost = BoardPost.FromJson(resObj);
                fromJson.UserId    = fromJson.BoardPost.FromId > 0 ? fromJson.BoardPost.FromId : (long?)null;
                break;

            case GroupLongPollUpdateType.BoardPostDelete:
                fromJson.BoardPostDelete = BoardPostDelete.FromJson(resObj);
                break;

            case GroupLongPollUpdateType.MarketCommentNew:
            case GroupLongPollUpdateType.MarketCommentEdit:
            case GroupLongPollUpdateType.MarketCommentRestore:
                fromJson.MarketComment = MarketComment.FromJson(resObj);
                fromJson.UserId        = fromJson.MarketComment.FromId;
                break;

            case GroupLongPollUpdateType.MarketCommentDelete:
                fromJson.MarketCommentDelete = MarketCommentDelete.FromJson(resObj);
                fromJson.UserId = fromJson.MarketCommentDelete.DeleterId;
                break;

            case GroupLongPollUpdateType.GroupLeave:
                fromJson.GroupLeave = GroupLeave.FromJson(resObj);
                fromJson.UserId     = fromJson.GroupLeave.IsSelf == true ? fromJson.GroupLeave.UserId : null;
                break;

            case GroupLongPollUpdateType.GroupJoin:
                fromJson.GroupJoin = GroupJoin.FromJson(resObj);
                fromJson.UserId    = fromJson.GroupJoin.UserId;
                break;

            case GroupLongPollUpdateType.UserBlock:
                fromJson.UserBlock = UserBlock.FromJson(resObj);
                fromJson.UserId    = fromJson.UserBlock.AdminId;
                break;

            case GroupLongPollUpdateType.UserUnblock:
                fromJson.UserUnblock = UserUnblock.FromJson(resObj);
                fromJson.UserId      = fromJson.UserUnblock.ByEndDate == true ? null : fromJson.UserUnblock.AdminId;
                break;

            case GroupLongPollUpdateType.PollVoteNew:
                fromJson.PollVoteNew = PollVoteNew.FromJson(resObj);
                fromJson.UserId      = fromJson.PollVoteNew.UserId;
                break;

            case GroupLongPollUpdateType.GroupChangePhoto:
                fromJson.GroupChangePhoto = GroupChangePhoto.FromJson(resObj);
                fromJson.UserId           = fromJson.GroupChangePhoto.UserId;
                break;

            case GroupLongPollUpdateType.GroupOfficersEdit:
                fromJson.GroupOfficersEdit = GroupOfficersEdit.FromJson(resObj);
                fromJson.UserId            = fromJson.GroupOfficersEdit.AdminId;
                break;
            }

            return(fromJson);
        }
Ejemplo n.º 31
0
 /// <summary>
 /// There are no comments for PhotoComment in the schema.
 /// </summary>
 public void AddToPhotoComment(PhotoComment photoComment)
 {
     base.AddObject("PhotoComment", photoComment);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Create a new PhotoComment object.
 /// </summary>
 /// <param name="id">Initial value of Id.</param>
 /// <param name="comment">Initial value of Comment.</param>
 /// <param name="dateTime">Initial value of DateTime.</param>
 public static PhotoComment CreatePhotoComment(global::System.Guid id, string comment, global::System.DateTime dateTime)
 {
     PhotoComment photoComment = new PhotoComment();
     photoComment.Id = id;
     photoComment.Comment = comment;
     photoComment.DateTime = dateTime;
     return photoComment;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// There are no comments for PhotoComment in the schema.
 /// </summary>
 public void AddToPhotoComment(PhotoComment photoComment)
 {
     base.AddObject("PhotoComment", photoComment);
 }