Beispiel #1
0
        public virtual JsonResult SaveOperationPlan(List <SPSaveViewModel> dataSave, List <SPSaveViewModel> operationNumberSave, List <SPJustifications> justificationSave, SPSearchByFilterDTO filters, bool submit, int currentPeriod, int currentYear, string roleSelected)
        {
            var userName         = IDBContext.Current.UserName;
            var role             = Session[userName + roleSelected].ToString();
            var roleUser         = _spAdministrationService.GetRoleIdByRole(Session[userName + roleSelected].ToString());
            var getSecurityGroup = Globals.Resolve <IAuthorizationManager>().GetAdGroups(userName);

            getSecurityGroup = _spAdministrationService.FilterSecurityGroups(getSecurityGroup, roleUser);
            var securityGroup = string.Join(",", getSecurityGroup.ToArray());

            if (currentPeriod == 1)
            {
                if (role == SpGlobalValues.ChiefofOperations)
                {
                    if (dataSave != null)
                    {
                        foreach (var item in dataSave)
                        {
                            var existData = _viewModelMapperHelper.GetSupervisionPlanModality(item.OperationNumber);
                            if (existData.IsValid)
                            {
                                if (item.Value != item.ModalityValues)
                                {
                                    _viewModelMapperHelper.UpdateSupervisionPlanModality(item, role);
                                }
                            }
                            else
                            {
                                _viewModelMapperHelper.SaveSupervisionPlanModality(item, role);
                            }
                        }
                    }

                    if (justificationSave != null)
                    {
                        foreach (var item in justificationSave)
                        {
                            var idSupervisionPlan =
                                _viewModelMapperHelper.GetSupervisionPlanId(item.OperationNumber, currentYear);

                            if (idSupervisionPlan == 0)
                            {
                                idSupervisionPlan =
                                    _viewModelMapperHelper.CreateNewSupervisionPlan(item.OperationNumber,
                                                                                    currentYear);
                            }

                            _spAdministrationService.SaveJustifications(item.Value, idSupervisionPlan);
                        }
                    }

                    if (submit)
                    {
                        _spAdministrationService.SupervisionPlanSubmit(filters.OperationNum, filters.OperationName, filters.ApprovalYear.ToString(), filters.Unit, filters.PrevYearMarhPmrClass, filters.CurrYearMarPmrClass, filters.ExFinanciatExtCri, filters.SpModality, filters.SpModalityAfter, filters.LastEditedBy, securityGroup, roleUser, filters.IsRevRequired, currentYear, userName, role, currentPeriod);
                        _viewModelMapperHelper.SendMessageCountryRepresentativeBySecurityGroup(getSecurityGroup.ToList());
                    }
                }
                else
                {
                    if (dataSave != null)
                    {
                        foreach (var item in dataSave)
                        {
                            var existData = _viewModelMapperHelper.GetSupervisionPlanModality(item.OperationNumber);
                            if (existData.IsValid)
                            {
                                _viewModelMapperHelper.UpdateSupervisionPlanModality(item, role);
                            }
                            else
                            {
                                _viewModelMapperHelper.SaveSupervisionPlanModality(item, role);
                            }
                        }
                    }

                    if (justificationSave != null)
                    {
                        foreach (var item in justificationSave)
                        {
                            var idSupervisionPlan =
                                _viewModelMapperHelper.GetSupervisionPlanId(item.OperationNumber, currentYear);

                            if (idSupervisionPlan == 0)
                            {
                                idSupervisionPlan =
                                    _viewModelMapperHelper.CreateNewSupervisionPlan(item.OperationNumber,
                                                                                    currentYear);
                            }

                            _spAdministrationService.SaveJustifications(item.Value, idSupervisionPlan);
                        }
                    }

                    if (submit)
                    {
                        var response = _spAdministrationService.SupervisionPlanSubmit(
                            filters.OperationNum,
                            filters.OperationName,
                            filters.ApprovalYear.ToString(),
                            filters.Unit,
                            filters.PrevYearMarhPmrClass,
                            filters.CurrYearMarPmrClass,
                            filters.ExFinanciatExtCri,
                            filters.SpModality,
                            filters.SpModalityAfter,
                            filters.LastEditedBy,
                            securityGroup,
                            roleUser,
                            filters.IsRevRequired,
                            currentYear,
                            userName,
                            role,
                            currentPeriod);

                        _viewModelMapperHelper.SendMessageTeamLeader(response.SPCreatedOperations);
                        _viewModelMapperHelper.SendMessageChiefOperationsBySecurityGroup(getSecurityGroup.ToList());
                    }
                }
            }
            else
            {
                if (role == SpGlobalValues.ChiefofOperations)
                {
                    if (dataSave != null)
                    {
                        foreach (var item in dataSave)
                        {
                            var existData = _viewModelMapperHelper.GetSupervisionPlanModality(item.OperationNumber);
                            if (existData.IsValid)
                            {
                                if (item.Value != item.ModalityValues)
                                {
                                    _viewModelMapperHelper.UpdateSupervisionPlanModality(item, role);
                                }
                            }
                            else
                            {
                                _viewModelMapperHelper.SaveSupervisionPlanModality(item, role);
                            }
                        }
                    }

                    if (justificationSave != null)
                    {
                        foreach (var item in justificationSave)
                        {
                            var idSupervisionPlan =
                                _viewModelMapperHelper.GetSupervisionPlanId(item.OperationNumber, currentYear);

                            if (idSupervisionPlan == 0)
                            {
                                idSupervisionPlan =
                                    _viewModelMapperHelper.CreateNewSupervisionPlan(item.OperationNumber,
                                                                                    currentYear);
                            }

                            _spAdministrationService.SaveJustifications(item.Value, idSupervisionPlan);
                        }
                    }

                    if (submit)
                    {
                        _spAdministrationService.SupervisionPlanSubmit(filters.OperationNum, filters.OperationName, filters.ApprovalYear.ToString(), filters.Unit, filters.PrevYearMarhPmrClass, filters.CurrYearMarPmrClass, filters.ExFinanciatExtCri, filters.SpModality, filters.SpModalityAfter, filters.LastEditedBy, securityGroup, roleUser, filters.IsRevRequired, currentYear, userName, role, currentPeriod);
                        _viewModelMapperHelper.SendMessageCountryRepresentativeBySecurityGroup(getSecurityGroup.ToList(), false);
                    }
                }
                else
                {
                    if (dataSave != null)
                    {
                        foreach (var item in dataSave)
                        {
                            var existData = _viewModelMapperHelper.GetSupervisionPlanModality(item.OperationNumber);
                            if (existData.IsValid)
                            {
                                if (item.Value != item.ModalityValues)
                                {
                                    _viewModelMapperHelper.UpdateSupervisionPlanModality(item, role);
                                }
                            }
                            else
                            {
                                _viewModelMapperHelper.SaveSupervisionPlanModality(item, role);
                            }
                        }
                    }

                    if (justificationSave != null)
                    {
                        foreach (var item in justificationSave)
                        {
                            var idSupervisionPlan =
                                _viewModelMapperHelper.GetSupervisionPlanId(item.OperationNumber, currentYear);

                            if (idSupervisionPlan == 0)
                            {
                                idSupervisionPlan =
                                    _viewModelMapperHelper.CreateNewSupervisionPlan(item.OperationNumber,
                                                                                    currentYear);
                            }

                            _spAdministrationService.SaveJustifications(item.Value, idSupervisionPlan);
                        }
                    }

                    if (submit)
                    {
                        var response = _spAdministrationService.SupervisionPlanSubmit(filters.OperationNum, filters.OperationName, filters.ApprovalYear.ToString(), filters.Unit, filters.PrevYearMarhPmrClass, filters.CurrYearMarPmrClass, filters.ExFinanciatExtCri, filters.SpModality, filters.SpModalityAfter, filters.LastEditedBy, securityGroup, roleUser, filters.IsRevRequired, currentYear, userName, role, currentPeriod);
                        _viewModelMapperHelper.SendMessageTeamLeader(response.SPCreatedOperations);
                        _viewModelMapperHelper.SendMessageTeamLeader(response.SPUpdatedOperations, true);
                        _viewModelMapperHelper.SendMessageChiefOperationsBySecurityGroup(getSecurityGroup.ToList(), false);
                    }
                }
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }