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 AddQuest(UpdateQuest quest) { DateTime DateCreate = DateTime.Now; if (quest.Points.Count > 2 && quest.Name != null && quest.Prizes.Count > 0 && Identity.isAuthentication || true) { if (quest.Id != null) { int ID = quest.Id.Value; QuestDTO questDTO = QuestServices.Get(ID); questDTO.StartQuest = quest.DateTime; questDTO.Description = quest.Description; questDTO.LimitOfPeople = Convert.ToInt32(quest.MaxPeople); questDTO.Name = quest.Name; QuestServices.Update(questDTO); if (quest.Photo != null) { string dir = Server.MapPath("~/Resources/Images/Quest"); string type = quest.Photo.FileName.Split('.').Last(); string src = "/Resources/Images/Quest/" + cryptMD5.GetHash(Convert.ToString(questDTO.Id)) + "." + type; string path = Server.MapPath("~" + src); quest.Photo.SaveAs(path); questDTO.SRC = src; QuestServices.Update(questDTO); } List <PrizeDTO> prizeDTO = PrizeServices.GetAll().Where(x => x.QuestId == ID).ToList(); List <PointDTO> pointDTO = PointServices.GetAll().Where(x => x.QuestId == ID).ToList(); foreach (PrizeDTO prz in prizeDTO) { PrizeServices.Delete(prz.Id); } foreach (PointDTO pnt in pointDTO) { PointServices.Delete(pnt.Id); } PrizeDTO prizeDTOnew; PointDTO pointDTOnew; foreach (UpdateQuest.Prize prize in quest.Prizes) { prizeDTOnew = new PrizeDTO(); prizeDTOnew.MaxPlace = prize.Max; prizeDTOnew.MinPlace = prize.Min; prizeDTOnew.Name = prize.Title; prizeDTOnew.QuestId = ID; PrizeServices.Create(prizeDTOnew); } foreach (UpdateQuest.Point point in quest.Points) { pointDTOnew = new PointDTO(); pointDTOnew.Latitude = point.getLatitude(); pointDTOnew.Longitude = point.getLongitude(); pointDTOnew.Task = point.Task; pointDTOnew.QuestId = ID; pointDTOnew.Address = point.Address; PointServices.Create(pointDTOnew); } TempData["Message"] = "Успешно отредактировано"; return(Redirect("/Home/Home")); } else { QuestDTO questDTO = new QuestDTO(); questDTO.StartQuest = quest.DateTime; questDTO.DateCreate = DateCreate; questDTO.Description = quest.Description; questDTO.LimitOfPeople = Convert.ToInt32(quest.MaxPeople); questDTO.Name = quest.Name; questDTO.Creater = Identity.user.Id; QuestServices.Create(questDTO); QuestDTO newQuestDTO = QuestServices.GetAll().FirstOrDefault(x => x.Name == quest.Name && x.Creater == Identity.user.Id && x.DateCreate == DateCreate); if (quest.Photo != null) { string dir = Server.MapPath("~/Resources/Images/Quest"); string type = quest.Photo.FileName.Split('.').Last(); string src = "/Resources/Images/Quest/" + cryptMD5.GetHash(Convert.ToString(newQuestDTO.Id)) + "." + type; string path = Server.MapPath("~" + src); quest.Photo.SaveAs(path); newQuestDTO.SRC = src; QuestServices.Update(newQuestDTO); } PrizeDTO prizeDTO; PointDTO pointDTO; foreach (UpdateQuest.Prize prize in quest.Prizes) { prizeDTO = new PrizeDTO(); prizeDTO.MaxPlace = prize.Max; prizeDTO.MinPlace = prize.Min; prizeDTO.Name = prize.Title; prizeDTO.QuestId = newQuestDTO.Id; PrizeServices.Create(prizeDTO); } foreach (UpdateQuest.Point point in quest.Points) { pointDTO = new PointDTO(); pointDTO.Latitude = point.getLatitude(); pointDTO.Longitude = point.getLongitude(); pointDTO.Task = point.Task; pointDTO.QuestId = newQuestDTO.Id; pointDTO.Address = point.Address; PointServices.Create(pointDTO); } TempData["Message"] = "Успешно добавлено"; return(Redirect("/Home/Home")); } } TempData["Message"] = "Квест не добавлен"; return(RedirectToAction("Quest")); }