public Response <DivisionDetailsModel> SaveDivision(DivisionDetailsModel division) { var divisionResponse = new Response <DivisionDetailsModel>(); using (var transactionScope = _unitOfWork.BeginTransactionScope()) { var divisionResult = new Response <OrganizationDetailsModel>(); if (division.Division.DetailID > 0) { divisionResult = _organizationStructureDataProvider.UpdateOrganizationStructure(division.Division); } else { division.Division.DataKey = OrganizationType.Division.ToString(); divisionResult = _organizationStructureDataProvider.AddOrganizationStructure(division.Division); division.Division.DetailID = divisionResult.ID; } // if division is failed to save if (divisionResult.ResultCode != 0) { divisionResponse.ResultCode = divisionResult.ResultCode; divisionResponse.ResultMessage = divisionResult.ResultMessage; return(divisionResponse); } if (!division.ForceRollback.GetValueOrDefault(false)) { _unitOfWork.TransactionScopeComplete(transactionScope); } } return(divisionResponse); }
/// <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); }
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); }
/// <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); }