public async Task <IActionResult> Edit(LeftMenuItemViewModel ViewModel)
        {
            ModelState.Remove(nameof(ViewModel.ImageFile));

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (ModelState.IsValid)
            {
                var lmi = _leftMenuItemsVersionsRepository.GetByLeftMenuItemId(ViewModel.Id);
                var leftMenuItemVersion = ViewModel.MapToLeftMenuItemVersionsModel();

                if (lmi == null || ViewModel.VersionStatusEnum == VersionStatusEnum.Approved || ViewModel.VersionStatusEnum == VersionStatusEnum.Ignored)
                {
                    leftMenuItemVersion.CreatedById       = user.Id;
                    leftMenuItemVersion.CreationDate      = DateTime.Now;
                    leftMenuItemVersion.VersionStatusEnum = VersionStatusEnum.Draft;
                    leftMenuItemVersion.ChangeActionEnum  = ChangeActionEnum.Update;
                    leftMenuItemVersion.Id             = 0;
                    leftMenuItemVersion.LeftMenuItemId = ViewModel.Id;
                    if (ViewModel.ImageFile != null)
                    {
                        leftMenuItemVersion.ImagePath = _fileService.UploadImageUrlNew(ViewModel.ImageFile);
                    }
                    _leftMenuItemsVersionsRepository.Add(leftMenuItemVersion);
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Definitions > Left Menu Item > Edit", ViewModel.EnTitle);
                    return(RedirectToAction(nameof(Index)));
                }


                if (ViewModel.ImageFile != null)
                {
                    leftMenuItemVersion.ImagePath = _fileService.UploadImageUrlNew(ViewModel.ImageFile);
                }

                leftMenuItemVersion.CreationDate      = DateTime.Now;
                leftMenuItemVersion.Id                = lmi.Id;
                leftMenuItemVersion.VersionStatusEnum = VersionStatusEnum.Draft;
                leftMenuItemVersion.ChangeActionEnum  = ChangeActionEnum.Update;
                leftMenuItemVersion.ApprovalDate      = lmi.ApprovalDate;
                leftMenuItemVersion.ApprovedById      = lmi.ApprovedById;
                leftMenuItemVersion.CreatedById       = lmi.CreatedById;
                leftMenuItemVersion.CreationDate      = lmi.CreationDate;
                leftMenuItemVersion.LeftMenuItemId    = lmi.LeftMenuItemId;
                var update = _leftMenuItemsVersionsRepository.Update(leftMenuItemVersion);
                if (update)
                {
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Definitions > Left Menu Item > Edit", ViewModel.EnTitle);
                    _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess);
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Definitions > Left Menu Item > Edit", ViewModel.EnTitle);
                    _toastNotification.AddErrorToastMessage(ToasrMessages.warning);
                    return(View(ViewModel));
                }
            }
            return(View(ViewModel));
        }
Ejemplo n.º 2
0
        //index
        //public static List<LeftMenuItemListViewModel> MapToLeftMenuItemListViewModel(this IEnumerable<LeftMenuItem> pageNewsType)
        //{
        //    return pageNewsType.Select(NewsType => new LeftMenuItemListViewModel
        //    {
        //        Id= NewsType.Id,
        //        EnName = NewsType.EnName,
        //        ArName= NewsType.ArName,
        //        IsDeleted=NewsType.IsDeleted
        //    }).ToList();
        //}

        //create

        //edit post
        //public static LeftMenuItem MapToLeftMenuItemVersion(this LeftMenuItemEditViewModel LeftMenuItemViewModel)
        //{
        //    LeftMenuItem LeftMenuItem = new LeftMenuItem();
        //    LeftMenuItem.Id = LeftMenuItemViewModel.NewsType.Id.Value;
        //    LeftMenuItem.EnName = LeftMenuItemViewModel.NewsType.EnName;
        //    LeftMenuItem.ArName = LeftMenuItemViewModel.NewsType.ArName;
        //    return LeftMenuItem;
        //}

        public static LeftMenuItem MapToLeftMenuItemViewModel(this LeftMenuItemViewModel LeftMenuItemCreateViewModel)
        {
            LeftMenuItem viewModel = new LeftMenuItem()
            {
                LeftMenuType = LeftMenuItemCreateViewModel.LeftMenuType,
                EnTitle      = LeftMenuItemCreateViewModel.EnTitle,
                ArTitle      = LeftMenuItemCreateViewModel.ArTitle,
                Link         = LeftMenuItemCreateViewModel.Link,
                ImagePath    = LeftMenuItemCreateViewModel.ImagePath,
                CreationDate = LeftMenuItemCreateViewModel.CreationDate,
                CreatedById  = LeftMenuItemCreateViewModel.CreatedById,
                IsActive     = LeftMenuItemCreateViewModel.IsActive
            };

            return(viewModel);
        }
Ejemplo n.º 3
0
        //edit get
        public static LeftMenuItemViewModel MapToLeftMenuItemViewModelInEdit(this LeftMenuItem LeftMenuItem)
        {
            LeftMenuItemViewModel newsTypeViewModel = new LeftMenuItemViewModel
            {
                Id           = LeftMenuItem.Id,
                LeftMenuType = LeftMenuItem.LeftMenuType,
                EnTitle      = LeftMenuItem.EnTitle,
                ArTitle      = LeftMenuItem.ArTitle,
                Link         = LeftMenuItem.Link,
                ImagePath    = LeftMenuItem.ImagePath,
                CreationDate = LeftMenuItem.CreationDate,
                CreatedById  = LeftMenuItem.CreatedById,
                IsActive     = LeftMenuItem.IsActive
            };

            return(newsTypeViewModel);
        }
Ejemplo n.º 4
0
        //edit get
        public static LeftMenuItemViewModel MapToLeftMenuItemVersionsViewModel(this LeftMenuItemVersions LeftMenuItemCreateViewModel)
        {
            LeftMenuItemViewModel newsTypeViewModel = new LeftMenuItemViewModel
            {
                LeftMenuType      = LeftMenuItemCreateViewModel.LeftMenuType,
                EnTitle           = LeftMenuItemCreateViewModel.EnTitle,
                ArTitle           = LeftMenuItemCreateViewModel.ArTitle,
                Link              = LeftMenuItemCreateViewModel.Link,
                ImagePath         = LeftMenuItemCreateViewModel.ImagePath,
                CreationDate      = LeftMenuItemCreateViewModel.CreationDate,
                CreatedById       = LeftMenuItemCreateViewModel.CreatedById,
                IsActive          = LeftMenuItemCreateViewModel.IsActive,
                Id                = LeftMenuItemCreateViewModel.Id,
                Order             = LeftMenuItemCreateViewModel.Order,
                IsDeleted         = LeftMenuItemCreateViewModel.IsDeleted,
                ApprovalDate      = LeftMenuItemCreateViewModel.ApprovalDate,
                ApprovedById      = LeftMenuItemCreateViewModel.ApprovedById,
                LeftMenuItemId    = LeftMenuItemCreateViewModel.LeftMenuItemId,
                VersionStatusEnum = LeftMenuItemCreateViewModel.VersionStatusEnum,
                ChangeActionEnum  = LeftMenuItemCreateViewModel.ChangeActionEnum
            };

            return(newsTypeViewModel);
        }