public ActionResult CreateTask(TemporaryExerciseModel tmpEx)
        {
            ICollection<Answer> answerList = new List<Answer>();
            answerList.Add(new Answer { Value = tmpEx.Answer });
            AppUser user = context.AppUserSet.Where(c => c.Email == User.Identity.Name).FirstOrDefault();
            Exercise ex = new Exercise
            {
                AppUserId = user.Id,
                Answer = answerList,
                Description = tmpEx.Text,
                Header = tmpEx.Header,
                Category = tmpEx.Category,
                Level = Helpers.getRank(tmpEx).ToString(),
                TimesSolved = 0,
                Rank = 0,
                Comment = new List<Comment>(),
                AddedDate = DateTime.Now,
                Attempted = "0",
                Tag = Helpers.ParseTags(tmpEx.Tags)
            };

            user.PublishedTasks += 1;
            context.TagSet.Concat(Helpers.ParseTags(tmpEx.Tags));
            context.ExerciseSet.Add(ex);
            context.SaveChanges();
            LuceneTagModel.AddUpdateLuceneIndex(Helpers.ParseTags(tmpEx.Tags));
            LuceneSearchModel.AddUpdateLuceneIndex(ex);
            return View(ex);
        }
Esempio n. 2
0
 public static int getRank(TemporaryExerciseModel ex)
 {
     string s = ex.Difficulty;
     if (s.Equals("Easy") || s.Equals("Легкое"))
         return 1;
     else if (s.Equals("Normal") || s.Equals("Нормальное"))
         return 2;
     else if (s.Equals("Medium") || s.Equals("Среднее"))
         return 3;
     else if (s.Equals("Hard") || s.Equals("Сложное"))
         return 4;
     else if (s.Equals("Very hard") || s.Equals("Очень сложное"))
         return 5;
     return 0;
 }