Exemplo n.º 1
0
        public UserEstimate RecordUserEstimate(UserEstimate newUserEstimate)
        {
            var entities = new Entities();
            var result   = entities.UserEstimates.Add(newUserEstimate);

            entities.SaveChanges();

            return(result);
        }
Exemplo n.º 2
0
        public ActionResult AssessArticle(EstimateUpdate model)
        {
            var articleId = model.ArticleId;
            var estimate  = model.Estimate;

            var article = dbContext.Article.FirstOrDefault(a => a.Id == articleId);

            if (article == null)
            {
                return(BadRequest("The requested article does not exist in the data base"));
            }

            // If a user can create a comment according to a current status of an article
            if (article.Status != ArticleStatus.APPROVED)
            {
                return(BadRequest("The article ought to be approved to have comments"));
            }

            var curUser   = GetUserInfo();
            var curUserId = curUser.id;

            if (article.AuthorId == curUserId)
            {
                return(BadRequest("Authors cannot assess their own articles"));
            }

            var entity = dbContext.UserEstimate.FirstOrDefault(
                e => e.ArticleId == articleId && e.AuthorId == curUserId);
            DateTime now = DateTime.Now;

            if (entity == null)
            {
                entity           = new UserEstimate();
                entity.ArticleId = article.Id;
                entity.AuthorId  = curUserId;

                dbContext.UserEstimate.Add(entity);
            }

            var history = AddHistory(articleId, curUserId, "Estimate.Estimate",
                                     estimate.ToString(), entity.Estimate.ToString(), now, entity.Id);

            entity.Estimate   = estimate;
            entity.InsertDate = DateTime.Now;

            AddNotification($"A user {curUser.name} has assessed an article '{article.Name}'", history, article.AuthorId);

            dbContext.SaveChanges();

            return(Ok(new { finalEstimate = article.GetFinalEstimate() }));
        }
Exemplo n.º 3
0
        public IHttpActionResult Post([FromBody] UserEstimate newUserEstimate)
        {
            UserEstimate estimate = _dbApiRepository.RecordUserEstimate(newUserEstimate);

            return(Ok(estimate));
        }
Exemplo n.º 4
0
        public IHttpActionResult GetEstimateDataById(int id)
        {
            UserEstimate est = _dbApiRepository.GetUserEstimate(id);

            return(Ok(est));
        }