public List <FrayteFuelSurChargeList> GetThreeMonthFuelRate(int OperationZoneId, DateTime Year) { List <FrayteFuelSurChargeList> _fuel = new List <FrayteFuelSurChargeList>(); FrayteFuelSurChargeList _fuelssur = new FrayteFuelSurChargeList(); _fuelssur.LogisticCompany = ""; var result = GetDistinctLogisticCompany(OperationZoneId); try { if (Year.Month == 1) { _fuelssur.FuelSurCharge = new List <FuelSurChargeModel>(); for (int ii = 0; ii < result.Count; ii++) { _fuelssur = new FrayteFuelSurChargeList(); _fuelssur.FuelSurCharge = new List <FuelSurChargeModel>(); var Company = result[ii].LogisticCompany; for (int i = 0; i < 3; i++) { if (i == 0) { var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == Year.Month && r.FuelMonthYear.Year == Year.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; //_fuelssur.LogisticCompany = data.LogisticCompany; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 1) { DateTime month = Year.AddMonths(-1); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 2) { DateTime month = Year.AddMonths(-2); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } } if (_fuelssur.FuelSurCharge.Count > 0) { _fuel.Add(_fuelssur); } } } else if (Year.Month == 2) { for (int ii = 0; ii < result.Count; ii++) { _fuelssur = new FrayteFuelSurChargeList(); _fuelssur.FuelSurCharge = new List <FuelSurChargeModel>(); var Company = result[ii].LogisticCompany; for (int i = 0; i < 3; i++) { if (i == 0) { var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == Year.Month && r.FuelMonthYear.Year == Year.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; //_fuelssur.LogisticCompany = data.LogisticCompany; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 1) { DateTime month = Year.AddMonths(-1); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 2) { DateTime month = Year.AddMonths(-2); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } } if (_fuelssur.FuelSurCharge.Count > 0) { _fuel.Add(_fuelssur); } } } else { for (int ii = 0; ii < result.Count; ii++) { _fuelssur = new FrayteFuelSurChargeList(); _fuelssur.FuelSurCharge = new List <FuelSurChargeModel>(); var Company = result[ii].LogisticCompany; for (int i = 0; i < 3; i++) { if (i == 0) { var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == Year.Month && r.FuelMonthYear.Year == Year.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; //_fuelssur.LogisticCompany = data.LogisticCompany; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 1) { DateTime month = Year.AddMonths(-1); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 2) { DateTime month = Year.AddMonths(-2); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } } if (_fuelssur.FuelSurCharge.Count > 0) { _fuel.Add(_fuelssur); } } } for (int a = 0; a < _fuel.Count; a++) { if (_fuel[a].FuelSurCharge == null || _fuel[a].FuelSurCharge.Count < 3) { _fuel[a].FuelSurCharge = SaveFuelCharge(OperationZoneId, Year, _fuel[a].LogisticCompany); } _fuel[a].FuelSurCharge.OrderBy(x => x.FuelMonthYear).ToList(); } return(_fuel); } catch (Exception ex) { return(null); } }
public List <FuelSurChargeModel> SaveFuelCharge(int OperationZoneId, DateTime Year, string LogisticCompany) { FrayteFuelSurChargeSaveModel FrayteSurCharge = new FrayteFuelSurChargeSaveModel(); var result = GetDistinctLogisticCompany(OperationZoneId); FrayteSurCharge.OperationZoneId = OperationZoneId; FrayteSurCharge.Year = Year; SaveFuelSurCharge(FrayteSurCharge); List <FrayteFuelSurChargeList> _fuel = new List <FrayteFuelSurChargeList>(); FrayteFuelSurChargeList _fuelssur = new FrayteFuelSurChargeList(); _fuelssur.FuelSurCharge = new List <FuelSurChargeModel>(); try { if (Year.Month == 1) { var Company = LogisticCompany; for (int i = 0; i < 3; i++) { if (i == 0) { var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == Year.Month && r.FuelMonthYear.Year == Year.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; //_fuelssur.LogisticCompany = data.LogisticCompany; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 1) { DateTime month = Year.AddMonths(-1); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 2) { DateTime month = Year.AddMonths(-2); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } } } else if (Year.Month == 2) { var Company = LogisticCompany; for (int i = 0; i < 3; i++) { if (i == 0) { var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == Year.Month && r.FuelMonthYear.Year == Year.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; //_fuelssur.LogisticCompany = data.LogisticCompany; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 1) { DateTime month = Year.AddMonths(-1); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 2) { DateTime month = Year.AddMonths(-2); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } } } else { var Company = LogisticCompany; for (int i = 0; i < 3; i++) { if (i == 0) { var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == Year.Month && r.FuelMonthYear.Year == Year.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; //_fuelssur.LogisticCompany = data.LogisticCompany; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 1) { DateTime month = Year.AddMonths(-1); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } else if (i == 2) { DateTime month = Year.AddMonths(-2); var data = dbcontext.FuelSurCharges.Where(r => r.OperationZoneId == OperationZoneId && r.FuelMonthYear.Month == month.Month && r.FuelMonthYear.Year == month.Year).FirstOrDefault(); if (data != null) { FuelSurChargeModel fuel = new FuelSurChargeModel(); fuel.FuelSurchargeId = data.FuelSurChargeId; fuel.FrayteFuelPercent = data.FrayteFuelPercent.ToString(); fuel.ExpryeFuelPercent = data.ExpryesFuelPercent.ToString(); fuel.DomesticFuelPercent = data.DomesticFuelPercent.ToString(); fuel.RoadFuelPercent = data.RoadFuelSurcharge.ToString(); fuel.FuelMonthYear = data.FuelMonthYear; _fuelssur.FuelSurCharge.Add(fuel); } } } } return(_fuelssur.FuelSurCharge.OrderBy(x => x.FuelMonthYear).ToList()); } catch (Exception ex) { return(null); } }