示例#1
0
        public static HomePagePhotoVersions MapToPhotoVersionModel(this HP_PhotoViewModel pgMinisty)
        {
            HomePagePhotoVersions viewModel = new HomePagePhotoVersions()
            {
                Id = pgMinisty.PhotoId ?? pgMinisty.Id,
                IsActive = pgMinisty.IsActive,
                IsDeleted = pgMinisty.IsDeleted,
                VersionStatusEnum = pgMinisty.VersionStatusEnum,
                ChangeActionEnum = pgMinisty.ChangeActionEnum,
                CreationDate = pgMinisty.CreationDate,
                ModificationDate = pgMinisty.ModificationDate,
                ModifiedById = pgMinisty.ModifiedById,
                ApprovalDate = pgMinisty.ApprovalDate,
                ApprovedById = pgMinisty.ApprovedById,
                CreatedById = pgMinisty.CreatedById,
                ArDescription = pgMinisty.ArDescription,
                ArTitle = pgMinisty.ArTitle,
                EnDescription = pgMinisty.EnDescription,
                EnTitle = pgMinisty.EnTitle,
                ImageUrl = pgMinisty.ImageUrl,
                HomePagePhotoId = pgMinisty.PhotoId,
                Url = pgMinisty.Url
            };

            return viewModel;
        }
示例#2
0
 public static HomePagePhoto MapToPhotosModel(this HP_PhotoViewModel viewModel)
 {
     return new HomePagePhoto()
     {
         Id = viewModel.Id,
         EnTitle = viewModel.EnTitle,
         ArDescription = viewModel.ArDescription,
         ArTitle = viewModel.ArTitle,
         EnDescription = viewModel.EnDescription,
         ImageUrl = viewModel.ImageUrl,
         IsActive = viewModel.IsActive,
         IsDeleted = viewModel.IsDeleted,
         Url = viewModel.Url
     };
 }
        public async Task <IActionResult> Edit(HP_PhotoViewModel ViewModel)
        {
            ViewModel.ArDescription.ValidateHtml("ArDescription", ModelState);
            ViewModel.EnDescription.ValidateHtml("EnDescription", ModelState);

            ModelState.Remove(nameof(ViewModel.ImageFile));

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

            if (ModelState.IsValid)
            {
                var phv          = _hP_PhotosVersionRepository.GetByPhotoId(ViewModel.Id);
                var photoVersion = ViewModel.MapToPhotoVersionModel();

                if (phv == null || ViewModel.VersionStatusEnum == VersionStatusEnum.Approved || ViewModel.VersionStatusEnum == VersionStatusEnum.Ignored)
                {
                    photoVersion.CreatedById       = user.Id;
                    photoVersion.CreationDate      = DateTime.Now;
                    photoVersion.VersionStatusEnum = VersionStatusEnum.Draft;
                    photoVersion.ChangeActionEnum  = ChangeActionEnum.Update;
                    photoVersion.Id = 0;
                    photoVersion.HomePagePhotoId = ViewModel.Id;
                    if (ViewModel.ImageFile != null)
                    {
                        photoVersion.ImageUrl = _fileService.UploadImageUrlNew(ViewModel.ImageFile);
                    }
                    _hP_PhotosVersionRepository.Add(photoVersion);
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Home Page > Photos > Update", ViewModel.EnTitle);
                    return(RedirectToAction(nameof(Index)));
                }


                if (ViewModel.ImageFile != null)
                {
                    photoVersion.ImageUrl = _fileService.UploadImageUrlNew(ViewModel.ImageFile);
                }

                photoVersion.CreationDate      = DateTime.Now;
                photoVersion.Id                = phv.Id;
                photoVersion.VersionStatusEnum = VersionStatusEnum.Draft;
                photoVersion.ChangeActionEnum  = ChangeActionEnum.Update;
                photoVersion.ApprovalDate      = phv.ApprovalDate;
                photoVersion.ApprovedById      = phv.ApprovedById;
                photoVersion.CreatedById       = phv.CreatedById;
                photoVersion.CreationDate      = phv.CreationDate;
                photoVersion.ModificationDate  = phv.ModificationDate;
                photoVersion.ModifiedById      = phv.ModifiedById;
                photoVersion.HomePagePhotoId   = phv.HomePagePhotoId;
                var update = _hP_PhotosVersionRepository.Update(photoVersion);
                if (update)
                {
                    _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess);
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Home Page > Photos > Update", ViewModel.EnTitle);
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    _toastNotification.AddErrorToastMessage(ToasrMessages.warning);
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Home Page > Photos > Warning", ViewModel.EnTitle);
                    return(View(ViewModel));
                }
            }
            return(View(ViewModel));
        }