public IActionResult Edit(ComponentFormViewModel viewModel, [FromQuery] int sheetType)
        {
            if (ModelState.IsValid)
            {
                if (sheetType == (int)SheetTypeEnum.ComponentConst)
                {
                    return(EditConst(viewModel, out int id));
                }
                else if (sheetType == (int)SheetTypeEnum.ComponentCurrent)
                {
                    return(EditCurrent(viewModel, out int id));
                }
            }

            if (sheetType == (int)SheetTypeEnum.ComponentConst)
            {
                FormEditCommon((int)DFIndicatorEnum.GDPByExpenditureAtMarketPricesConstantprices, viewModel);

                ViewBag.Component     = "Constant";
                ViewBag.ComponentEnum = (int)SheetTypeEnum.ComponentConst;
            }
            else if (sheetType == (int)SheetTypeEnum.ComponentCurrent)
            {
                FormEditCommon((int)DFIndicatorEnum.GDPByExpenditureAtMarketPricesCurrentPrices, viewModel);

                ViewBag.Component     = "Current";
                ViewBag.ComponentEnum = (int)SheetTypeEnum.ComponentCurrent;
            }

            return(View(viewModel));
        }
        public async Task <IActionResult> Create(ComponentFormViewModel viewModel, [FromQuery] int sheetType)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                viewModel.CreatedById = user.Id;

                if (sheetType == (int)SheetTypeEnum.ComponentConst)
                {
                    viewModel.DFIndicatorId = (int)DFIndicatorEnum.GDPByExpenditureAtMarketPricesConstantprices;
                    _componentConstantRepository.AddVer(viewModel.MapToComponentConstantVerModel());
                    _toastNotification.AddSuccessToastMessage("Element has been Created successfully.");
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Add, "Definitions > Economic Indicators > Component > Constant", "Constant ID " + viewModel.DFIndicatorId);
                    return(RedirectToAction(nameof(Index), new { sheetType = (int)SheetTypeEnum.ComponentConst }));
                }
                if (sheetType == (int)SheetTypeEnum.ComponentCurrent)
                {
                    viewModel.DFIndicatorId = (int)DFIndicatorEnum.GDPByExpenditureAtMarketPricesCurrentPrices;
                    _componentCurrenttRepository.AddVer(viewModel.MapToComponentCurrentVerModel());
                    _toastNotification.AddSuccessToastMessage("Element has been Created successfully.");
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Add, "Definitions > Economic Indicators > Component > Current", "Current  ID " + viewModel.DFIndicatorId);
                    return(RedirectToAction(nameof(Index), new { sheetType = (int)SheetTypeEnum.ComponentCurrent }));
                }
            }
            CreateCommon(sheetType);
            return(View(viewModel));
        }
        /// <summary>
        /// Core form edit based on sheet type
        /// </summary>
        /// <param name="indicator">indicator id</param>
        /// <param name="componentFormViewModel">component edited model</param>
        /// <returns></returns>
        private void FormEditCommon(int indicator, ComponentFormViewModel componentFormViewModel)
        {
            ViewBag.Indicator = _dFIndicatorRepository.GetByID(indicator).NameEn;
            ViewBag.Source    = _dFSourceRepository.GetByID((int)DFSourceEnum.MinistryOfPlanning).NameEn;
            ViewBag.Unit      = _dFUnitRepository.GetByID((int)DFUnitEnum.BillionEGP).NameEn;
            var allYears = _dFYearsRepository.GetAll();

            ViewBag.DFYearBaseId   = new SelectList(allYears, "Id", "NameEn", componentFormViewModel.DFYearBaseId);
            ViewBag.DFYearFiscalId = new SelectList(allYears, "Id", "NameEn", componentFormViewModel.DFYearFiscalId);
            ViewBag.DFQuarterId    = new SelectList(_dFQuartersRepository.GetAll(), "Id", "NameEn", componentFormViewModel.DFQuarterId);
        }
        public IActionResult Edit([FromQuery] int sheetType, [FromQuery] bool isVersion, int id)
        {
            ComponentFormViewModel componentViewModel = null;

            if (sheetType == (int)SheetTypeEnum.ComponentConst)
            {
                var componentConstVerModel = _componentConstantRepository.GetVerById(id);
                if (componentConstVerModel != null && isVersion)
                {
                    componentViewModel = componentConstVerModel.MapToComponentConstantViewModel();
                }
                else
                {
                    var componentConstModel = _componentConstantRepository.GetById(id);
                    componentViewModel = componentConstModel.MapToComponentConstantViewModel();
                }


                ViewBag.Indicator = _dFIndicatorRepository.GetByID((int)DFIndicatorEnum.GDPByExpenditureAtMarketPricesConstantprices).NameEn;
                FormEditCommon((int)DFIndicatorEnum.GDPByExpenditureAtMarketPricesConstantprices, componentViewModel);

                ViewBag.Component     = "Constant";
                ViewBag.ComponentEnum = (int)SheetTypeEnum.ComponentConst;
            }
            else if (sheetType == (int)SheetTypeEnum.ComponentCurrent)
            {
                var componentCurrentVerModel = _componentCurrenttRepository.GetVerById(id);
                if (componentCurrentVerModel != null && isVersion)
                {
                    componentViewModel = componentCurrentVerModel.MapToComponentCurrentViewModel();
                }
                else
                {
                    var componentCurrenttModel = _componentCurrenttRepository.GetById(id);
                    componentViewModel = componentCurrenttModel.MapToComponentCurrentViewModel();
                }

                FormEditCommon((int)DFIndicatorEnum.GDPByExpenditureAtMarketPricesCurrentPrices, componentViewModel);

                ViewBag.Component     = "Current";
                ViewBag.ComponentEnum = (int)SheetTypeEnum.ComponentCurrent;
            }

            return(View(componentViewModel));
        }
Exemple #5
0
 public static ComponentCurrent MapToComponentCurrentModel(this ComponentFormViewModel model)
 {
     return(new ComponentCurrent()
     {
         Id = model.Id,
         DFIndicatorId = model.DFIndicatorId,
         DFSourceId = model.DFSourceId,
         DFYearFiscalId = model.DFYearFiscalId,
         DFUnitId = model.DFUnitId,
         DFQuarterId = model.DFQuarterId,
         IsDeleted = model.IsDeleted,
         ExportsOfGoodsAndServices = model.ExportsOfGoodsAndServices,
         GovernmentConsumption = model.GovernmentConsumption,
         GrossCapitalFormation = model.GrossCapitalFormation,
         ImportsOfGoodsAndServices = model.ImportsOfGoodsAndServices,
         PrivateConsumption = model.PrivateConsumption,
         TotalGrossDomesticProductAtMarketPrices = model.TotalGrossDomesticProductAtMarketPrices
     });
 }
        private IActionResult EditCurrent(ComponentFormViewModel viewModel, out int id, bool fromDelete = false)
        {
            var componentCurrentVersion = _componentCurrenttRepository.GetByComponentCurrentId(viewModel.ComponentId ?? 0);
            var componentCurrentById    = _componentCurrenttRepository.GetVerById(viewModel.Id);

            componentCurrentVersion = componentCurrentById == null ? componentCurrentVersion : componentCurrentById;
            var componentCurrentVersionModel = viewModel.MapToComponentCurrentVerModel();

            componentCurrentVersionModel.ComponentCurrentId = viewModel.ComponentId > 0 ? viewModel.ComponentId : (int?)null;
            if (!fromDelete)
            {
                componentCurrentVersionModel.ChangeActionEnum = ChangeActionEIEnum.Update;
                componentCurrentVersionModel.IsDeleted        = false;
            }
            else
            {
                componentCurrentVersionModel.ChangeActionEnum = ChangeActionEIEnum.Delete;
            }
            if (componentCurrentVersion == null || componentCurrentVersionModel.VersionStatusEnum == VersionStatusEIEnum.Approved || componentCurrentVersionModel.VersionStatusEnum == VersionStatusEIEnum.Ignored)
            {
                var user = _userManager.GetUserAsync(HttpContext.User);
                componentCurrentVersionModel.VersionStatusEnum = VersionStatusEIEnum.Draft;
                componentCurrentVersionModel.Id          = 0;
                componentCurrentVersionModel.CreatedById = user.Result.Id;


                _componentCurrenttRepository.AddVer(componentCurrentVersionModel);
                _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess);
                id = componentCurrentVersionModel.Id;
                return(RedirectToAction(nameof(Index), new { sheetType = (int)SheetTypeEnum.ComponentCurrent }));
            }

            componentCurrentVersionModel.Id = componentCurrentVersion != null ? componentCurrentVersion.Id : viewModel.Id;

            _componentCurrenttRepository.UpdateVer(componentCurrentVersionModel);
            id = componentCurrentVersionModel.Id;
            _toastNotification.AddSuccessToastMessage("Element has been Edited successfully.");
            _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Definitions > Economic Indicators > Component > current", "current  ID " + viewModel.Id);
            return(RedirectToAction(nameof(Index), new { sheetType = (int)SheetTypeEnum.ComponentCurrent }));
        }
Exemple #7
0
 public static ComponentConstantVersion MapToComponentConstantVerModel(this ComponentFormViewModel model)
 {
     return(new ComponentConstantVersion()
     {
         Id = model.Id,
         DFIndicatorId = model.DFIndicatorId,
         DFSourceId = model.DFSourceId,
         DFYearFiscalId = model.DFYearFiscalId,
         DFUnitId = model.DFUnitId,
         DFQuarterId = model.DFQuarterId,
         IsDeleted = model.IsDeleted,
         ExportsOfGoodsAndServices = model.ExportsOfGoodsAndServices,
         GovernmentConsumption = model.GovernmentConsumption,
         GrossCapitalFormation = model.GrossCapitalFormation,
         ImportsOfGoodsAndServices = model.ImportsOfGoodsAndServices,
         PrivateConsumption = model.PrivateConsumption,
         TotalGrossDomesticProductAtMarketPrices = model.TotalGrossDomesticProductAtMarketPrices,
         VersionStatusEnum = MPMAR.Analytics.Data.Enums.VersionStatusEIEnum.Draft,
         ChangeActionEnum = MPMAR.Analytics.Data.Enums.ChangeActionEIEnum.New,
         ComponentConstantId = model.ComponentId,
         CreatedById = model.CreatedById
     });
 }