Ejemplo n.º 1
0
        public Response <CompanyDetailsModel> SaveCompany(CompanyDetailsModel company)
        {
            var companyResponse = new Response <CompanyDetailsModel>();

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

                company.Addresses.ForEach(item =>
                {
                    item.DetailID = company.Company.DetailID;
                });
                company.CompanyIdentifiers.ForEach(item =>
                {
                    item.DetailID = company.Company.DetailID;
                });

                // if company is failed to save
                if (companyResult.ResultCode != 0)
                {
                    companyResponse.ResultCode    = companyResult.ResultCode;
                    companyResponse.ResultMessage = companyResult.ResultMessage;
                    return(companyResponse);
                }

                var companyIdentifiersResult = _organizationIdentifiersDataProvider.SaveOrganizationIdentifiers(company.CompanyIdentifiers);
                // if organization identifier is failed to save
                if (companyIdentifiersResult.ResultCode != 0)
                {
                    companyResponse.ResultCode    = companyIdentifiersResult.ResultCode;
                    companyResponse.ResultMessage = companyIdentifiersResult.ResultMessage;
                    return(companyResponse);
                }

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

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

            return(companyResponse);
        }
Ejemplo n.º 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);
        }