public IEnumerable <ChaufferCharge> Get([FromUri] ChaufferChargeMain chaufferChargeMain) { if (!ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } return(chaufferChargeService.GetChaufferChargesByChaufferChargeMainId(chaufferChargeMain.ChaufferChargeMainId).Select(chaufferChrg => chaufferChrg.CreateFrom()).ToList()); }
/// <summary> /// Delete a Chauffer Charge /// </summary> public void Delete(ChaufferChargeMain chaufferChargeMain) { if (chaufferChargeMain == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } chaufferChargeService.DeleteAdditionalCharge(chaufferChargeService.FindById(chaufferChargeMain.ChaufferChargeMainId)); }
public ChaufferChargeMainContent Post(ChaufferChargeMain chaufferChargeMain) { if (chaufferChargeMain == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } ChaufferChargeMainContent reponse = chaufferChargeService.SaveChaufferCharge(chaufferChargeMain.CreateFrom()) .CreateFrom(); return(reponse); }
/// <summary> /// hauffer Charge Validation /// </summary> /// <param name="chaufferChargeMain"></param> /// <param name="flag"></param> private void ChaufferChargeValidation(ChaufferChargeMain chaufferChargeMain, bool flag) { // ReSharper disable once TooWideLocalVariableScope DateTime chaufferChargeMainStDate, chaufferChargeStDate; chaufferChargeMainStDate = Convert.ToDateTime(chaufferChargeMain.StartDt); if (flag) { if (chaufferChargeMainStDate < DateTime.Now.Date) { throw new CaresException(string.Format(CultureInfo.InvariantCulture, Resources.Tariff.ChaufferCharge.InvalidStartDate)); } if (chaufferChargeMainRepository.LoadChaufferChargeMainExist(chaufferChargeMain.TariffTypeCode)) { throw new CaresException(string.Format(CultureInfo.InvariantCulture, Resources.Tariff.ChaufferCharge.ChaufferChargeByTariffExist)); } } if (chaufferChargeMain.ChaufferCharges != null) { foreach (var item in chaufferChargeMain.ChaufferCharges) { chaufferChargeStDate = Convert.ToDateTime(item.StartDt); if (item.ChaufferChargeId == 0) { if (chaufferChargeStDate < DateTime.Now.Date) { throw new CaresException(string.Format(CultureInfo.InvariantCulture, Resources.Tariff.ChaufferCharge.ChaufferChargeInvalidEffectiveDates)); } if (chaufferChargeStDate < chaufferChargeMainStDate) { throw new CaresException(string.Format(CultureInfo.InvariantCulture, Resources.Tariff.ChaufferCharge.ChaufferChargeInvalidRangeEffectiveDate)); } } } } }
/// <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> /// Delete Chauffer Charge /// </summary> /// <param name="chaufferChargeMain"></param> public void DeleteAdditionalCharge(ChaufferChargeMain chaufferChargeMain) { chaufferChargeMainRepository.Delete(chaufferChargeMain); chaufferChargeMainRepository.SaveChanges(); }