Пример #1
0
        public ActionResult EditQuest(ViewQuestModel quest)
        {
            ViewBag.User = userService.GetUserByEmail(User.Identity.Name);
            int flag = 0;

            foreach (var item in questService.GetAll())
            {
                if (item.Name.Equals(quest.Name))
                {
                    flag++;
                    break;
                }
            }
            if (flag > 0 && quest.Id == 0)
            {
                ModelState.AddModelError("", "Такой материал уже существует");
            }
            if (quest.Type.Equals("Тест"))
            {
                if (quest.Percent_Of_Exelent <= quest.Percent_Of_Good || quest.Percent_Of_Exelent <= quest.Percent_Of_Satisfactory || quest.Percent_Of_Good <= quest.Percent_Of_Satisfactory)
                {
                    ModelState.AddModelError("", "Ошибка в соотношении процентов");
                }
                else if (quest.Percent_Of_Exelent > 100 || quest.Percent_Of_Exelent < 30 ||
                         quest.Percent_Of_Good > 100 || quest.Percent_Of_Good < 30 || quest.Percent_Of_Satisfactory > 100 || quest.Percent_Of_Satisfactory < 30)
                {
                    ModelState.AddModelError("", "Процент должен быть в промежутке от 30 до 100");
                }
            }
            if (ModelState.IsValid)
            {
                if (quest.Id == 0)
                {
                    QuestDTO questDTO = Mapper.Map <ViewQuestModel, QuestDTO>(quest);
                    questService.Create(questDTO);
                    TempData["message"] = string.Format("Добавление задания выполнено успешно");
                }
                else
                {
                    QuestDTO newQuest = questService.GetById(quest.Id);
                    if (newQuest != null)
                    {
                        var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ViewQuestModel, QuestDTO>()).CreateMapper();
                        newQuest = mapper.Map <ViewQuestModel, QuestDTO>(quest);
                        questService.Update(newQuest);
                        TempData["message"] = string.Format("Добавление задания выполнено успешно");
                    }
                }
                if (userService.GetUserByEmail(User.Identity.Name).RoleId == 2)
                {
                    return(RedirectToAction("TeacherPanel", "Teacher", new { result = "quests" }));
                }
                return(RedirectToAction("AdminPanel", new { result = "quests" }));
            }
            ViewBag.Teachers = CreateSelectListOfTeachers();
            ViewBag.Groups   = CreateSelectListOfGroups(0);
            ViewBag.User     = userService.GetUserByEmail(User.Identity.Name);
            return(View());
        }
Пример #2
0
        public ActionResult EditQuest(int questId)
        {
            ViewBag.Teachers = CreateSelectListOfTeachers();
            ViewBag.Groups   = CreateSelectListOfGroups(0);
            ViewBag.User     = userService.GetUserByEmail(User.Identity.Name);
            QuestDTO question = questService.GetById(questId);

            foreach (var item in groupService.GetGroupsByQuestId(questId))
            {
                Debug.WriteLine(item.Name);
            }

            foreach (var item in ViewBag.Groups)
            {
                if (groupService.GetGroupsByQuestId(questId).Any(g => string.Equals(g.Name, item.Text)))
                {
                    item.Selected = true;
                }
            }
            ViewQuestModel viewQuestModel = Mapper.Map <QuestDTO, ViewQuestModel>(question);

            return(View(viewQuestModel));
        }