public static void Create(QuestDTO questDTO) { Quest quest = MapperTransform <Quest, QuestDTO> .ToEntity(questDTO); Database.Quests.Create(quest); Database.Save(); }
public IEnumerable <string> GetTimeSections(QuestDTO quest, DateTime date) { List <string> list = new List <string>(); List <string> exTime = new List <string>(); int startTime = 8; int endTime = 20; for (int i = startTime; i < endTime; i += quest.Duration) { string time = DateTime.Parse(i + ":00").ToShortTimeString(); string newDateTimeSection = date.ToShortDateString() + " " + time; var find = Database.Reserves.Find(x => x.Quest.Id == quest.Id). Intersect(Database.Reserves.Find(x => x.DateTimeSection == newDateTimeSection)); if (find != null) { foreach (var el in find) { exTime.Add(el.DateTimeSection.Split(' ')[1]); } } list.Add(time); } return(list.Except(exTime)); }
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()); }
public QuestDTO GetQuestByName(string name) { Quest quest = Database.Quests.FindByName(name); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <Quest, QuestDTO>()).CreateMapper(); QuestDTO questDTO = mapper.Map <Quest, QuestDTO>(quest); return(questDTO); }
public QuestDTO GetById(int?id) { Quest quest = Database.Quests.GetById(id); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <Quest, QuestDTO>()).CreateMapper(); QuestDTO questDTO = mapper.Map <Quest, QuestDTO>(quest); return(questDTO); }
public ReservationWindow(IQuestService qs, IReservationService rs, QuestDTO quest) { this.qs = qs; this.rs = rs; this.quest = quest; InitializeComponent(); this.Text = $"Reservation for quest \"{quest.Name}\""; SetTimeSections(quest.Id, DateTime.Now); }
public static bool ToQuestDTO(Quest input, QuestDTO output) { if (input == null) { return(false); } output.QuestData = input.QuestData; output.QuestId = input.QuestId; output.NextQuestId = input.NextQuestId; return(true); }
public static bool ToQuest(QuestDTO input, Quest output) { if (input == null) { output = null; return(false); } output.QuestData = input.QuestData; output.QuestId = input.QuestId; return(true); }
public HttpResponseMessage NewQuest(QuestDTO quest) { try { QuestService.AddNewQuest(quest); return(Request.CreateResponse(HttpStatusCode.OK, true)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e)); } }
public QuestDTO LoadById(long id) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { QuestDTO dto = new QuestDTO(); if (Mapper.Mappers.QuestMapper.ToQuestDTO(context.Quest.Find(id), dto)) { return(dto); } return(null); } }
public QuestDTO LoadById(long id) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { QuestDTO dto = new QuestDTO(); if (Mapper.Mappers.QuestMapper.ToQuestDTO(context.Quest.AsNoTracking().FirstOrDefault(s => s.QuestId == id), dto)) { return(dto); } return(null); } }
public static void Update(QuestDTO questDTO) { Quest quest = Database.Quests.Get(questDTO.Id); quest.Name = questDTO.Name; quest.Description = questDTO.Description; quest.Creater = questDTO.Creater; quest.DateCreate = questDTO.DateCreate; quest.LimitOfPeople = questDTO.LimitOfPeople; quest.StartQuest = questDTO.StartQuest; quest.SRC = questDTO.SRC; Database.Quests.Update(quest); Database.Save(); }
public ActionResult Quest(string id) { ViewBag.Page = pageInfo.setView("Quest"); ViewBag.Message = TempData["Message"]; if (id != null) { int ID = Convert.ToInt32(id); QuestDTO questDTO = QuestServices.Get(ID); return(View(questDTO)); } return(View()); }
public IEnumerable <QuestDTO> LoadAll() { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <QuestDTO> result = new List <QuestDTO>(); foreach (Quest entity in context.Quest) { QuestDTO dto = new QuestDTO(); Mapper.Mappers.QuestMapper.ToQuestDTO(entity, dto); result.Add(dto); } return(result); } }
private static QuestDTO insert(QuestDTO quest, OpenNosContext context) { Quest entity = new Quest(); Mapper.Mappers.QuestMapper.ToQuest(quest, entity); context.Quest.Add(entity); context.SaveChanges(); if (Mapper.Mappers.QuestMapper.ToQuestDTO(entity, quest)) { return(quest); } return(null); }
private static QuestDTO update(Quest entity, QuestDTO quest, OpenNosContext context) { if (entity != null) { Mapper.Mappers.QuestMapper.ToQuest(quest, entity); context.SaveChanges(); } if (Mapper.Mappers.QuestMapper.ToQuestDTO(entity, quest)) { return(quest); } return(null); }
public QuestDTO generateDTO() { var item = new QuestDTO(); item.title = _data["title"]; item.description = _data["description"]; item.minAge = Int32.Parse(_data["minAge"]); item.valueId = Int32.Parse(_data["value_id"]); item.skillIds = new int[] { Int32.Parse(_data["skill1_id"]), Int32.Parse(_data["skill2_id"]) }; return(item); }
public ActionResult DeleteQuest(int questId) { QuestDTO deleteQuest = questService.GetById(questId); if (deleteQuest != null) { questService.Delete(questId); TempData["message"] = string.Format("Удаление \"{0}\" выполнено успешно", deleteQuest.Name); } if (userService.GetUserByEmail(User.Identity.Name).RoleId == 2) { return(RedirectToAction("TeacherPanel", "Teacher", new { result = "quests" })); } return(RedirectToAction("AdminPanel", new { result = "quests" })); }
public ActionResult Result(int module) { ViewBag.Page = page.setView("Result").setTitle("Result - Quest / NEW WORLD"); ViewBag.Method = HttpContext.Request.HttpMethod; QuestDTO questDTO = QuestServices.Get(module); if (questDTO == null) { return(HttpNotFound()); } List <PrizeDTO> prizeDTO = PrizeServices.GetAll().Where(x => x.QuestId == module).ToList(); ViewBag.prizeDTO = prizeDTO; return(View(questDTO)); }
public ActionResult ActivateQuest(int questId) { QuestDTO quest = questService.GetById(questId); if (quest.Active) { quest.Active = false; } else { quest.Active = true; } questService.Update(quest); ViewBag.Quest = quest; ViewBag.User = userService.GetUserByEmail(User.Identity.Name); return(View()); }
public Quest(QuestDTO input) { QuestId = input.QuestId; QuestType = input.QuestType; LevelMin = input.LevelMin; LevelMax = input.LevelMax; StartDialogId = input.StartDialogId; EndDialogId = input.EndDialogId; DialogNpcVNum = input.DialogNpcVNum; DialogNpcId = input.DialogNpcId; TargetMap = input.TargetMap; TargetX = input.TargetX; TargetY = input.TargetY; InfoId = input.InfoId; NextQuestId = input.NextQuestId; IsDaily = input.IsDaily; LoadSqstPosition(); }
public JsonResult OnZonesLoadOneQuest(int module) { QuestDTO quest = QuestServices.Get(module); ZonesLoad zonesLoad = new ZonesLoad(); double argLat = 0, ardLong = 0; double Radius = 0; foreach (PointDTO point in quest.pointDTO) { argLat += point.Latitude; ardLong += point.Longitude; } argLat = (quest.pointDTO.Count == 0) ? 0 : argLat / quest.pointDTO.Count; ardLong = (quest.pointDTO.Count == 0) ? 0 : ardLong / quest.pointDTO.Count; foreach (PointDTO point in quest.pointDTO) { double TRadius = Math.Sqrt(Math.Pow(argLat - point.Latitude, 2) + Math.Pow(ardLong - point.Longitude, 2)); Radius = Radius > TRadius ? Radius : TRadius; } Radius += 0.002; zonesLoad.Bounds = new double[2][] { new double[2] { argLat + Radius, ardLong - Radius }, new double[2] { argLat - Radius, ardLong + Radius } }; zonesLoad.ArgLatitude = argLat; zonesLoad.ArgLongtude = ardLong; zonesLoad.Name = quest.Name; quest.pointDTO.ForEach(x => zonesLoad.coordinates.Add(new double[2] { x.Latitude, x.Longitude })); Random randonGen = new Random(); Color randomColor = Color.FromArgb(70, randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); zonesLoad.fillColor = "#" + randomColor.R.ToString("X2") + randomColor.G.ToString("X2") + randomColor.B.ToString("X2") + randomColor.A.ToString("X2"); return(Json(zonesLoad)); }
public QuestDTO InsertOrUpdate(QuestDTO quest) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { Quest entity = context.Quest.Find(quest.QuestId); if (entity == null) { return(insert(quest, context)); } return(update(entity, quest, context)); } } catch (Exception e) { Logger.Error(string.Format(Language.Instance.GetMessageFromKey("INSERT_ERROR"), quest, e.Message), e); return(quest); } }
public ActionResult Game(int module) { if (Identity.isAuthentication) { ViewBag.Page = page.setView("Game").setTitle("Game - Quest / NEW WORLD"); ViewBag.Method = HttpContext.Request.HttpMethod; QuestDTO questDTO = QuestServices.Get(module); if (questDTO == null) { return(HttpNotFound()); } List <PointDTO> pointDTO = PointServices.GetAll().Where(x => x.QuestId == module).ToList(); ViewBag.Point = pointDTO; return(View(questDTO)); } else { return(Redirect("Error")); } }
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)); }
public ActionResult InformQuest(int module) { ViewBag.Page = page.setView("InformQuest").setTitle("Information - Quest / NEW WORLD"); ViewBag.Method = HttpContext.Request.HttpMethod; QuestDTO questDTO = QuestServices.Get(module); if (questDTO == null) { return(HttpNotFound()); } bool userStart = false; bool can = false; List <PrizeDTO> prize = PrizeServices.GetAll().Where(x => x.QuestId == questDTO.Id).ToList(); if (Identity.isAuthentication) { userStart = !UserInQuestServices.GetAll().Any(x => x.UserId == Identity.user.Id && x.StatusId == 1 && questDTO.Id == x.QuestId); //если false то не может участвовать List <UserInQuestDTO> userInQuest = UserInQuestServices.GetAll().Where(x => x.UserId == Identity.user.Id && x.StatusId == 1).ToList(); can = QuestServices.GetAll() .Any(x => userInQuest.Any(s => x.Id == s.QuestId) && Math.Abs(questDTO.StartQuest.Subtract(x.StartQuest).TotalHours) < 5); //если true то не может участвовать } ViewBag.userStart = userStart; ViewBag.can = can; ViewBag.prize = prize; ViewBag.countPeople = questDTO.countPeople; return(View(questDTO)); }
public static bool ToQuest(QuestDTO input, Quest output) { if (input == null) { return(false); } output.QuestId = input.QuestId; output.QuestType = input.QuestType; output.LevelMin = input.LevelMin; output.LevelMax = input.LevelMax; output.StartDialogId = input.StartDialogId; output.EndDialogId = input.EndDialogId; output.DialogNpcVNum = input.DialogNpcVNum; output.DialogNpcId = input.DialogNpcId; output.TargetMap = input.TargetMap; output.TargetX = input.TargetX; output.TargetY = input.TargetY; output.InfoId = input.InfoId; output.NextQuestId = input.NextQuestId; output.IsDaily = input.IsDaily; return(true); }
private ResultDTO CreateResult(AnswerModel answerModel) { ResultDTO result = new ResultDTO(); result.Answers = new List <AnswerInfo>(); result.Date = System.DateTime.Now.ToString(); foreach (var item in answerModel.results) { AnswerInfo answerInfo = new AnswerInfo(); answerInfo.Text_of_answer = item.Text_of_answer; answerInfo.isTrue = item.isTrue; answerInfo.QuestionId = item.QuestionId; answerInfo.ResultId = result.Id; result.Answers.Add(answerInfo); } double countTrusAnswers = 0; QuestDTO quest = questService.GetById(answerModel.idQuest); result.QuestId = answerModel.idQuest; result.UserId = userService.GetUserByEmail(User.Identity.Name).Id; if (answerModel.Type.Equals("Тест")) { foreach (var item in answerModel.results) { if (item.isTrue) { countTrusAnswers++; } } double value = (countTrusAnswers / answerModel.results.Count) * 100; result.Percente = Math.Round(value, 2); if (result.Percente >= quest.Percent_Of_Exelent) { result.Mark = 5; } else { if (result.Percente >= quest.Percent_Of_Good) { result.Mark = 4; } else { if (result.Percente >= quest.Percent_Of_Satisfactory) { result.Mark = 3; } else { result.Mark = 2; } } } } return(result); }
public QuestDTO InsertOrUpdate(QuestDTO quest) => throw new NotImplementedException();
// POST api/Quest public IHttpActionResult Post(QuestDTO quest) { var model = mapper.Map<QuestDTO, Quest>(quest); var owner = dataManager.Users.FirstOrDefault(u => u.UserName == quest.Owner); if (owner == null) throw new HttpResponseException(HttpStatusCode.BadRequest); model.Author = owner; model.Date = DateTime.Now; try { dataManager.Quests.Add(model); dataManager.Save(); return Ok(); } catch { throw new HttpResponseException(HttpStatusCode.BadRequest); } }
// PUT api/Quest public void Put(QuestDTO quest) { }
public void Update(QuestDTO item) { Database.Quests.Update(Mapper.Map <QuestDTO, Quest>(item)); Database.Save(); Database.Dispose(); }