Ejemplo n.º 1
0
        public async Task <IActionResult> SubmitChanges([FromQuery] int cityPlanId, [FromQuery] int id)
        {
            var pageRouteVersion = _pageRouteVersionRepository.GetPageRouteVersionByPageType(PageTypeConsts.CityPlan);
            var user             = await _userManager.GetUserAsync(HttpContext.User);

            var cityPlanVersion = _cityPlanVersionRepository.GetDetail(id);

            if (cityPlanVersion != null)
            {
                cityPlanVersion.VersionStatusEnum = VersionStatusEnum.Submitted;
                _cityPlanVersionRepository.Update(cityPlanVersion);
            }
            var cityPlanYearVersion = _cityPlanYearVersionRepository.GetDraftByCityId(cityPlanVersion.Id);

            foreach (var record in cityPlanYearVersion)
            {
                record.VersionStatusEnum = VersionStatusEnum.Submitted;
                _cityPlanYearVersionRepository.Update(record);
            }

            var ifApprovalExist = _approvalNotificationsRepository.GetByPageNameAndRelatedId(PagesNamesConst.CityPlan, id);

            if (ifApprovalExist == null || ifApprovalExist.VersionStatusEnum == VersionStatusEnum.Approved || ifApprovalExist.VersionStatusEnum == VersionStatusEnum.Ignored)
            {
                ApprovalNotification approval = new ApprovalNotification()
                {
                    ChangeAction      = ChangeActionEnum.Update,
                    VersionStatusEnum = VersionStatusEnum.Submitted,
                    ChangesDateTime   = DateTime.Now,
                    ChangeType        = ChangeType.PageContent,
                    PageLink          = $"/{nameof(CityPlanController)[0..^10]}?cityPlanVerId={id}",
Ejemplo n.º 2
0
        /// <summary>
        /// core method for update city plan year
        /// </summary>
        /// <param name="viewModel">view model for city plan year</param>
        /// <returns></returns>
        private async Task <IActionResult> EditMethod(CityPlanYearEditViewModel viewModel)
        {
            var pageRouteVersion = _pageRouteVersionRepository.GetPageRouteVersionByPageType(PageTypeConsts.CityPlan);

            if (ModelState.IsValid)
            {
                var cityPlanYearVersionByCityPlanYearId = _cityPlanYearVersionRepository.GetByCityYearId(viewModel.CityPlanYearId ?? 0);
                var cityPlanYearVersionById             = _cityPlanYearVersionRepository.GetDetail(viewModel.Id);
                cityPlanYearVersionByCityPlanYearId = cityPlanYearVersionById == null ? cityPlanYearVersionByCityPlanYearId : cityPlanYearVersionById;
                var cityPlanYearVersionModel = viewModel.MapToCityPlanYearVersion();

                if (viewModel.EnFile != null)
                {
                    cityPlanYearVersionModel.EnFileUrl = _fileService.UploadFileUrlNew(viewModel.EnFile);
                }
                if (viewModel.ArFile != null)
                {
                    cityPlanYearVersionModel.ArFileUrl = _fileService.UploadFileUrlNew(viewModel.ArFile);
                }

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

                if (cityPlanYearVersionByCityPlanYearId == null || cityPlanYearVersionModel.VersionStatusEnum == VersionStatusEnum.Approved || cityPlanYearVersionModel.VersionStatusEnum == VersionStatusEnum.Ignored)
                {
                    cityPlanYearVersionModel.CreatedById       = user.Id;
                    cityPlanYearVersionModel.CreationDate      = DateTime.Now;
                    cityPlanYearVersionModel.VersionStatusEnum = VersionStatusEnum.Draft;
                    cityPlanYearVersionModel.ChangeActionEnum  = ChangeActionEnum.Update;
                    cityPlanYearVersionModel.Id               = 0;
                    cityPlanYearVersionModel.CityPlanYearId   = viewModel.CityPlanYearId > 0 ? viewModel.CityPlanYearId : (int?)null;
                    pageRouteVersion.ContentVersionStatusEnum = VersionStatusEnum.Draft;
                    _cityPlanYearVersionRepository.Add(cityPlanYearVersionModel);
                    _pageRouteVersionRepository.Update(pageRouteVersion);
                    _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess);
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Static Page > Citizen Plan > Year Plan > Edit", "Year Plan ID " + cityPlanYearVersionModel.CityPlanYearId);

                    return(RedirectToAction(nameof(Index), new { cityPlanVerId = cityPlanYearVersionModel.CityPlanVersionId }));
                }

                cityPlanYearVersionModel.Id = cityPlanYearVersionByCityPlanYearId != null ? cityPlanYearVersionByCityPlanYearId.Id : viewModel.Id;
                pageRouteVersion.ContentVersionStatusEnum = VersionStatusEnum.Draft;

                _cityPlanYearVersionRepository.Update(cityPlanYearVersionModel);
                _pageRouteVersionRepository.Update(pageRouteVersion);
                _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess);

                _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Static Page > Citizen Plan > Year Plan > Edit", "Year Plan ID " + cityPlanYearVersionModel.Id);

                return(RedirectToAction(nameof(Index), new { cityPlanVerId = cityPlanYearVersionModel.CityPlanVersionId }));
            }
            return(View(viewModel));
        }