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));
        }
Пример #2
0
        //create
        public static PageNewsType MapToPageNewsTypeViewModel(this PageNewsTypeCreateViewModel PageNewsTypeCreateViewModel)
        {
            PageNewsType viewModel = new PageNewsType()
            {
                EnName = PageNewsTypeCreateViewModel.NewsType.EnName,
                ArName = PageNewsTypeCreateViewModel.NewsType.ArName,
            };

            return(viewModel);
        }
        public IActionResult Create()
        {
            PageNewsTypeCreateViewModel viewModel = new PageNewsTypeCreateViewModel();

            return(View(viewModel));
        }