public void CreateContract(ContractEntity contractEntity) { var _contractHumanResourceNeedsList = new List <ContractHumanResourceNeeds>(); int Id; try { var contractsForThisClient = _unitOfWork.ContractInformationRepository.GetMany(c => c.ClientId == contractEntity.ContractInformation.ClientId); if (contractsForThisClient != null) { Id = contractsForThisClient.ToList().Count + 1; } else { Id = 1; } var contractId = contractEntity.ContractInformation.ClientId + "/" + Id; var _contractInformation = Mapper.Map <ContractInformation>(contractEntity.ContractInformation); var _contractBilling = Mapper.Map <ContractBilling>(contractEntity.ContractBilling); var _contractPaysheet = Mapper.Map <ContractPaysheet>(contractEntity.ContractPaySheet); var _contractInvoice = Mapper.Map <ContractInvoiceHeadingText>(contractEntity.ContractInvoiceHeadingText); foreach (var humanResourceNeeds in contractEntity.ContractHumanResourceNeeds) { if (humanResourceNeeds.MappedEmployees != null) { foreach (var mappedEmployee in humanResourceNeeds.MappedEmployees) { var _employee = _unitOfWork.EmployeePersonalInfoRepository.Get(e => e.EmpId == mappedEmployee.EmpId); _employee.ContractId = contractId; _unitOfWork.EmployeePersonalInfoRepository.Update(_employee); } } var _humanResourceNeeds = Mapper.Map <ContractHumanResourceNeeds>(humanResourceNeeds); _contractHumanResourceNeedsList.Add(_humanResourceNeeds); } _contractInformation.ContractId = contractId; _contractInformation.IsActive = true; _unitOfWork.ContractInformationRepository.Insert(_contractInformation); if (_contractBilling != null) { _contractBilling.ContractId = contractId; _unitOfWork.ContractBillingRepository.Insert(_contractBilling); } if (_contractPaysheet != null) { _contractPaysheet.ContractId = contractId; _unitOfWork.ContractPaysheetRepository.Insert(_contractPaysheet); } if (_contractInvoice != null) { _contractInvoice.ContractId = contractId; _unitOfWork.ContractInvoiceHeadingTextRepository.Insert(_contractInvoice); } foreach (var _humanResourceNeeds in _contractHumanResourceNeedsList) { _humanResourceNeeds.ContractId = contractId; _unitOfWork.ContractHumanResourceNeedsRepository.Insert(_humanResourceNeeds); } _unitOfWork.Save(); } catch (Exception ex) { throw ex; } }
public void InitializeCountriesInSystem() { UnitOfWork.Countries.AddCountries(Country.GetCountriesInSystem()); UnitOfWork.Save(); }