Beispiel #1
0
        /// <summary>
        /// Modifi the user if he succesfuly solve the task
        /// </summary>
        /// <param name="user">User who solve the task</param>
        /// <param name="task">Task which was solved</param>
        public void UserSolveTask(UserProfile user, Task task)
        {
            user.SolutionsCount++;
            user.Rating += 50;
            user.Tasks2.Add(task);
            db.Entry(user).State = EntityState.Modified;

            task.UserProfiles1.Add(user);
            task.SolutionsCount++;
            if (task.FirstSolve == null)
            {
                task.FirstSolve = DateTime.Now;
            }
            task.Attempts++;
            db.Entry(task).State = EntityState.Modified;

            db.SaveChanges();
        }
Beispiel #2
0
 private JsonResult CheckAnswerWithoutAuthor(UserProfile user, Task task, AnswerInfo answerInfo)
 {
     AnswerResult result = new AnswerResult();
     if (!user.Tasks2.Contains(task))
     {
         if (data.IsAnswerCorrect(answerInfo.TaskId, answerInfo.Answer))
         {
             data.UserSolveTask(user, task);
             result.Success = true;
             result.Message = Messages.UserSuccess;
         }
         else
         {
             data.UserFailToSolveTask(user, task);
             result.Success = false;
             result.Message = Messages.UserFail;
         }
         return Json(result);
     }
     result.Success = false;
     result.Message = Messages.UserAlreadySolve;
     return Json(result);
 }
Beispiel #3
0
 /// <summary>
 /// Modifi user who's attempt to solve was unsuccesfull
 /// </summary>
 /// <param name="user">User who get failed</param>
 /// <param name="task">Task which wasn't solved</param>
 public void UserFailToSolveTask(UserProfile user, Task task)
 {
     user.Rating -= 5;
     db.Entry(user).State = EntityState.Modified;
     task.Attempts++;
     db.Entry(task).State = EntityState.Modified;
     db.SaveChanges();
 }