public ActionResult Upsert(FaqUpsertViewModel model) { if (ModelState.IsValid) { try { var dbModel = Mapper.Map <Faq>(model); using (var transaction = ContextManager.NewTransaction()) { faqService.Upsert(dbModel); transaction.Commit(); } this.ShowMessage(MessageType.Success, Resource.ChangesSuccessfullySaved); return(RedirectToAction("Index", new FaqQueryViewModel { Id = model.Id })); } catch (UserDbException e) { Logger.Error(e); ModelState.AddModelError(string.Empty, Resource.DbErrorMessage); } catch (UserException e) { ModelState.AddModelError(string.Empty, e.Message); } } InitUpsertBreadcrumb(model); return(View(model)); }
private void InitUpsertBreadcrumb(FaqUpsertViewModel model) { this.InitAdminBreadcrumb( Title, model.Id.HasValue ? string.Format(Resource.Editing, model.Question) : Resource.CreateFaq, true); }
public void UpsertInvalidModel() { ////Arrange var model = new FaqUpsertViewModel(); ////Act SimulateValidation(model, faqController); var result = faqController.Upsert(model); ////Assert faqController.ModelState.IsValid.Should().Be(false); }
public void UpsertInvalidModelRedirectToUpsert() { ////Arrange var model = new FaqUpsertViewModel(); ////Act SimulateValidation(model, faqController); var result = faqController.Upsert(model); ////Assert result.Should().BeOfType(typeof(ViewResult)); }
public ActionResult Upsert(Guid?id = null) { var model = new FaqUpsertViewModel(); if (id.HasValue) { using (ContextManager.NewConnection()) { model = Mapper.Map <FaqUpsertViewModel>(faqService.GetFaq(id.Value, true)); } } InitUpsertBreadcrumb(model); return(View(model)); }
public void UpsertInvalidModelReturnSameModel() { ////Arrange var model = new FaqUpsertViewModel(); var question = new SortedDictionary <string, string> { { EnumHelper.GetLanguageId(Language.BG).ToString(), "Въпрос тест" }, { EnumHelper.GetLanguageId(Language.EN).ToString(), "Question Test" } }; model.Questions = question; ////Act SimulateValidation(model, faqController); var result = faqController.Upsert(model) as ViewResult; ////Assert var resultModel = result.Model as FaqUpsertViewModel; resultModel.Questions.Should().BeEquivalentTo(question); }