/// <summary> /// Save Seasonal Discount Main /// </summary> /// <param name="seasonalDiscountMain"></param> /// <returns></returns> public SeasonalDiscountMainContent SaveSeasonalDiscount(SeasonalDiscountMain seasonalDiscountMain) { SeasonalDiscountMain seasonalDiscountMainDbVersion = seasonalDiscountMainRepository.Find(seasonalDiscountMain.SeasonalDiscountMainId); TariffType tariffType = tariffTypeRepository.Find(long.Parse(seasonalDiscountMain.TariffTypeCode)); seasonalDiscountMain.TariffTypeCode = tariffType.TariffTypeCode; if (seasonalDiscountMainDbVersion == null) //Add Case { AddSeasonalDiscount(seasonalDiscountMain); } else //Update { UpdateSeasonalDiscount(seasonalDiscountMain, seasonalDiscountMainDbVersion); } seasonalDiscountMainRepository.SaveChanges(); return(new SeasonalDiscountMainContent { SeasonalDiscountMainId = seasonalDiscountMain.SeasonalDiscountMainId, Code = seasonalDiscountMain.SeasonalDiscountMainCode, Name = seasonalDiscountMain.SeasonalDiscountMainName, Description = seasonalDiscountMain.SeasonalDiscountMainDescription, StartDt = seasonalDiscountMain.StartDt, EndDt = seasonalDiscountMain.EndDt, TariffTypeId = tariffType.TariffTypeId, CompanyId = tariffType.Operation.Department.Company.CompanyId, CompanyCodeName = tariffType.Operation.Department.Company.CompanyCode + " - " + tariffType.Operation.Department.Company.CompanyName, DepartmentId = tariffType.Operation.Department.DepartmentId, TariffTypeCodeName = tariffType.TariffTypeCode + " - " + tariffType.TariffTypeName, OperationId = tariffType.OperationId, OperationCodeName = tariffType.Operation.OperationCode + " - " + tariffType.Operation.OperationName, }); }
/// <summary> /// Find Tariff Type By Id /// </summary> /// <param name="id"></param> /// <returns></returns> public TariffTypeDetailResponse FindDetailById(long id) { List <TariffType> revisionList = new List <TariffType>(); var tariffType = tariffTypeRepository.Find(id); if (tariffType != null && tariffType.RevisionNumber > 0) { var tempId = tariffType.TariffTypeId; for (int i = 0; i < tariffType.RevisionNumber; i++) { if (tempId > 0) { var tariffRevision = tariffTypeRepository.GetRevison(tempId); tempId = tariffRevision != null ? tariffRevision.TariffTypeId : 0; revisionList.Add(tariffRevision); } } } return(new TariffTypeDetailResponse { TariffType = tariffType, TariffTypeRevisions = revisionList }); }
/// <summary> /// Add Additional Driver Charge /// </summary> /// <param name="additionalDriverCharge"></param> /// <returns></returns> public AdditionalDriverChargeSearchContent SaveAdditionalDriverCharge(AdditionalDriverCharge additionalDriverCharge) { TariffType tariffType = tariffTypeRepository.Find(long.Parse(additionalDriverCharge.TariffTypeCode)); additionalDriverCharge.TariffTypeCode = tariffType.TariffTypeCode; long oldRecordId = additionalDriverCharge.AdditionalDriverChargeId; if (additionalDriverCharge.AdditionalDriverChargeId == 0) //Add Case { additionalDriverCharge.IsActive = true; additionalDriverCharge.IsDeleted = additionalDriverCharge.IsPrivate = additionalDriverCharge.IsReadOnly = false; additionalDriverCharge.RecLastUpdatedBy = additionalDriverCharge.RecCreatedBy = additionalDriverChargeRepository.LoggedInUserIdentity; additionalDriverCharge.RecCreatedDt = additionalDriverCharge.RecLastUpdatedDt = DateTime.Now; additionalDriverCharge.RowVersion = 0; additionalDriverCharge.UserDomainKey = additionalDriverChargeRepository.UserDomainKey; additionalDriverChargeRepository.Add(additionalDriverCharge); additionalDriverChargeRepository.SaveChanges(); } else //Update Case { additionalDriverCharge.IsActive = true; additionalDriverCharge.IsDeleted = additionalDriverCharge.IsPrivate = additionalDriverCharge.IsReadOnly = false; additionalDriverCharge.RecLastUpdatedBy = additionalDriverCharge.RecCreatedBy = additionalDriverChargeRepository.LoggedInUserIdentity; additionalDriverCharge.RecCreatedDt = additionalDriverCharge.RecLastUpdatedDt = DateTime.Now; additionalDriverCharge.RevisionNumber = additionalDriverCharge.RevisionNumber + 1; additionalDriverCharge.UserDomainKey = additionalDriverChargeRepository.UserDomainKey; additionalDriverCharge.AdditionalDriverChargeId = 0; additionalDriverChargeRepository.Add(additionalDriverCharge); additionalDriverChargeRepository.SaveChanges(); AdditionalDriverCharge oldAdditionalDriverChargeRecord = additionalDriverChargeRepository.Find(oldRecordId); oldAdditionalDriverChargeRecord.ChildAdditionalDriverChargeId = additionalDriverCharge.AdditionalDriverChargeId; additionalDriverChargeRepository.SaveChanges(); } return(new AdditionalDriverChargeSearchContent { AdditionalDriverChargeId = additionalDriverCharge.AdditionalDriverChargeId, TariffTypeCode = tariffType.TariffTypeCode, TariffTypeCodeName = tariffType.TariffTypeCode + " - " + tariffType.TariffTypeName, AdditionalDriverChargeRate = additionalDriverCharge.AdditionalDriverChargeRate, StartDt = additionalDriverCharge.StartDt, CompanyCodeName = tariffType.Operation.Department.Company.CompanyCode + " - " + tariffType.Operation.Department.Company.CompanyName, OperationCodeName = tariffType.Operation.OperationCode + " - " + tariffType.Operation.OperationName, RevisionNumber = additionalDriverCharge.RevisionNumber, CompanyId = tariffType.Operation.Department.Company.CompanyId, DepartmentId = tariffType.Operation.Department.DepartmentId, OperationId = tariffType.Operation.OperationId, TariffTypeId = tariffType.TariffTypeId, }); }
/// <summary> /// Save Chauffer Charge Main /// </summary> /// <param name="chaufferChargeMain"></param> /// <returns></returns> public ChaufferChargeMainContent SaveChaufferCharge(ChaufferChargeMain chaufferChargeMain) { ChaufferChargeMain chaufferChargeMainDbVersion = chaufferChargeMainRepository.Find(chaufferChargeMain.ChaufferChargeMainId); TariffType tariffType = tariffTypeRepository.Find(long.Parse(chaufferChargeMain.TariffTypeCode)); chaufferChargeMain.TariffTypeCode = tariffType.TariffTypeCode; if (chaufferChargeMainDbVersion == null) //Add Case { //Validate Chauffer Charge Main ChaufferChargeValidation(chaufferChargeMain, true); chaufferChargeMain.IsActive = true; chaufferChargeMain.IsDeleted = chaufferChargeMain.IsPrivate = chaufferChargeMain.IsReadOnly = false; chaufferChargeMain.RecLastUpdatedBy = chaufferChargeMain.RecCreatedBy = chaufferChargeMainRepository.LoggedInUserIdentity; chaufferChargeMain.RecCreatedDt = chaufferChargeMain.RecLastUpdatedDt = DateTime.Now; chaufferChargeMain.RowVersion = 0; chaufferChargeMain.UserDomainKey = chaufferChargeMainRepository.UserDomainKey; if (chaufferChargeMain.ChaufferCharges != null) { foreach (var item in chaufferChargeMain.ChaufferCharges) { item.IsActive = true; item.IsDeleted = item.IsPrivate = item.IsReadOnly = false; item.RecLastUpdatedBy = item.RecCreatedBy = chaufferChargeMainRepository.LoggedInUserIdentity; item.RecCreatedDt = item.RecLastUpdatedDt = DateTime.Now; item.RowVersion = 0; item.RevisionNumber = 0; item.UserDomainKey = chaufferChargeMainRepository.UserDomainKey; } } chaufferChargeMainRepository.Add(chaufferChargeMain); } else //Update { chaufferChargeMainDbVersion.RecLastUpdatedBy = chaufferChargeMainRepository.LoggedInUserIdentity; chaufferChargeMainDbVersion.RecLastUpdatedDt = DateTime.Now; chaufferChargeMainDbVersion.StartDt = chaufferChargeMain.StartDt; if (chaufferChargeMain.ChaufferCharges != null) { //Validate Chauffer Charge Main ChaufferChargeValidation(chaufferChargeMain, false); foreach (var item in chaufferChargeMain.ChaufferCharges) { if ( chaufferChargeMainDbVersion.ChaufferCharges.All( x => x.ChaufferChargeId != item.ChaufferChargeId || item.ChaufferChargeId == 0)) { item.IsActive = true; item.IsDeleted = item.IsPrivate = item.IsReadOnly = false; item.RecLastUpdatedBy = item.RecCreatedBy = chaufferChargeMainRepository.LoggedInUserIdentity; item.RecCreatedDt = item.RecLastUpdatedDt = DateTime.Now; item.RowVersion = 0; item.RevisionNumber = 0; item.UserDomainKey = chaufferChargeMainRepository.UserDomainKey; chaufferChargeMainDbVersion.ChaufferCharges.Add(item); } else { if (chaufferChargeMainDbVersion.ChaufferCharges.Any( x => x.ChaufferChargeId == item.ChaufferChargeId)) { ChaufferCharge chaufferChargeDbVesion = chaufferChargeMainDbVersion.ChaufferCharges.First( x => x.ChaufferChargeId == item.ChaufferChargeId); if (chaufferChargeDbVesion.DesigGradeId != item.DesigGradeId || chaufferChargeDbVesion.StartDt != item.StartDt // ReSharper disable once CompareOfFloatsByEqualityOperator || chaufferChargeDbVesion.ChaufferChargeRate != item.ChaufferChargeRate) { item.IsActive = true; item.IsDeleted = item.IsPrivate = item.IsReadOnly = false; item.RecLastUpdatedBy = item.RecCreatedBy = chaufferChargeMainRepository.LoggedInUserIdentity; item.RecCreatedDt = item.RecLastUpdatedDt = DateTime.Now; item.RowVersion = 0; item.ChaufferChargeMainId = chaufferChargeMain.ChaufferChargeMainId; item.RevisionNumber = chaufferChargeDbVesion.RevisionNumber + 1; item.ChaufferChargeId = 0; item.UserDomainKey = chaufferChargeMainRepository.UserDomainKey; chaufferChargeRepository.Add(item); chaufferChargeRepository.SaveChanges(); chaufferChargeDbVesion.ChildChaufferChargeId = item.ChaufferChargeMainId; } } } } } } chaufferChargeMainRepository.SaveChanges(); return(new ChaufferChargeMainContent { ChaufferChargeMainId = chaufferChargeMain.ChaufferChargeMainId, Code = chaufferChargeMain.ChaufferChargeMainCode, Name = chaufferChargeMain.ChaufferChargeMainName, Description = chaufferChargeMain.ChaufferChargeMainDescription, StartDate = chaufferChargeMain.StartDt, TariffTypeId = tariffType.TariffTypeId, CompanyId = tariffType.Operation.Department.Company.CompanyId, CompanyCodeName = tariffType.Operation.Department.Company.CompanyCode + " - " + tariffType.Operation.Department.Company.CompanyName, DepartmentId = tariffType.Operation.Department.DepartmentId, TariffTypeCodeName = tariffType.TariffTypeCode + " - " + tariffType.TariffTypeName, OperationId = tariffType.OperationId, OperationCodeName = tariffType.Operation.OperationCode + " - " + tariffType.Operation.OperationName, }); }
/// <summary> /// Add/Edit Service Rate /// </summary> /// <param name="serviceRtMain"></param> /// <returns></returns> public ServiceRtMainContent SaveServiceRate(ServiceRtMain serviceRtMain) { TariffType tariffType = tariffTypeRepository.Find(long.Parse(serviceRtMain.TariffTypeCode)); serviceRtMain.TariffTypeCode = tariffType.TariffTypeCode; ServiceRtMain serviceRtMainDbVersion = serviceRtMainRepository.Find(serviceRtMain.ServiceRtMainId); #region Add if (serviceRtMainDbVersion == null) { ValidateServiceRt(serviceRtMain, true); serviceRtMain.UserDomainKey = serviceRtMainRepository.UserDomainKey; serviceRtMain.IsActive = true; serviceRtMain.IsDeleted = false; serviceRtMain.IsPrivate = false; serviceRtMain.IsReadOnly = false; serviceRtMain.RecCreatedDt = DateTime.Now; serviceRtMain.RecLastUpdatedDt = DateTime.Now; serviceRtMain.RecCreatedBy = serviceRtMainRepository.LoggedInUserIdentity; serviceRtMain.RecLastUpdatedBy = serviceRtMainRepository.LoggedInUserIdentity; serviceRtMain.RowVersion = 0; //set child (Service Rate in Service Rate Main) properties #region Service Rate in Service Rate Main if (serviceRtMain.ServiceRts != null) { // set properties foreach (ServiceRt item in serviceRtMain.ServiceRts) { item.IsActive = true; item.IsDeleted = false; item.IsPrivate = false; item.IsReadOnly = false; item.RecCreatedDt = DateTime.Now; item.RecLastUpdatedDt = DateTime.Now; item.RecCreatedBy = serviceRtMainRepository.LoggedInUserIdentity; item.RecLastUpdatedBy = serviceRtMainRepository.LoggedInUserIdentity; item.UserDomainKey = serviceRtMainRepository.UserDomainKey; } } #endregion serviceRtMainRepository.Add(serviceRtMain); serviceRtMainRepository.SaveChanges(); } #endregion #region Edit else { ValidateServiceRt(serviceRtMain, false); serviceRtMainDbVersion.RecLastUpdatedDt = DateTime.Now; serviceRtMainDbVersion.RecLastUpdatedBy = serviceRtMainRepository.LoggedInUserIdentity; serviceRtMainDbVersion.StartDt = serviceRtMain.StartDt; //add new Insurance Rate items if (serviceRtMain.ServiceRts != null) { foreach (ServiceRt serviceRt in serviceRtMain.ServiceRts) { if ( serviceRtMainDbVersion.ServiceRts.All( x => x.ServiceRtId != serviceRt.ServiceRtId) || serviceRt.ServiceRtId == 0) { // set properties serviceRt.IsActive = true; serviceRt.IsDeleted = false; serviceRt.IsPrivate = false; serviceRt.IsReadOnly = false; serviceRt.RecCreatedDt = DateTime.Now; serviceRt.RecLastUpdatedDt = DateTime.Now; serviceRt.RecCreatedBy = serviceRtMainRepository.LoggedInUserIdentity; serviceRt.RecLastUpdatedBy = serviceRtMainRepository.LoggedInUserIdentity; serviceRt.UserDomainKey = serviceRtMainRepository.UserDomainKey; serviceRt.ServiceRtMainId = serviceRtMain.ServiceRtMainId; serviceRtMainDbVersion.ServiceRts.Add(serviceRt); } else { serviceRt.IsActive = true; serviceRt.IsDeleted = false; serviceRt.IsPrivate = false; serviceRt.IsReadOnly = false; serviceRt.RecCreatedDt = DateTime.Now; serviceRt.RecLastUpdatedDt = DateTime.Now; serviceRt.RecCreatedBy = serviceRtMainRepository.LoggedInUserIdentity; serviceRt.RecLastUpdatedBy = serviceRtMainRepository.LoggedInUserIdentity; serviceRt.UserDomainKey = serviceRtMainRepository.UserDomainKey; serviceRt.ServiceRtMainId = serviceRtMain.ServiceRtMainId; long oldRecordId = serviceRt.ServiceRtId; serviceRt.ServiceRtId = 0; serviceRt.RevisionNumber = serviceRt.RevisionNumber + 1; serviceRtRepository.Add(serviceRt); serviceRtRepository.SaveChanges(); ServiceRt oldServiceRt = serviceRtRepository.Find(oldRecordId); oldServiceRt.ChildServiceRtId = serviceRt.ServiceRtId; serviceRtRepository.SaveChanges(); } } } } serviceRtMainRepository.SaveChanges(); #endregion return(new ServiceRtMainContent { TariffTypeCodeName = tariffType.TariffTypeCode + " - " + tariffType.TariffTypeName, TariffTypeId = tariffType.TariffTypeId, OperationId = tariffType.Operation.OperationId, OperationCodeName = tariffType.Operation.OperationCode + " - " + tariffType.Operation.OperationName, ServiceRtMainId = serviceRtMain.ServiceRtMainId, ServiceRtMainCode = serviceRtMain.ServiceRtMainCode, ServiceRtMainName = serviceRtMain.ServiceRtMainName, ServiceRtMainDescription = serviceRtMain.ServiceRtMainDescription, StartDt = serviceRtMain.StartDt }); }
/// <summary> /// Add Tariff Rate /// </summary> /// <param name="standardRateMain"></param> /// <returns></returns> public TariffRateContent SaveTariffRate(StandardRateMain standardRateMain) { TariffType tariffType = tariffTypeRepository.Find(long.Parse(standardRateMain.TariffTypeCode)); standardRateMain.TariffTypeCode = tariffType.TariffTypeCode; #region Add if (standardRateMain.StandardRtMainId == 0) { StandardRateValidation(standardRateMain, true); standardRateMain.UserDomainKey = standardRateMainRepository.UserDomainKey; standardRateMain.IsActive = true; standardRateMain.IsDeleted = false; standardRateMain.IsPrivate = false; standardRateMain.IsReadOnly = false; standardRateMain.RecCreatedDt = DateTime.Now; standardRateMain.RecLastUpdatedDt = DateTime.Now; standardRateMain.RecCreatedBy = standardRateMainRepository.LoggedInUserIdentity; standardRateMain.RecLastUpdatedBy = standardRateMainRepository.LoggedInUserIdentity; standardRateMain.RowVersion = 0; //set child (Standard Rate in Standard Rate Main) properties #region Standard Rate in Standard Rate Main if (standardRateMain.StandardRates != null) { // set properties foreach (StandardRate item in standardRateMain.StandardRates) { item.IsActive = true; item.IsDeleted = false; item.IsPrivate = false; item.IsReadOnly = false; item.RecCreatedDt = DateTime.Now; item.RecLastUpdatedDt = DateTime.Now; item.RecCreatedBy = standardRateMainRepository.LoggedInUserIdentity; item.RecLastUpdatedBy = standardRateMainRepository.LoggedInUserIdentity; item.UserDomainKey = standardRateMainRepository.UserDomainKey; } } #endregion standardRateMainRepository.Add(standardRateMain); standardRateMainRepository.SaveChanges(); } #endregion #region Edit else { StandardRateValidation(standardRateMain, false); if (standardRateMain.StandardRates != null) { foreach (StandardRate standardRate in standardRateMain.StandardRates) { standardRate.IsActive = true; standardRate.IsDeleted = false; standardRate.IsPrivate = false; standardRate.IsReadOnly = false; standardRate.RecCreatedDt = DateTime.Now; standardRate.RecLastUpdatedDt = DateTime.Now; standardRate.RecCreatedBy = standardRateMainRepository.LoggedInUserIdentity; standardRate.RecLastUpdatedBy = standardRateMainRepository.LoggedInUserIdentity; standardRate.UserDomainKey = standardRateMainRepository.UserDomainKey; standardRate.StandardRtMainId = standardRateMain.StandardRtMainId; if (standardRate.StandardRtId > 0) { long oldRecordId = standardRate.StandardRtId; standardRate.StandardRtId = 0; standardRate.RevisionNumber = standardRate.RevisionNumber + 1; standardRateRepository.Add(standardRate); standardRateRepository.SaveChanges(); StandardRate oldStandardRate = standardRateRepository.Find(oldRecordId); oldStandardRate.ChildStandardRtId = standardRate.StandardRtId; standardRateRepository.SaveChanges(); } else { standardRateRepository.Add(standardRate); standardRateRepository.SaveChanges(); } } } } #endregion return(new TariffRateContent { StandardRtMainId = standardRateMain.StandardRtMainId, StandardRtMainCode = standardRateMain.StandardRtMainCode, StandardRtMainName = standardRateMain.StandardRtMainName, StandardRtMainDescription = standardRateMain.StandardRtMainDescription, StartDt = standardRateMain.StartDt, EndDt = standardRateMain.EndDt, TariffTypeId = tariffType.TariffTypeId, TariffTypeCodeName = tariffType.TariffTypeCode + " - " + tariffType.TariffTypeName, OperationId = tariffType.OperationId, OperationCodeName = tariffType.Operation.OperationCode + " - " + tariffType.Operation.OperationName, }); }