public string AddComment(Guid id, string name, string title, string message)
        {
            if (id == Guid.Empty)
            {
                return("خطا در ارسال نظر");
            }
            if (string.IsNullOrEmpty(name))
            {
                return("لطفا نام خود را وارد کنید");
            }
            if (string.IsNullOrEmpty(title))
            {
                return("لطفا عنوان را وارد کنید");
            }
            if (string.IsNullOrEmpty(message))
            {
                return("نظر خود را بنویسید");
            }
            var obj = new UserComments()
            {
                ProductId = id,
                FullName  = name,
                Title     = title,
                Message   = message,
                IsAccept  = false
            };

            db.UserComments.Add(obj);
            db.SaveChanges();
            return("نطر شما با موفقیت ثبت شد");
        }
        /// <summary>
        /// Edits a user review
        /// </summary>
        /// <param name="id"> Identifier for the edited comments </param>
        /// <param name="userComments">Identifier for the UserComments</param>
        /// <returns> edited review</returns>
        public async Task <IActionResult> Edit(int id, [Bind(" ID, UserID, TrailID, UserComment")] UserComments userComments)
        {
            if (id != userComments.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userComments);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserReviewExists(userComments.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userComments));
        }
 public async Task <int> Save(UserComments userComments)
 {
     using (var db = _context)
     {
         db.UserComments.Add(userComments);
         return(await db.SaveChangesAsync());
     }
 }
        private async Task <ResponseComment> GetFullCommentInfo(UserComments comment)
        {
            var com         = _mapper.Map <ResponseComment>(comment);
            var commentUser = await _userContext.Users.Find(c => c.Id == comment.UserId).FirstOrDefaultAsync();

            com.User = _mapper.Map <ResponseUser>(commentUser);
            return(com);
        }
        public void CanGetUserReviewUserComment()
        {
            UserComments userComment = new UserComments()
            {
                UserComment = "Was Fun"
            };

            Assert.Equal("Was Fun", userComment.UserComment);
        }
        public void CanGetUserReviewUserID()
        {
            UserComments userComment = new UserComments()
            {
                UserInfoID = 1
            };

            Assert.Equal(1, userComment.UserInfoID);
        }
        public void CanGetUserReviewTrailID()
        {
            UserComments userComment = new UserComments()
            {
                TrailID = 1
            };

            Assert.Equal(1, userComment.TrailID);
        }
示例#8
0
 //POST:/Users/GetSmallComments
 public IActionResult GetSmallComments(UserComments mymodel)
 {
     if (!ModelState.IsValid)
     {
         return(View(mymodel));
     }
     mymodel.Comments = DataService.GetSmallComments(mymodel.User.Id);
     mymodel.User     = DataService.GetUserById(mymodel.User.Id);
     return(View(mymodel));
 }
        public void CanSetUserReviewUserComment()
        {
            UserComments userReviews = new UserComments()
            {
                UserComment = "Was Fun"
            };

            userReviews.UserComment = "Nevermind";

            Assert.Equal("Nevermind", userReviews.UserComment);
        }
        public void CanSetUserReviewID()
        {
            UserComments userComment = new UserComments()
            {
                ID = 1
            };

            userComment.ID = 2;

            Assert.Equal(2, userComment.ID);
        }
        public async Task <IHttpActionResult> GetCommentDTO(int id)
        {
            UserComments commentDTO = await db.UserComments.FindAsync(id);

            if (commentDTO == null)
            {
                return(NotFound());
            }

            return(Ok(commentDTO));
        }
示例#12
0
 internal void AddUserComment(string s)
 {
     if (UserComments == null)
     {
         UserComments = new List <string>();
     }
     if (!UserComments.Contains(s))
     {
         UserComments.Add(s);
     }
 }
        public async Task <IActionResult> Create([Bind(" ID, UserID, TrailID, UserComment")] UserComments userComments)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userComments);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userComments));
        }
示例#14
0
        /// <exception cref="ImgurException"/>
        private async Task <IList <IComment> > ReadCommentsSince(
            DateTimeOffset SinceExclusive,
            string ByUsername,
            short RequestsLimit
            )
        {
            List <IComment> Result       = new List <IComment>();
            ushort          RequestCount = 0;
            int             page         = 0;
            bool            more;
            DateTimeOffset  OldestCommentDateTime = DateTimeOffset.MinValue;

            do
            {
                if (RequestCount >= RequestsLimit && RequestsLimit > 0)
                {
                    Log.Imgur_.LogWarning(
                        "Reached API call limit whilst retrieving Comments for User '{0}' since {1}; not all Comments since that point will have been retrieved and processed",
                        ByUsername, SinceExclusive
                        );
                    break;
                }
                IList <IComment> UserComments;
                try{
                    UserComments = (
                        //Pages start from 0
                        await APIUserAccount.GetCommentsAsync(ByUsername, CommentSortOrder.Newest, page++)
                        ).ToList();
                }catch (ImgurException) {
                    throw;
                }catch (HttpRequestException Error) {
                    throw ToImgurException(Error);
                }catch (TaskCanceledException Error) {
                    throw ToImgurException(Error);
                }
                Result.AddRange(UserComments);
                more = UserComments.Count >= CommentsPerPage;
                if (UserComments.Count > 0)
                {
                    OldestCommentDateTime = UserComments.Last().DateTime;
                }
                ++RequestCount;
                //Keep pulling Comments pages until the oldest Comment pulled is from at or before SinceExclusive
            }while(more && OldestCommentDateTime > SinceExclusive);
            //Remove any Comments from the last Comments page that were from at or before SinceExclusive
            return((
                       from C in Result
                       where C.DateTime > SinceExclusive
                       select C
                       ).ToList());
        }
        public async Task <int> Delete(int id)
        {
            using (var db = _context)
            {
                UserComments userComments = db.UserComments.Find(id);
                if (userComments == null)
                {
                    return(0);
                }

                db.UserComments.Remove(userComments);
                return(await db.SaveChangesAsync());
            }
        }
        public async Task <IHttpActionResult> DeleteCommentDTO(int id)
        {
            UserComments commentDTO = await db.UserComments.FindAsync(id);

            if (commentDTO == null)
            {
                return(NotFound());
            }

            db.UserComments.Remove(commentDTO);
            await db.SaveChangesAsync();

            return(Ok(commentDTO));
        }
示例#17
0
        public async Task <IActionResult> Create(TrailDetails trailDetails)
        {
            UserComments comment = new UserComments()
            {
                TrailID     = trailDetails.Trail.TrailID,
                UserInfoID  = trailDetails.UserComment.UserInfoID,
                UserComment = trailDetails.UserComment.UserComment,
            };

            int id = trailDetails.Trail.TrailID;
            await _trail.AddComment(comment);

            return(RedirectToAction("Details", new { id }));
        }
            public async Task <SendCommentDTO> Handle(Command request, CancellationToken cancellationToken)
            {
                var sender = await dataContext.Users.FirstOrDefaultAsync(x => x.Id == currentUser.UserId);

                if (sender is null)
                {
                    throw new HttpContextException(HttpStatusCode.NotFound, new { User = "******" });
                }

                var advertise = await dataContext.Advertise.Where(x => x.UniqueId == request.AdvertiseId)
                                .FirstOrDefaultAsync();

                ModelInput sampleData = new ModelInput()
                {
                    Comment = request.Comment,
                };

                // Make a single prediction on the sample data and print results
                var predictionResult = ConsumeModel.Predict(sampleData);


                var userComment = new UserComments
                {
                    Advertise        = advertise,
                    Commenter        = sender,
                    CommentedAt      = DateTime.UtcNow,
                    Comment          = request.Comment,
                    PositiveAccuracy = predictionResult.Score[0],
                    NegativeAccuracy = predictionResult.Score[1]
                };
                await dataContext.UserComments.AddAsync(userComment);

                var success = await dataContext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(new SendCommentDTO
                    {
                        Comment = userComment.Comment,
                        CommentedAt = userComment.CommentedAt,
                        DisplayName = $"{userComment.Commenter.FirstName} {userComment.Commenter.LastName}"
                    });
                }
                else
                {
                    throw new Exception("ERROR WHILE SENDING Comment");
                }
            }
示例#19
0
        public async Task <Operate> AddOrUpdate(UserComments model)
        {
            var result = new Operate();

            try
            {
                await AddOrUpdateUserComments(model);
            }
            catch (Exception ex)
            {
                result.Status  = -1;
                result.Message = ex.Message;
                Logger.WriteErrorLog(ex);
            }
            return(result);
        }
示例#20
0
        public void TestAddCommentNameField()
        {
            //Arrange
            FakeRepository fakeRepo       = new FakeRepository();
            HomeController homeController = new HomeController(fakeRepo);
            UserComments   uC1            = new UserComments()
            {
                Name    = "Brian",
                Comment = "Test Comment 1"
            };

            //Act
            homeController.AddComment(uC1.Name, uC1.Comment);

            //Assert
            Assert.Equal("Brian", fakeRepo.Comments[0].Name);
        }
示例#21
0
        /// <summary>
        /// Hash code for the Metadata for equality checks
        /// </summary>
        public override int GetHashCode()
        {
            // Get the hash code for the Date field if it is not null.
            int hashDate = Date == null ? 0 : Date.GetHashCode();

            // Get the hash code for the Description field.
            int hashMerchant = Merchant.GetHashCode();

            // Get the hash code for the UserComments field.
            int hashUserComments = UserComments.GetHashCode();

            // Get the hash code for the Amount field.
            int hashAmount = Amount.GetHashCode();

            // Calculate the hash code for the transaction.
            return(hashDate ^ hashMerchant ^ hashUserComments ^ hashAmount);
        }
示例#22
0
 void LoadUserComments(children child)
 {
     if (!string.IsNullOrWhiteSpace(child.author))
     {
         if (!UserComments.ContainsKey(child.author))
         {
             UserComments[child.author] = new List <CommentObj>();
         }
         UserComments[child.author].Add(new CommentObj()
         {
             Id = child.id, Text = child.text
         });
     }
     foreach (children childNode in child.Children)
     {
         LoadUserComments(childNode);
     }
 }
示例#23
0
        public UserComments Exec(SqlConnection db, AuthenticatedUser au, int skip, int take)
        {
            var retComments = new UserComments();

            foreach (var item in repository.UserComments(db, au.Id, skip, take, ref retComments.total))
            {
                retComments.list.Add(new UserCommentInformation
                {
                    Comment         = item.Comment,
                    Date            = item.DateAdded,
                    ProductName     = "x",
                    ProductCategory = "y",
                    ProductId       = 1
                });
            }

            return(retComments);
        }
示例#24
0
        public async Task <JsonNetResult> ByUser(GetUserCommentsViewModel model)
        {
            // If no user was specified, default to the current logged in user
            Guid?userId = model.UserId ?? User.GetCurrentUserId();

            if (userId == null)
            {
                ModelState.AddModelError(string.Empty, "No user specified and no user currently logged in.");
                return(JsonFailure());
            }

            // Get a page of comments for the user, then look up video details for those videos
            UserComments result = await _comments.GetUserComments(new GetUserComments
            {
                UserId               = userId.Value,
                PageSize             = model.PageSize,
                FirstCommentIdOnPage = model.FirstCommentIdOnPage
            });

            // For the ViewModel, we want to add information about the video to each comment as well, so get the video preview
            // information for the comments and then use a LINQ to objects Join to merge the two together (this should be OK since
            // the dataset should be small since we're doing a page at a time)
            IEnumerable <VideoPreview> videoPreviews = await _videoCatalog.GetVideoPreviews(result.Comments.Select(c => c.VideoId).ToHashSet());

            var returnModel = new UserCommentsViewModel
            {
                UserId   = result.UserId,
                Comments = result.Comments.Join(videoPreviews, c => c.VideoId, vp => vp.VideoId, (c, vp) => new UserCommentViewModel
                {
                    CommentId                 = c.CommentId,
                    Comment                   = c.Comment,
                    CommentTimestamp          = c.CommentTimestamp,
                    VideoViewUrl              = Url.Action("View", "Videos", new { videoId = c.VideoId }),
                    VideoName                 = vp.Name,
                    VideoPreviewImageLocation = vp.PreviewImageLocation
                }).ToList()
            };

            return(JsonSuccess(returnModel));
        }
        public async Task <int> Update(UserComments userComments)
        {
            using (var db = _context)
            {
                db.Entry(userComments).State = EntityState.Modified;

                try
                {
                    return(await db.SaveChangesAsync());
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserCommentsExists(userComments.Id))
                    {
                        throw;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
        public async Task <IHttpActionResult> PostCommentDTO([FromBody] CommentDTO commentDTO)
        {
            var vidId = commentDTO.Video_id;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //if the user comment is equal to minus 1 then it is a comment on a video
            //else if the id is greater than 0 then it is a reply to a comment
            if (commentDTO.Id == -1)
            {
                UserComments userComment = new UserComments
                {
                    Comment  = commentDTO.Comment,
                    UserName = User.Identity.Name
                };
                var video = db.Videos.Find(vidId);
                video.Comments.Add(userComment);
            }
            else
            {
                UserComments userComment = new UserComments
                {
                    Comment  = commentDTO.Comment,
                    UserName = User.Identity.Name
                };

                var comment = db.UserComments.Find(commentDTO.Id);
                comment.Replies.Add(userComment);
            }

            await db.SaveChangesAsync();

            return(Ok("success"));
        }
示例#27
0
 public void Add(UserComments entity)
 {
     throw new NotImplementedException();
 }
示例#28
0
 private async Task AddOrUpdateUserComments(UserComments entity)
 {
     await userCommentsAgent.AddOrUpdate(entity);
 }
 public async Task <Operate> AddOrUpdate(UserComments model)
 {
     return(await userCommentsBLL.AddOrUpdate(model));
 }
示例#30
0
 public void Delete(UserComments comment)
 {
     _entities.DeleteObject(comment);
 }
示例#31
0
        public async Task AddComment(UserComments userComment)
        {
            await _context.UserComments.AddAsync(userComment);

            await _context.SaveChangesAsync();
        }
 public async Task AddComment(UserComments comment)
 {
 }