public async Task <IActionResult> Create(PageNewsTypeCreateViewModel NewsTypeViewModel) { if (ModelState.IsValid) { PageNewsType PageNewsType = NewsTypeViewModel.MapToPageNewsTypeViewModel(); var user = await _userManager.GetUserAsync(HttpContext.User); PageNewsType.CreatedById = user.Id; PageNewsType.CreationDate = DateTime.Now; PageNewsType newPageNewsType = _PageNewsTypeRepository.Add(PageNewsType); if (newPageNewsType != null) { _toastNotification.AddSuccessToastMessage(ToasrMessages.AddSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Add, "Definitions > News Type > Add", newPageNewsType.EnName); return(RedirectToAction("Index")); } else { _toastNotification.AddErrorToastMessage(ToasrMessages.warning); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Definitions > News Type > Add", PageNewsType.EnName); return(View(NewsTypeViewModel)); } } return(View(NewsTypeViewModel)); }
public IActionResult Edit(int id) { PageNewsType PageNewsType = _PageNewsTypeRepository.Get(id); NewsTypeViewModel NewsTypeVm = PageNewsType.MapToPageNewsTypeViewModelInEdit(); PageNewsTypeEditViewModel viewModel = new PageNewsTypeEditViewModel(NewsTypeVm); return(View(viewModel)); }
//edit post public static PageNewsType MapToPageNewsTypeVersion(this PageNewsTypeEditViewModel PageNewsTypeViewModel) { PageNewsType PageNewsType = new PageNewsType(); PageNewsType.Id = PageNewsTypeViewModel.NewsType.Id.Value; PageNewsType.EnName = PageNewsTypeViewModel.NewsType.EnName; PageNewsType.ArName = PageNewsTypeViewModel.NewsType.ArName; return(PageNewsType); }
//create public static PageNewsType MapToPageNewsTypeViewModel(this PageNewsTypeCreateViewModel PageNewsTypeCreateViewModel) { PageNewsType viewModel = new PageNewsType() { EnName = PageNewsTypeCreateViewModel.NewsType.EnName, ArName = PageNewsTypeCreateViewModel.NewsType.ArName, }; return(viewModel); }
//edit get public static NewsTypeViewModel MapToPageNewsTypeViewModelInEdit(this PageNewsType PageNewsType) { NewsTypeViewModel newsTypeViewModel = new NewsTypeViewModel { Id = PageNewsType.Id, EnName = PageNewsType.EnName, ArName = PageNewsType.ArName, }; return(newsTypeViewModel); }
public PageNewsType Update(PageNewsType pageNewsType) { try { var item = _db.PageNewsType.Attach(pageNewsType); item.State = EntityState.Modified; _db.SaveChanges(); return(_db.PageNewsType.FirstOrDefault(s => s.Id == pageNewsType.Id)); } catch (Exception ex) { return(null); } }
public PageNewsType Add(PageNewsType pageNewsType) { try { _db.PageNewsType.Add(pageNewsType); _db.SaveChanges(); return(_db.PageNewsType.FirstOrDefault(c => c.Id == pageNewsType.Id)); } catch (Exception ex) { return(null); } }
public IActionResult Delete(int id) { PageNewsType NewsType = _PageNewsTypeRepository.Delete(id); if (NewsType != null) { TempData[notificationMessageKey] = "Element has been deleted successfully. </br> It will take effect after admin approval."; TempData[notificationTypeKey] = notificationSuccess; _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Delete, "Definitions > News Type > Delete", NewsType.EnName); return(Json(new { })); } TempData[notificationMessageKey] = "Error has been occurred."; TempData[notificationTypeKey] = notificationError; _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Definitions > News Type > Delete", "Error has been occurred."); return(Json(new { })); }
public IActionResult Edit(PageNewsTypeEditViewModel pageNewsTypeEditViewModel) { if (ModelState.IsValid) { PageNewsType PageNewsType = pageNewsTypeEditViewModel.MapToPageNewsTypeVersion(); PageNewsType newPageNewsType = _PageNewsTypeRepository.Update(PageNewsType); if (newPageNewsType != null) { _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Definitions > News Type > Edit", pageNewsTypeEditViewModel.NewsType.EnName); return(RedirectToAction("Index")); } _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Definitions > News Type > Edit", pageNewsTypeEditViewModel.NewsType.EnName); _toastNotification.AddErrorToastMessage(ToasrMessages.warning); return(View(pageNewsTypeEditViewModel)); } return(View(pageNewsTypeEditViewModel)); }