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; } }
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; } }
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)); } }
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)); } }
public void AddObjective(ObjectiveDto objective) { try { _unitOfWork.ObjectiveRepository.Create(objective.ToDbEntity()); _unitOfWork.ObjectiveRepository.Save(); _unitOfWork.Commit(); } catch (Exception) { _unitOfWork.RollBack(); throw; } }
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; } }
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); } }
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); }