/// <summary>
        /// Save the program.
        /// </summary>
        /// <param name="program">The program.</param>
        /// <returns></returns>
        public Response <ProgramDetailsModel> SaveProgram(ProgramDetailsModel program)
        {
            var programResponse = new Response <ProgramDetailsModel>();

            using (var transactionScope = _unitOfWork.BeginTransactionScope())
            {
                var programResult = new Response <OrganizationDetailsModel>();
                if (program.Program.DetailID > 0)
                {
                    programResult = _organizationStructureDataProvider.UpdateOrganizationStructure(program.Program);
                }
                else
                {
                    program.Program.DataKey  = OrganizationType.Program.ToString();
                    programResult            = _organizationStructureDataProvider.AddOrganizationStructure(program.Program);
                    program.Program.DetailID = programResult.ID;
                }

                program.ProgramHierarchies.ForEach(item =>
                {
                    item.ProgramID = program.Program.DetailID;
                });

                // if program is failed to save
                if (programResult.ResultCode != 0)
                {
                    programResponse.ResultCode    = programResult.ResultCode;
                    programResponse.ResultMessage = programResult.ResultMessage;
                    return(programResponse);
                }

                var programHierarchyResult = _organizationStructureDataProvider.SaveOrganizationHierarchy(program.ProgramHierarchies, OrganizationType.Program.ToString());
                // if program hierarchy is failed to save
                if (programHierarchyResult.ResultCode != 0)
                {
                    programResponse.ResultCode    = programHierarchyResult.ResultCode;
                    programResponse.ResultMessage = programHierarchyResult.ResultMessage;
                    return(programResponse);
                }

                if (!program.ForceRollback.GetValueOrDefault(false))
                {
                    _unitOfWork.TransactionScopeComplete(transactionScope);
                }
            }

            return(programResponse);
        }
Пример #2
0
        /// <summary>
        /// Save the program unit.
        /// </summary>
        /// <param name="programUnit">The program unit.</param>
        /// <returns></returns>
        public Response <ProgramUnitDetailsModel> SaveProgramUnit(ProgramUnitDetailsModel programUnit)
        {
            var programUnitResponse = new Response <ProgramUnitDetailsModel>();

            using (var transactionScope = _unitOfWork.BeginTransactionScope())
            {
                var programUnitResult = new Response <OrganizationDetailsModel>();
                if (programUnit.ProgramUnit.DetailID > 0)
                {
                    programUnitResult = _organizationStructureDataProvider.UpdateOrganizationStructure(programUnit.ProgramUnit);
                }
                else
                {
                    programUnit.ProgramUnit.DataKey = OrganizationType.ProgramUnit.ToString();
                    programUnitResult = _organizationStructureDataProvider.AddOrganizationStructure(programUnit.ProgramUnit);
                    programUnit.ProgramUnit.DetailID = programUnitResult.ID;
                }

                programUnit.ReportingUnit.DetailID = programUnit.ProgramUnit.DetailID;

                programUnit.Addresses.ForEach(item =>
                {
                    item.DetailID = programUnit.ProgramUnit.DetailID;
                });
                programUnit.ProgramUnitHierarchies.ForEach(item =>
                {
                    item.ProgramUnitID = programUnit.ProgramUnit.DetailID;
                });
                programUnit.ProgramUnitServices.ForEach(item =>
                {
                    item.DetailID = programUnit.ProgramUnit.DetailID;
                });
                programUnit.ProgramUnitServiceWorkflows.ForEach(item =>
                {
                    item.DetailID = programUnit.ProgramUnit.DetailID;
                });

                // if program unit is failed to save
                if (programUnitResult.ResultCode != 0)
                {
                    programUnitResponse.ResultCode    = programUnitResult.ResultCode;
                    programUnitResponse.ResultMessage = programUnitResult.ResultMessage;
                    return(programUnitResponse);
                }

                var reportingUnitResult = _organizationIdentifiersDataProvider.SaveOrganizationIdentifiers(new List <OrganizationIdentifiersModel>()
                {
                    programUnit.ReportingUnit
                });
                // if reporting unit is failed to save
                if (reportingUnitResult.ResultCode != 0)
                {
                    programUnitResponse.ResultCode    = reportingUnitResult.ResultCode;
                    programUnitResponse.ResultMessage = reportingUnitResult.ResultMessage;
                    return(programUnitResponse);
                }

                var programUnitAddressResult = _organizationStructureDataProvider.SaveOrganizationAddress(programUnit.Addresses);
                // if program unit address is failed to save
                if (programUnitAddressResult.ResultCode != 0)
                {
                    programUnitResponse.ResultCode    = programUnitAddressResult.ResultCode;
                    programUnitResponse.ResultMessage = programUnitAddressResult.ResultMessage;
                    return(programUnitResponse);
                }

                var programUnitHierarchyResult = _organizationStructureDataProvider.SaveOrganizationHierarchy(programUnit.ProgramUnitHierarchies, OrganizationType.ProgramUnit.ToString());
                // if program unit hierarchy is failed to save
                if (programUnitHierarchyResult.ResultCode != 0)
                {
                    programUnitResponse.ResultCode    = programUnitHierarchyResult.ResultCode;
                    programUnitResponse.ResultMessage = programUnitHierarchyResult.ResultMessage;
                    return(programUnitResponse);
                }

                var programUnitServicesResult = _organizationStructureDataProvider.SaveServiceOrganization(programUnit.ProgramUnitServices);
                // if program unit services is failed to save
                if (programUnitServicesResult.ResultCode != 0)
                {
                    programUnitResponse.ResultCode    = programUnitServicesResult.ResultCode;
                    programUnitResponse.ResultMessage = programUnitServicesResult.ResultMessage;
                    return(programUnitResponse);
                }

                var programUnitServiceWorkflowsResult = _organizationStructureDataProvider.SaveOrganizationDetailsModuleComponent(programUnit.ProgramUnitServiceWorkflows);
                // if program unit service workflows is failed to save
                if (programUnitServiceWorkflowsResult.ResultCode != 0)
                {
                    programUnitResponse.ResultCode    = programUnitServiceWorkflowsResult.ResultCode;
                    programUnitResponse.ResultMessage = programUnitServiceWorkflowsResult.ResultMessage;
                    return(programUnitResponse);
                }

                if (!programUnit.ForceRollback.GetValueOrDefault(false))
                {
                    _unitOfWork.TransactionScopeComplete(transactionScope);
                }
            }

            return(programUnitResponse);
        }