예제 #1
0
        public void RateResource(RoadStep roadStep, int stepResourceId, RatingValue ratingValue)
        {
            var stepResource    = roadStep.StepResources.FirstOrDefault(p => p.Id == stepResourceId);
            var studentRoadStep = StudentRoadStep(roadStep);

            studentRoadStep.RateResource(stepResource, ratingValue);
        }
예제 #2
0
        /// <summary>
        /// Decrease or increase rating by delta
        /// </summary>
        /// <param name="value">Star 1-2-3-4-5</param>
        /// <param name="delta">+/- Delta</param>
        public void UpdateRating(RatingValue value, int delta)
        {
            var isNegative = delta < 0;
            var abs        = (ulong)Math.Abs(delta);

            switch (value)
            {
            // if isNegative == true and rating counter == 0, decreasing ulong will make field MAX ulong.
            // so, need to check it
            case RatingValue.Star1:
                if (isNegative && Rating1 == 0)
                {
                    break;
                }
                Rating1 = isNegative
            ? Rating1 - abs
            : Rating1 + abs;
                break;

            case RatingValue.Star2:
                if (isNegative && Rating2 == 0)
                {
                    break;
                }
                Rating2 = isNegative
            ? Rating2 - abs
            : Rating2 + abs;
                break;

            case RatingValue.Star3:
                if (isNegative && Rating3 == 0)
                {
                    break;
                }
                Rating3 = isNegative
            ? Rating3 - abs
            : Rating3 + abs;
                break;

            case RatingValue.Star4:
                if (isNegative && Rating4 == 0)
                {
                    break;
                }
                Rating4 = isNegative
            ? Rating4 - abs
            : Rating4 + abs;
                break;

            case RatingValue.Star5:
                if (isNegative && Rating5 == 0)
                {
                    break;
                }
                Rating5 = isNegative
            ? Rating5 - abs
            : Rating5 + abs;
                break;
            }
        }
예제 #3
0
 public StepResourceRating(int id, string name, string description, RatingValue ratingValue)
 {
     Id          = id;
     Name        = name;
     Description = description;
     RatingValue = ratingValue;
 }
예제 #4
0
 public StudentResourceRating(StudentXRoadStep studentXRoadStep, StepResource stepResource, RatingValue ratingValue)
 {
     StudentXRoadStep = studentXRoadStep;
     CreateDate       = DateTime.Now;
     StepResource     = stepResource;
     RatingValue      = ratingValue;
 }
예제 #5
0
        public override GraphChangeStatus Update(CommentID ratingId, RatingValue value, string content, byte[] data)
        {
            var pair = HostSet.AssignHost(ratingId.G_Volume);

            return(Contracts.ServiceClientHub
                   .CallWithRetry <IGraphCommentSystemClient, GraphChangeStatus>(
                       commentSystem => commentSystem.Update(ratingId, value, content, data),
                       pair.Select(host => host.RegionPath)
                       ));
        }
예제 #6
0
파일: GraphServers.cs 프로젝트: saleyn/agni
 /// <summary>
 /// Create new comment with rating
 /// </summary>
 /// <param name="gAuthorNode">GDID of autor node</param>
 /// <param name="gTargetNode">GDID of target node</param>
 /// <param name="dimension">Scope for rating</param>
 /// <param name="content">Content</param>
 /// <param name="data">Byte array of data</param>
 /// <param name="publicationState">State of publication</param>
 /// <param name="value">star 1-2-3-4-5</param>
 /// <param name="timeStamp">Time of current action</param>
 /// <returns>Comment</returns>
 public Comment Create(GDID gAuthorNode,
                       GDID gTargetNode,
                       string dimension,
                       string content,
                       byte[] data,
                       PublicationState publicationState,
                       RatingValue value  = RatingValue.Undefined,
                       DateTime?timeStamp = null)
 {
     return(Comments.Create(gAuthorNode, gTargetNode, dimension, content, data, publicationState, value, timeStamp));
 }
예제 #7
0
        /// <summary>
        /// Updates existing rating by ID
        /// </summary>
        public GraphChangeStatus Update(CommentID commentId, RatingValue value, string content, byte[] data)
        {
            if (commentId.IsZero)
            {
                return(GraphChangeStatus.NotFound);
            }

            try
            {
                // Taking comment row
                var currentDateTime = App.TimeSource.UTCNow;
                var ctxComment      = ForComment(commentId.G_Volume); // CRUD context for comment
                var comment         = getCommentRow(commentId, ctxComment);
                if (comment == null)
                {
                    return(GraphChangeStatus.NotFound);
                }

                var targetNode = DoGetNode(comment.G_TargetNode);
                if ((currentDateTime - comment.Create_Date) > GraphHost.EditCommentSpan(targetNode, comment.Dimension))
                {
                    return(GraphChangeStatus.NotFound);
                }

                var ctxNode = ForNode(comment.G_TargetNode); // CRUD context for target node

                // Updating fields
                var filter = "Message,Data";
                comment.Message = content;
                comment.Data    = data;

                // if comment is root and rating value is not RatingValue.Undefined
                // Update rating
                if (comment.IsRoot && value != RatingValue.Undefined)
                {
                    // Update NodeRating
                    var nodeRating = getNodeRating(comment.G_TargetNode, comment.Dimension, ctxNode);
                    nodeRating.UpdateRating((RatingValue)comment.Rating, -1);
                    nodeRating.UpdateRating(value, 1);
                    ctxNode.Update(nodeRating, filter: "Last_Change_Date,Cnt,Rating1,Rating2,Rating3,Rating4,Rating5".OnlyTheseFields());

                    // Update rating value of comment
                    comment.Rating = (byte)value;
                    filter         = "Rating," + filter;
                }
                var resComment = ctxComment.Update(comment, filter: filter.OnlyTheseFields());
                return(resComment == 0 ? GraphChangeStatus.NotFound : GraphChangeStatus.Updated);
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "GraphCommentSystem.Update", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_UPDATE_RATING_ERROR.Args(commentId.G_Comment), ex);
            }
        }
 protected void Submit_Click(object sender, EventArgs e)
 {
     using (DBInteractiobDataContext Ratingcontext = new DBInteractiobDataContext())
     {
         RatingValue rv = new RatingValue();
         rv.ratingvalue1 = TextBox1.Text;
         Ratingcontext.RatingValues.InsertOnSubmit(rv);
         Ratingcontext.SubmitChanges();
         Response.Write("<script>alert('inserted successfully!!');</script>");
     }
 }
예제 #9
0
        public override Comment Create(GDID gAuthorNode, GDID gTargetNode, string dimension, string content, byte[] data,
                                       PublicationState publicationState, RatingValue rating = RatingValue.Undefined, DateTime?epoch = null)
        {
            var pair = HostSet.AssignHost(gTargetNode);

            return(Contracts.ServiceClientHub
                   .CallWithRetry <IGraphCommentSystemClient, Comment>(
                       commentSystem => commentSystem.Create(gAuthorNode, gTargetNode, dimension, content, data, publicationState, rating, epoch),
                       pair.Select(host => host.RegionPath)
                       ));
        }
예제 #10
0
 private async Task ProcessRatingButton(PostRating ratingByCurrentUser, RatingValue ratingValue)
 {
     if (ratingByCurrentUser.Value == ratingValue)
     {
         await _ratingRepository.Delete(ratingByCurrentUser.Id);
     }
     else
     {
         ratingByCurrentUser.Value = ratingValue;
         await _ratingRepository.Update(ratingByCurrentUser);
     }
 }
예제 #11
0
        public async Task <ActionResult <RatingValue> > Calculate([FromBody] SingleWorkRequest request)
        {
            var result = await ProcessSingleRequest(request).ConfigureAwait(false);

            var rating = result.Review.CalculateRawRating();
            var value  = new RatingValue();

            value.Stars    = rating.StarsRating;
            value.Negative = rating.Negative;
            value.Positive = rating.Positive;
            return(Ok(value));
        }
예제 #12
0
        public IHttpActionResult GetRatingValueForRecipe(int recipeId)
        {
            List <Rating> ratings = db.Ratings.Where(r => r.RecipeID == recipeId).ToList();
            double        value   = 0.0;

            if (ratings.Count > 0)
            {
                value = (double)ratings.Sum(r => r.Value) / (double)ratings.Count;
            }
            RatingValue rv = new RatingValue(recipeId, value);

            return(Ok(rv));
        }
예제 #13
0
파일: GraphHost.cs 프로젝트: saleyn/agni
        /// <summary>
        ///  Returns true if authorNode can create new comment of specified targetNode as of commentDate and
        ///  if rating value can be applied
        /// </summary>
        public virtual bool CanCreateComment(GraphNode authorNode,
                                             GraphNode targetNode,
                                             string dimension,
                                             DateTime commentDate,
                                             RatingValue rating)
        {
            var ratingRequired = CommentRatingRequired(targetNode.NodeType, dimension);

            if (ratingRequired && rating == RatingValue.Undefined)
            {
                return(false);
            }

            if (ratingRequired && !CanBeRatingActor(authorNode.NodeType, dimension))
            {
                return(false);
            }

            return(DoCanCreateComment(authorNode, targetNode, dimension, commentDate, rating));
        }
예제 #14
0
        /// <summary>
        /// Comment
        /// </summary>
        /// <param name="id">ID</param>
        /// <param name="parentId">Parent comment ID</param>
        /// <param name="authorNode">Author node</param>
        /// <param name="targetNode">Target node</param>
        /// <param name="createDate">Creation Date</param>
        /// <param name="dimension">Scope of comments</param>
        /// <param name="publicationState">Publication state</param>
        /// <param name="rating">Rating (0,1,2,3,4,5)</param>
        /// <param name="message">Message</param>
        /// <param name="data">Data</param>
        /// <param name="likes">Likes count</param>
        /// <param name="dislikes">Dislikes count</param>
        /// <param name="complaintCount">Complaint count</param>
        /// <param name="responseCount">Response count</param>
        /// <param name="inUse">In use (InUse = false - comment has been deleted)</param>
        /// <param name="editable">Can be edited</param>
        public Comment(CommentID id,
                       CommentID?parentId,
                       GraphNode authorNode,
                       GraphNode targetNode,
                       DateTime createDate,
                       string dimension,

                       PublicationState publicationState,
                       RatingValue rating,
                       string message,
                       byte[] data,

                       uint likes,
                       uint dislikes,
                       uint complaintCount,
                       uint responseCount,

                       bool inUse,
                       bool editable)
        {
            ID          = id;
            ParentID    = parentId;
            AuthorNode  = authorNode;
            TargetNode  = targetNode;
            Create_Date = createDate;
            Dimension   = dimension;

            PublicationState = publicationState;
            Rating           = rating;
            Message          = message;
            Data             = data;

            Likes          = likes;
            Dislikes       = dislikes;
            ComplaintCount = complaintCount;
            ResponseCount  = responseCount;

            IsRoot   = !parentId.HasValue;
            In_Use   = inUse;
            Editable = editable;
        }
예제 #15
0
        /// <summary>
        /// Create new comment with rating
        /// </summary>
        /// <param name="gAuthorNode">GDID of autor node</param>
        /// <param name="gTargetNode">GDID of target node</param>
        /// <param name="dimension">Scope for rating</param>
        /// <param name="content">Content</param>
        /// <param name="data">Byte array of data</param>
        /// <param name="publicationState">State of publication</param>
        /// <param name="value">star 1-2-3-4-5</param>
        /// <param name="timeStamp">Time of current action</param>
        /// <returns>ID</returns>
        Comment IGraphCommentSystem.Create(GDID gAuthorNode,
                                           GDID gTargetNode,
                                           string dimension,
                                           string content,
                                           byte[] data,
                                           PublicationState publicationState,
                                           RatingValue value,
                                           DateTime?timeStamp)
        {
            try
            {
                // 1. Get nodes for creation new comment
                var authorNode      = DoGetNode(gAuthorNode);
                var targetNode      = DoGetNode(gTargetNode);
                var currentDateTime = timeStamp ?? App.TimeSource.UTCNow;

                if (!GraphHost.CanCreateComment(authorNode, targetNode, dimension, currentDateTime, value))
                {
                    throw new GraphException(StringConsts.GS_CAN_NOT_CREATE_COMMENT_ERROR.Args(authorNode, targetNode, value));
                }

                return(DoCreate(targetNode,
                                authorNode,
                                null, dimension,
                                content,
                                data,
                                publicationState,
                                value,
                                currentDateTime));
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "GraphCommentSystem.Create()", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_CREATE_COMMENT_ERROR.Args(gTargetNode, gAuthorNode), ex);
            }
        }
예제 #16
0
 /// <summary>
 /// Make new Comment
 /// </summary>
 internal static Comment MakeNew(CommentID commentID, CommentID?parentID, GraphNode authorNode, GraphNode targetNode, DateTime create_Date, string dimension, PublicationState publicationState, RatingValue rating, string message, byte[] data)
 {
     return(new Comment(commentID, parentID, authorNode, targetNode, create_Date, dimension, publicationState, rating, message, data, 0, 0, 0, 0, true, true));
 }
예제 #17
0
 /// <inheritdoc />
 public override string ToString()
 {
     return($"{DataHandler.Title} {RatingValue.ToString()} (Rating ID: '{RatingId.ToString()}')");
 }
예제 #18
0
 public override GraphChangeStatus Update(CommentID ratingId, RatingValue value, string content, byte[] data)
 {
     return(GraphChangeStatus.NotFound);
 }
예제 #19
0
 protected override bool DoCanCreateComment(GraphNode authorNode, GraphNode targetNode, string dimension, DateTime commentDate, RatingValue rating)
 {
     throw new NotImplementedException();
 }
예제 #20
0
        /// <summary>
        /// Creating new comment
        /// </summary>
        /// <param name="targetNode">Target node</param>
        /// <param name="authorNode">Author node, who made comment</param>
        /// <param name="parentID">Parent comment id</param>
        /// <param name="dimension">Scope of comment</param>
        /// <param name="content">Content</param>
        /// <param name="data">Byte array of data</param>
        /// <param name="publicationState">State of publication</param>
        /// <param name="value">star 1-2-3-4-5</param>
        /// <param name="creationTime">Time of current action</param>
        /// <returns>ID</returns>
        protected virtual Comment DoCreate(GraphNode targetNode,
                                           GraphNode authorNode,
                                           CommentID?parentID,
                                           string dimension,
                                           string content,
                                           byte[] data,
                                           PublicationState publicationState,
                                           RatingValue value,
                                           DateTime?creationTime)
        {
            // Create comment and, if need, volume
            var ctxNode = ForNode(targetNode.GDID); // get shard context for target node
            var volume  = parentID.HasValue         // if we have parentID, we need to place response comment in same volume as parent
        ? getVolume(targetNode.GDID, parentID.Value.G_Volume, ctxNode)
        : getEmptyVolume(targetNode.GDID, dimension, ctxNode);

            if (volume == null)
            {
                throw new GraphException(StringConsts.GS_RESPONSE_VOLUME_MISSING_ERROR);
            }

            var comment = new CommentRow(true)
            {
                G_CommentVolume = volume.G_CommentVolume,
                G_Parent        = parentID.HasValue ? parentID.Value.G_Comment : (GDID?)null,
                G_AuthorNode    = authorNode.GDID,
                G_TargetNode    = targetNode.GDID,
                Create_Date     = creationTime ?? App.TimeSource.UTCNow,
                Dimension       = dimension,

                Message          = content,
                Data             = data,
                PublicationState = GSPublicationState.ToDomainString(publicationState),
                Rating           = (byte)value,

                Like           = 0,
                Dislike        = 0,
                ComplaintCount = 0,
                ResponseCount  = 0,

                IsRoot = !parentID.HasValue,
                In_Use = true
            };

            ForComment(volume.G_CommentVolume).Insert(comment);

            // Update ratings , if comment is root
            if (comment.IsRoot)
            {
                var nodeRating = getNodeRating(targetNode.GDID, dimension, ctxNode);
                nodeRating.UpdateCount(1);                           // Update count of commentaries (only root commentaries counts)
                nodeRating.UpdateRating(value, 1);                   //Update ratings
                nodeRating.Last_Change_Date = App.TimeSource.UTCNow; // update change time
                ctxNode.Update(nodeRating, filter: "Last_Change_Date,Cnt,Rating1,Rating2,Rating3,Rating4,Rating5".OnlyTheseFields());
            }
            // Update parent ResponseCount, if comment is not root
            else if (parentID.HasValue)
            {
                var ctxParent = ForComment(parentID.Value.G_Volume);
                var parent    = getCommentRow(parentID.Value, ctxParent);
                if (parent != null)
                {
                    parent.UpdateResponseCount(1);
                    ctxParent.Update(parent, filter: "ResponseCount".OnlyTheseFields());
                }
            }

            // Update count of commentaries in volume
            volume.Count++;
            ctxNode.Update(volume, filter: "Count".OnlyTheseFields());
            return(Comment.MakeNew(new CommentID(comment.G_CommentVolume, comment.GDID),
                                   parentID,
                                   authorNode,
                                   targetNode,
                                   comment.Create_Date,
                                   comment.Dimension,
                                   GSPublicationState.ToPublicationState(comment.PublicationState),
                                   (RatingValue)comment.Rating,
                                   comment.Message,
                                   comment.Data));
        }
예제 #21
0
 public void RateResource(StepResource stepResource, RatingValue ratingValue)
 {
     StudentResourceRatings.Add(new StudentResourceRating(this, stepResource, ratingValue));
 }
예제 #22
0
파일: GraphServers.cs 프로젝트: saleyn/agni
 public GraphChangeStatus Update(CommentID commentId, RatingValue value, string content, byte[] data)
 {
     return(Comments.Update(commentId, value, content, data));
 }
예제 #23
0
        public void RateExercise(RoadStep roadStep, int stepExerciseId, string comment, RatingValue ratingValue)
        {
            var studentExercise = GetStudentExercise(roadStep, stepExerciseId);

            studentExercise.FinishExerciseComment = comment;
            studentExercise.RatingValue           = ratingValue;
        }
예제 #24
0
 public abstract GraphChangeStatus Update(CommentID ratingId, RatingValue value, string content, byte[] data);
예제 #25
0
 public override Comment Create(GDID gAuthorNode, GDID gTargetNode, string dimension, string content, byte[] data,
                                PublicationState publicationState, RatingValue rating = RatingValue.Undefined, DateTime?epoch = null)
 {
     return(default(Comment));
 }
예제 #26
0
 public abstract Comment Create(GDID gAuthorNode, GDID gTargetNode, string dimension, string content, byte[] data,
                                PublicationState publicationState, RatingValue rating = RatingValue.Undefined, DateTime?epoch = null);
예제 #27
0
파일: GraphHost.cs 프로젝트: saleyn/agni
 protected abstract bool DoCanCreateComment(GraphNode authorNode,
                                            GraphNode targetNode,
                                            string dimension,
                                            DateTime commentDate,
                                            RatingValue rating);