예제 #1
0
        private void SetUpObjective(Objective dbObjective, ObjectiveDto objective)
        {
            var challenger   = _unitOfWork.ChallengeRepository.All().Where(c => c.Challenge_ID == objective.ChallengeId).FirstOrDefault();
            var challengerId = challenger == null ? null : challenger.User_ID;

            dbObjective.Challenge_ID     = objective.ChallengeId;
            dbObjective.Deadline         = objective.Deadline;
            dbObjective.Description      = objective.Description;
            dbObjective.Expected_Outcome = objective.ExpectedOutcome;
            dbObjective.Name             = objective.Name;
            dbObjective.Progress         = objective.Progress;
            dbObjective.Start_Date       = objective.StartDate;
            dbObjective.End_Date         = objective.EndDate;
            if (objective.Status != 0)
            {
                dbObjective.Status_ID = objective.Status;
            }
            if (objective.Progress == 10 && (!objective.ChallengeId.HasValue || objective.UserId == challengerId))
            {
                dbObjective.Status_ID = (int)Common.Enums.ObjectiveStatus.Completed;
            }
            else if ((objective.Progress == 10 || objective.Status == (int)Common.Enums.ObjectiveStatus.Completed) && (objective.UserId != challengerId))
            {
                dbObjective.Status_ID = (int)Common.Enums.ObjectiveStatus.ForReview;
            }
            else if (objective.Progress > 0 && objective.Progress < 10 && objective.Status == (int)Common.Enums.ObjectiveStatus.NotActive)
            {
                dbObjective.Status_ID = (int)Common.Enums.ObjectiveStatus.Ongoing;
            }
        }
예제 #2
0
        public void UpdateChallengeBasedGrade(ObjectiveDto objective)
        {
            try
            {
                var dbObjective = _unitOfWork.ObjectiveRepository.GetById(objective.Id);
                SetUpObjective(dbObjective, objective);

                var systemGrade = _userRankComponent.PersistSystemGradeForObjective(objective.Id);
                var userGrade   = _unitOfWork.UserRatingRepository.All().Where(r => r.Objective_ID == objective.Id).FirstOrDefault().Grade;
                int grade       = Convert.ToInt32(0.6 * userGrade + 0.4 * systemGrade);

                dbObjective.Rating += grade;

                _unitOfWork.UserRepository.All().Where(u => u.Id == objective.UserId)
                .FirstOrDefault().Points += Convert.ToInt32(dbObjective.Rating);
                _unitOfWork.UserRankRepository.Save();
                _unitOfWork.ObjectiveRepository.Save();
                _unitOfWork.Commit();
            }
            catch (Exception)
            {
                _unitOfWork.RollBack();
                throw;
            }
        }
예제 #3
0
 public HttpResponseMessage AddObjective([FromBody] ObjectiveDto objective)
 {
     try
     {
         _objectiveService.AddObjective(objective);
         return(Request.CreateResponse(HttpStatusCode.Created, "Successfully added an objective!"));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
예제 #4
0
 public HttpResponseMessage UpdateObjective([FromBody] ObjectiveDto objective)
 {
     try
     {
         _objectiveService.UpdateObjective(objective);
         var userInfo = _userService.GetUserById(objective.UserId);
         return(Request.CreateResponse(HttpStatusCode.OK, userInfo));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
예제 #5
0
 public void AddObjective(ObjectiveDto objective)
 {
     try
     {
         _unitOfWork.ObjectiveRepository.Create(objective.ToDbEntity());
         _unitOfWork.ObjectiveRepository.Save();
         _unitOfWork.Commit();
     }
     catch (Exception)
     {
         _unitOfWork.RollBack();
         throw;
     }
 }
예제 #6
0
 private void UpdateObjectiveNotComplete(ObjectiveDto objective)
 {
     try
     {
         var dbObjective = _unitOfWork.ObjectiveRepository.GetById(objective.Id);
         SetUpObjective(dbObjective, objective);
         _unitOfWork.ObjectiveRepository.Save();
         _unitOfWork.Commit();
     }
     catch (Exception)
     {
         _unitOfWork.RollBack();
         throw;
     }
 }
예제 #7
0
 public void UpdateObjective(ObjectiveDto objective)
 {
     if ((objective.ChallengeId != null && objective.Status == (int)Common.Enums.ObjectiveStatus.Reviewed))
     {
         UpdateChallengeBasedGrade(objective);
     }
     else if (objective.ChallengeId == null && objective.Status == (int)Common.Enums.ObjectiveStatus.Completed)
     {
         UpdateGrade(objective);
     }
     else
     {
         UpdateObjectiveNotComplete(objective);
     }
 }
예제 #8
0
        public static Objective ToDbEntity(this ObjectiveDto objective)
        {
            var obj = new Objective()
            {
                Objective_ID     = objective.Id,
                Challenge_ID     = objective.ChallengeId,
                Deadline         = objective.Deadline,
                Description      = objective.Description,
                Expected_Outcome = objective.ExpectedOutcome,
                Name             = objective.Name,
                End_Date         = objective.EndDate,
                Status_ID        = (int)objective.Status,
                Start_Date       = objective.StartDate,
                User_ID          = objective.UserId,
                Progress         = objective.Progress
            };

            return(obj);
        }