public ActionResult Edit(int id, QuestionEdit model) { _context = new ApplicationDbContext(); ViewBag.CategoryName = new SelectList(_context.Categories.ToList(), "Name", "Name"); ViewBag.VersionName = new SelectList(_context.Versions.ToList(), "Name", "Name"); if (!ModelState.IsValid) { return(View(model)); } if (model.Id != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateQuestionService(); if (service.UpdateQuestion(model)) { TempData["SaveResult"] = "Your question was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your question could not be updated."); return(View(model)); }
public void EditQuestion(int questionId, QuestionEdit model) { Question question = _repo.GetById(questionId); question = model.UpdateQuestion(question, model); _repo.Update(question); }
public bool UpdateQuestion(QuestionEdit model) { using (var ctx = new ApplicationDbContext()) { var vsvc = GetVersionService(); var csvc = GetCategoryService(); if (!_userService.ConfirmUserIsAdmin(_userId.ToString())) { var playerEntity = ctx .Questions .Single(e => e.Id == model.Id && e.AuthorId == _userId.ToString()); playerEntity.Text = model.Text; playerEntity.CategoryId = csvc.GetCategoryIdByName(model.Category); playerEntity.VersionId = vsvc.GetVersionIdByName(model.Version); return(ctx.SaveChanges() == 1); } var adminEntity = ctx .Questions .Single(e => e.Id == model.Id); adminEntity.Text = model.Text; adminEntity.CategoryId = csvc.GetCategoryIdByName(model.Category); adminEntity.VersionId = vsvc.GetVersionIdByName(model.Version); return(ctx.SaveChanges() == 1); } }
public QuestionIndexWithScope EditGlobal(QuestionEdit data) { var question = this.context.GlobalQuestionPackages .SingleOrDefault(x => x.Id == data.Id); if (question == null) { throw new ServiceException("Question Not Found!"); } question.Name = data.Name; question.Question = data.Question; question.Comment = data.Comment; question.Answer = data.Answer; question.Difficulty = data.Difficulty.Value; context.SaveChanges(); var outData = Mapper.Map <QuestionGlobalIndex>(question); return(new QuestionIndexWithScope() { isGlobal = true, data = outData, }); }
// GET: Test public string Index() { var abc = QuestionEdit.New(); WriteLine(abc.Title); //var uow = UnitOfWorkFactory.Get(); //var uow2 = UnitOfWorkFactory.Get(); //WriteLine(uow); //WriteLine(uow2); //var repo = new QuestionRepository(uow); //var question = QuestionEditModel.Get(1); //Print(question); //question.Title = DateTime.Now.ToString(CultureInfo.InvariantCulture); //question.Answers[0].Description = "aabb" + DateTime.Now.Millisecond; //question.Answers[1].Description = "aabb" + DateTime.Now.Millisecond; ////question.Answers[2].IsDelete = true; //question.Upsert(true); //question = QuestionEditModel.Get(1); //Print(question); //return uow.Equals(uow2) ? bool.TrueString : bool.FalseString; return(""); }
public ActionResult Edit(int id, QuestionEdit model) { if (ModelState.IsValid) { _uow.GetRepository <IQuestionRepository>().UpdateQuestion(id, model); return(RedirectToAction("Index")); } return(View(model)); }
public QuestionEdit CreateQuestion(QuestionEdit model) { var response = HttpClient.PostAsJsonAsync(EndPoint, model).Result; if (!response.IsSuccessStatusCode) { throw new Exception(response.RequestMessage.RequestUri + " - " + response.StatusCode + " - " + response.ReasonPhrase); } return(response.Content.ReadAsAsync <QuestionEdit>().Result); }
public ActionResult Create(QuestionEdit editModel) { if (ModelState.IsValid) { _uow.GetRepository <IQuestionRepository>().CreateQuestion(editModel); return(RedirectToAction("Index")); } return(View(editModel)); }
private void Print(QuestionEdit questionEdit) { WriteLine(questionEdit.Id); WriteLine(questionEdit.Title); WriteLine("Children: " + questionEdit.Answers.Count); foreach (var item in questionEdit.Answers) { WriteLine(item.Id + " " + item.Description); } }
public IActionResult EditGlobal([FromBody] QuestionEdit data) { try { QuestionIndexWithScope result = questionService.EditGlobal(data); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult Edit(int id) { var svc = new QuestionService(); var detail = svc.GetQuestionById(id); var model = new QuestionEdit { IsActive = detail.IsActive }; return(View(model)); }
public IHttpActionResult Create(QuestionEdit model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } (new QuestionService(_uow.GetRepository <IQuestionRepository>())).CreateQuestion(model); _uow.Commit(); return(Ok(model)); }
public IActionResult EditPersonal([FromBody] QuestionEdit data) { try { var userData = jwtService.ParseData(this.User); QuestionIndexWithScope result = questionService.EditPersonal(data, userData.UserId); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void EditGlobal(QuestionEdit data) { var question = this.context.GlobalQuestionPackages .SingleOrDefault(x => x.Id == data.Id); if (question == null) { throw new ServiceException("Question Not Found!"); } question.Name = data.Name; question.Question = data.Question; question.Comment = data.Comment; question.Answer = data.Answer; question.Difficulty = data.Difficulty.Value; context.SaveChanges(); }
public QuestionIndexWithScope EditPersonal(QuestionEdit data, int userId) { var user = this.context.Users.SingleOrDefault(x => x.Id == userId); if (user == null) { throw new ServiceException(Constants.UserNotFoundMessage); } var question = this.context.PersonalQuestionPackages .SingleOrDefault(x => x.Id == data.Id); if (question == null) { throw new ServiceException("Question Not Found!"); } var questionSheetUserId = this.context.QuestionSheets .SingleOrDefault(x => x.Id == question.QuestionSheetId)?.UserId; if (questionSheetUserId == null) { throw new ServiceException("Invalid Parent Question Sheet!"); } if (questionSheetUserId != user.Id) { throw new ServiceException("Question Dos Not Belong To You!"); } question.Name = data.Name; question.Question = data.Question; question.Comment = data.Comment; question.Answer = data.Answer; question.Difficulty = data.Difficulty.Value; context.SaveChanges(); var outData = Mapper.Map <QuestionGlobalIndex>(question); return(new QuestionIndexWithScope() { isGlobal = false, data = outData, }); }
public ActionResult Edit(int id) { _context = new ApplicationDbContext(); ViewBag.CategoryName = new SelectList(_context.Categories.ToList(), "Name", "Name"); ViewBag.VersionName = new SelectList(_context.Versions.ToList(), "Name", "Name"); var service = CreateQuestionService(); var detail = service.GetQuestionById(id); var model = new QuestionEdit { Id = detail.Id, Text = detail.Text, Category = detail.Category.Name, Version = detail.GameVersion.Name, }; return(View(model)); }
public IHttpActionResult Edit(int id, QuestionEdit model) { QuestionService service = new QuestionService(_uow.GetRepository <IQuestionRepository>()); if (service.CanEdit(id)) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } service.EditQuestion(id, model); _uow.Commit(); return(Ok(model)); } ModelState.AddModelError("IsActive", "Question must be inactive to edit"); return(BadRequest(ModelState)); }
public void EditPersonal(QuestionEdit data, int userId) { var user = this.context.Users.SingleOrDefault(x => x.Id == userId); if (user == null) { throw new ServiceException(Constants.UserNotFoundMessage); } var question = this.context.PersonalQuestionPackages .SingleOrDefault(x => x.Id == data.Id); if (question == null) { throw new ServiceException("Question Not Found!"); } var questionSheetUserId = this.context.QuestionSheets .SingleOrDefault(x => x.Id == question.QuestionSheetId)?.UserId; if (questionSheetUserId == null) { throw new ServiceException("Invalid Parent Question Sheet!"); } if (questionSheetUserId != user.Id) { throw new ServiceException("Question Dos Not Belong To You!"); } question.Name = data.Name; question.Question = data.Question; question.Comment = data.Comment; question.Answer = data.Answer; question.Difficulty = data.Difficulty.Value; context.SaveChanges(); }
// GET: Questions/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } QuestionView question = _uow.GetRepository <IQuestionRepository>().GetOne(id.Value); if (question == null) { return(HttpNotFound()); } QuestionEdit editModel = new QuestionEdit() { Date = question.QuestionDate, Description = question.Description, Id = question.Id, IsActive = question.IsActive, Question = question.Question }; return(View(editModel)); }
public void CreateQuestion(QuestionEdit model) { _repo.Add(QuestionFactroy.CreateFromQuestionCreate(model)); }
// GET: Questions/Create public ActionResult Create() { QuestionEdit questionEdit = new QuestionEdit(); return(View(questionEdit)); }