public IActionResult Create(int pageRouteId) { List <PageNewsType> sectionTypes = _PageNewsRepository.GetPageNewsTypes(); PageNewsCreateViewModel viewModel = new PageNewsCreateViewModel(sectionTypes); viewModel.PageRouteId = pageRouteId; return(View(viewModel)); }
//view //public static PageNews MapToNewsVersion(this PageNews News) //{ // PageNews PageNews = new PageNews // { // Id = News.Id, // EnTitle = News.EnTitle, // ArTitle = News.ArTitle, // EnDescription = News.EnDescription, // ArDescription = News.ArDescription, // EnShortDescription=News.EnShortDescription, // ArShortDescription=News.ArShortDescription, // IsActive = News.IsActive, // Url = News.Url, // }; // return PageNews; //} public static List <NewsTypesForNewsVersion> MapToNewsTypeForNews(this PageNewsCreateViewModel PageNewsViewModel) { List <NewsTypesForNewsVersion> NewsTypesForNewsList = new List <NewsTypesForNewsVersion>(); string NewsTypeIds = PageNewsViewModel.NewsTypeIds; var NewsTypeIdsList = NewsTypeIds.Split(','); foreach (var NewsTypeId in NewsTypeIdsList) { NewsTypesForNewsVersion NewsTypesForNews = new NewsTypesForNewsVersion(); NewsTypesForNews.NewsTypeId = int.Parse(NewsTypeId); NewsTypesForNewsList.Add(NewsTypesForNews); } return(NewsTypesForNewsList); }
//create public static PageNewsVersion MapToPageNewsViewModel(this PageNewsCreateViewModel PageNewsCreateViewModel) { PageNewsVersion viewModel = new PageNewsVersion() { EnTitle = PageNewsCreateViewModel.News.EnTitle, ArTitle = PageNewsCreateViewModel.News.ArTitle, EnDescription = PageNewsCreateViewModel.News.EnDescription, ArDescription = PageNewsCreateViewModel.News.ArDescription, EnShortDescription = PageNewsCreateViewModel.News.EnShortDescription, ArShortDescription = PageNewsCreateViewModel.News.ArShortDescription, IsActive = PageNewsCreateViewModel.News.IsActive, Date = PageNewsCreateViewModel.News.Date, NewsTypesForNewsVersions = PageNewsCreateViewModel.MapToNewsTypeForNews() }; return(viewModel); }
public async Task <IActionResult> Create(PageNewsCreateViewModel NewsViewModel) { List <PageNewsType> NewsTypes; NewsViewModel.News.EnDescription.ValidateHtml("EnDescription", ModelState); NewsViewModel.News.ArDescription.ValidateHtml("ArDescription", ModelState); NewsViewModel.News.EnDescription.ValidateHtml("EnDescription", ModelState); NewsViewModel.News.ArDescription.ValidateHtml("ArDescription", ModelState); if (ModelState.IsValid) { PageNewsVersion PageNews = NewsViewModel.MapToPageNewsViewModel(); if (NewsViewModel.News.Photo != null) { PageNews.Url = _fileService.UploadImageUrlNew(NewsViewModel.News.Photo); } var user = await _userManager.GetUserAsync(HttpContext.User); PageNews.CreatedById = user.Id; PageNews.CreationDate = DateTime.Now; PageNewsVersion newPageNews = _PageNewsRepository.Add(PageNews, NewsViewModel.PageRouteId); if (newPageNews != null) { _toastNotification.AddSuccessToastMessage(ToasrMessages.AddSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Add, "Static Page > News > Add", NewsViewModel.News.EnTitle); return(RedirectToAction("Index", new { pageRouteId = NewsViewModel.PageRouteId })); } else { _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Static Page > News > Add", NewsViewModel.News.EnTitle); _toastNotification.AddErrorToastMessage(ToasrMessages.warning); NewsTypes = _PageNewsRepository.GetPageNewsTypes(); NewsViewModel = new PageNewsCreateViewModel(NewsTypes); return(View(NewsViewModel)); } } NewsTypes = _PageNewsRepository.GetPageNewsTypes(); NewsViewModel = new PageNewsCreateViewModel(NewsTypes); return(View(NewsViewModel)); }