public async Task <IActionResult> Edit(ContentNewsModel faqModel) { if (ModelState.IsValid) { DateTime time = DateTime.Now; if (!string.IsNullOrWhiteSpace(faqModel.TransactionDateFrom) && DateTime.TryParseExact(faqModel.TransactionDateFrom, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out time)) { faqModel.PostDate = time; bool isValidType = false; if (faqModel.NewsImage == null) { isValidType = true; } if (faqModel.NewsImage?.Length > 0) { var name = faqModel.NewsImage.FileName; string fileName = name.Split('\\').Last(); string extension = Path.GetExtension(fileName).ToLower(); if (extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif") { isValidType = true; } } if (!isValidType) { ModelState.AddModelError("NewsImage", Model.Resources.ValidationMessages.WrongFileType); CateNewssModel modelq = new CateNewssModel(); modelq.CateNewss = await _newsService.GetAllCateNews(); // ViewBag.CateNewsSelectList = data; List <SelectListItem> CateNewsIDs = new List <SelectListItem>(); foreach (CateNewsModel item in modelq.CateNewss) { SelectListItem item1 = new SelectListItem { Text = item.CateNewsName, Value = item.Id.ToString() }; CateNewsIDs.Add(item1); } faqModel.CateNewsIDs = CateNewsIDs; } await _newsService.UpdateContentNews(faqModel); } var id = faqModel.Id; return(RedirectToAction(nameof(ContentNewsController.List))); } return(View(faqModel)); }
public async Task <ContentNewsModel> GetContentNews(int?newsId) { try { ContentNews news = await _newsManager.GetContentNews(newsId); ContentNewsModel newsModel = _mapper.Map <ContentNewsModel>(news); return(newsModel); } catch (Exception ex) { throw ex; } }
public async Task <ContentNewsModel> SaveContentNews(ContentNewsModel newsModel) { try { ContentNews news = _mapper.Map <ContentNews>(newsModel); ContentNews savedNews = await _newsManager.SaveContentNews(news); ContentNewsModel savedNewsModel = _mapper.Map <ContentNewsModel>(savedNews); return(savedNewsModel); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> New() { CateNewssModel modelq = new CateNewssModel(); modelq.CateNewss = await _newsService.GetAllCateNews(); // ViewBag.CateNewsSelectList = data; ContentNewsModel faqModel = new ContentNewsModel(); List <SelectListItem> CateNewsIDs = new List <SelectListItem>(); foreach (CateNewsModel item in modelq.CateNewss) { SelectListItem item1 = new SelectListItem { Text = item.CateNewsName, Value = item.Id.ToString() }; CateNewsIDs.Add(item1); } faqModel.CateNewsIDs = CateNewsIDs; faqModel.PostDate = DateTime.Now; return(View(faqModel)); }
public async Task <IActionResult> Edit(int id) { ContentNewsModel model = await _newsService.GetContentNews(id); CateNewssModel modelq = new CateNewssModel(); modelq.CateNewss = await _newsService.GetAllCateNews(); // ViewBag.CateNewsSelectList = data; List <SelectListItem> CateNewsIDs = new List <SelectListItem>(); foreach (CateNewsModel item in modelq.CateNewss) { SelectListItem item1 = new SelectListItem { Text = item.CateNewsName, Value = item.Id.ToString() }; CateNewsIDs.Add(item1); } model.CateNewsIDs = CateNewsIDs; model.TransactionDateFrom = model.PostDate.ToString("dd/MM/yyyy"); return(View(model)); }
public async Task <IActionResult> Detail(int id) { try { //get contact from db //if (!_userService.IsSignedIn(User)) //{ // return RedirectToAction(nameof(HomeController.Index), "Home"); //} ContentNewsModel model = new ContentNewsModel(); model = await _newsService.GetContentNews(id); ViewBag.LstNewsOthersViewModel = await _newsService.GetListContentNewsOtherNew(5, 1, id, model.PostDate); ViewBag.LstNewsOthersViewModelOld = await _newsService.GetListContentNewsOtherOld(5, 1, id, model.PostDate); return(View(model)); // return View("~/Views/Support/Contact.cshtml", model); } catch (Exception ex) { throw ex; } }