public async Task <ActionResult> EditAsync(FaqItemViewModel viewModel) { var item = await _FaqRepository.GetAsync(viewModel.Id); if (item == null) { return(HttpNotFound()); } if (viewModel.IsDeleting) { await _FaqRepository.DeleteAsync(viewModel.Id); return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { item.Title = viewModel.Title; item.Content = viewModel.Content; item.DisplayOrder = viewModel.DisplayOrder; item.TitleFontSize = viewModel.TitleFontSize; await _FaqRepository.UpdateAsync(item); return(RedirectToAction(nameof(Index))); } else { return(View("CreateEdit", viewModel)); } }
public async Task <FaqItemViewModel> GetFaqItem(int faqId) { _sharedService.WriteLogs("GetFaqItem started by:" + _userSettings.UserName, true); try { var faq = await _faqRepository.GetByIdAsync(faqId); Guard.Against.NullFaq(faqId, faq); var vm = new FaqItemViewModel() { Id = faq.Id, Question = faq.Question, Answer = faq.Answer, IsAdministratorFaq = faq.IsAdministratorFaq, IsCoordinatorFaq = faq.IsCoordinatorFaq, IsTeacherFaq = faq.IsTeacherFaq, Sequence = faq.Sequence, YearId = faq.YearId, Alberta = faq.Alberta.HasValue ? faq.Alberta.Value : false, BritishColumbia = faq.BritishColumbia.HasValue ? faq.BritishColumbia.Value : false, Manitoba = faq.Manitoba.HasValue ? faq.Manitoba.Value : false, NewBrunswick = faq.NewBrunswick.HasValue ? faq.NewBrunswick.Value : false, NewfoundlandandLabrador = faq.NewfoundlandandLabrador.HasValue ? faq.NewfoundlandandLabrador.Value : false, NovaScotia = faq.NovaScotia.HasValue ? faq.NovaScotia.Value : false, Nunavut = faq.Nunavut.HasValue ? faq.Nunavut.Value : false, Ontario = faq.Ontario.HasValue ? faq.Ontario.Value : false, PrinceEdwardIsland = faq.PrinceEdwardIsland.HasValue ? faq.PrinceEdwardIsland.Value : false, Quebec = faq.Quebec.HasValue ? faq.Quebec.Value : false, Saskatchewan = faq.Saskatchewan.HasValue ? faq.Saskatchewan.Value : false, YukonTerritory = faq.YukonTerritory.HasValue ? faq.YukonTerritory.Value : false, NorthwestTerritories = faq.NorthwestTerritories.HasValue ? faq.NorthwestTerritories.Value : false, CreatedDate = faq.CreatedDate, CreatedBy = faq.CreatedBy, ModifiedDate = faq.ModifiedDate, ModifiedBy = faq.ModifiedBy }; return(vm); } catch (Exception ex) { _sharedService.WriteLogs("GetFaqItem failed:" + ex.Message, false); var vm = new FaqItemViewModel(); return(vm); } }
public async Task <int> CreateFaqAsync(FaqItemViewModel faq) { _sharedService.WriteLogs("CreateFaqAsync started by:" + _userSettings.UserName, true); try { var _faq = new Faq(); _faq.Question = string.IsNullOrEmpty(faq.Question) ? null : faq.Question.Trim(); _faq.Answer = string.IsNullOrEmpty(faq.Answer) ? null : faq.Answer.Trim(); _faq.IsAdministratorFaq = faq.IsAdministratorFaq; _faq.IsCoordinatorFaq = faq.IsCoordinatorFaq; _faq.IsTeacherFaq = faq.IsTeacherFaq; _faq.Sequence = faq.Sequence; _faq.YearId = faq.YearId; _faq.Alberta = faq.Alberta; _faq.BritishColumbia = faq.BritishColumbia; _faq.Manitoba = faq.Manitoba; _faq.NewBrunswick = faq.NewBrunswick; _faq.NewfoundlandandLabrador = faq.NewfoundlandandLabrador; _faq.NovaScotia = faq.NovaScotia; _faq.Nunavut = faq.Nunavut; _faq.Ontario = faq.Ontario; _faq.PrinceEdwardIsland = faq.PrinceEdwardIsland; _faq.Quebec = faq.Quebec; _faq.Saskatchewan = faq.Saskatchewan; _faq.YukonTerritory = faq.YukonTerritory; _faq.NorthwestTerritories = faq.NorthwestTerritories; _faq.CreatedDate = DateTime.Now; _faq.CreatedBy = _userSettings.UserName; _faq.ModifiedDate = DateTime.Now; _faq.ModifiedBy = _userSettings.UserName; await _faqRepository.AddAsync(_faq); return(_faq.Id); } catch (Exception ex) { _sharedService.WriteLogs("CreateFaqAsync failed:" + ex.Message, false); return(0); } }
public async Task <ActionResult> CreateAsync(FaqItemViewModel viewModel) { if (ModelState.IsValid) { var item = new FaqItem { Title = viewModel.Title, Content = viewModel.Content, DisplayOrder = viewModel.DisplayOrder, TitleFontSize = viewModel.TitleFontSize }; await _FaqRepository.CreateAsync(item); return(RedirectToAction(nameof(Index))); } else { return(View("CreateEdit", viewModel)); } }
protected FaqItemViewModel ToViewModel(FaqItem item) { FaqItemViewModel vm = Mapper.Map <FaqItemViewModel>(item); return(vm); }