private static void CreateFuelPriceListFrom(string tmpResult, IList <FuelPriceModel> retval)
        {
            //parse the temporary result through a json tokenizer to allow us to pick the section we need
            var jsonData = JToken.Parse(tmpResult) as dynamic;

            //pick the series section
            var seriesData = jsonData.series;

            //pick the only item in the series array
            var seriesItem = seriesData[0];

            //pick the data array in the series object
            var dataArray = seriesItem.data;

            //builds our model for each price-date array item and add that to our model list
            foreach (var item in dataArray)
            {
                var date  = item[0].ToString();
                var price = item[1].ToString();

                var priceDecimal = Convert.ToDecimal(price);

                var fuelPrice = new FuelPriceModel
                {
                    Date  = date,
                    Price = priceDecimal
                };

                retval.Add(fuelPrice);
            }
        }
Ejemplo n.º 2
0
        public FuelPriceModel SaveFuelPrice(FuelPriceModel fuelPrice)
        {
            FuelPriceModel savedFuelPrice = null;

            if (fuelPrice != null)
            {
                if (fuelPrice.Id == Guid.Empty)
                {
                    fuelPrice.Id = Guid.NewGuid();
                }

                //this checks if the data already exists
                var existingFuelPrice = _fuelPriceDbContext.FuelPrices.Any(f => f.Date == fuelPrice.Date);

                if (!existingFuelPrice)
                {
                    _fuelPriceDbContext.FuelPrices.Add(fuelPrice);

                    var results = _fuelPriceDbContext.SaveChanges();

                    if (results > 0)
                    {
                        savedFuelPrice = fuelPrice;
                    }
                }
            }

            return(savedFuelPrice);
        }
        public HttpResponseMessage SetBasePrice([FromBody] FuelPriceModel model)
        {
            ErrorMessage errorMessage;

            var fuelPrice = new FuelPrice
            {
                CashPrice              = model.CashPrice,
                CreditPrice            = model.CreditPrice,
                Grade                  = model.Grade,
                TaxExemptedCashPrice   = model.TaxExemptedCashPrice,
                TaxExemptedCreditPrice = model.TaxExemptedCreditPrice,
                GradeId                = model.GradeId,
                LevelId                = model.LevelId,
                TierId                 = model.TierId,
                Level                  = model.Level,
                Tier = model.Tier
            };

            var updatedPrice = _fuelPumpManager.SetBasePrice(ref fuelPrice, out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage?.MessageStyle.Message) && errorMessage.StatusCode != HttpStatusCode.OK)
            {
                return(Request.CreateResponse(errorMessage.StatusCode,
                                              new ErrorResponse
                {
                    Error = errorMessage.MessageStyle,
                }));
            }

            if (updatedPrice != null)
            {
                var response = new FuelPriceModel
                {
                    CashPrice              = updatedPrice.CashPrice,
                    LevelId                = updatedPrice.LevelId,
                    GradeId                = updatedPrice.GradeId,
                    CreditPrice            = updatedPrice.CreditPrice,
                    Grade                  = updatedPrice.Grade,
                    Level                  = updatedPrice.Level,
                    TaxExemptedCashPrice   = updatedPrice.TaxExemptedCashPrice,
                    TaxExemptedCreditPrice = updatedPrice.TaxExemptedCreditPrice,
                    Tier   = updatedPrice.Tier,
                    TierId = updatedPrice.TierId
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse
            {
                Error = new MessageStyle
                {
                    Message = Resource.InvalidRequest,
                    MessageType = MessageType.OkOnly
                }
            }));
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> SetDailyUpdateFuelPrice([FromBody] FuelPriceModel obj)
 {
     if (ModelState.IsValid)
     {
         return(Ok(await _pumpService.SetDailyUpdateFuelPrice(obj)));
     }
     else
     {
         return(UnprocessableEntity());
     }
 }
Ejemplo n.º 5
0
        private void SetPrice(FuelPriceModel fuelPrice)
        {
            if (fuelPrice == null)
            {
                return;
            }

            try
            {
                Convert.ToDecimal(fuelPrice.CashPrice, CultureInfo.InvariantCulture);
                Convert.ToDecimal(fuelPrice.CreditPrice, CultureInfo.InvariantCulture);
                if (FuelPrices.IsTaxExemptionVisible)
                {
                    if (fuelPrice.TaxExemptedCashPrice != "N/A")
                    {
                        Convert.ToDecimal(fuelPrice.TaxExemptedCashPrice, CultureInfo.InvariantCulture);
                    }
                    if (fuelPrice.TaxExemptedCreditPrice != "N/A")
                    {
                        Convert.ToDecimal(fuelPrice.TaxExemptedCreditPrice, CultureInfo.InvariantCulture);
                    }
                }
            }
            catch (Exception ex)
            {
                // Eating exception when prices are not in correct format
                return;
            }

            PerformAction(async() =>
            {
                if (IsGrouped)
                {
                    var reponse       = await _fuelPumpBusinessLogic.SetGroupBasePrice(FuelPrices.ToEntity().Prices, fuelPrice.Row);
                    FuelPrices.Prices = reponse.ToModel().Prices;
                    FuelPrices.Report = reponse?.Report.ReportContent;
                }
                else
                {
                    var reponse = await _fuelPumpBusinessLogic.SetBasePrice(fuelPrice.ToEntity());
                    var model   = reponse?.ToModel();
                    var price   = FuelPrices.Prices.FirstOrDefault(x => x.GradeId == model?.GradeId &&
                                                                   x.TierId == model?.TierId && x.LevelId == model?.LevelId);
                    var index = FuelPrices.Prices.IndexOf(price);
                    if (index != -1)
                    {
                        FuelPrices.Prices[index] = model;
                    }
                }
            });
        }
Ejemplo n.º 6
0
        public async Task <int> SetDailyUpdateFuelPrice(FuelPriceModel fuelPrice)
        {
            try
            {
                var sp     = StringGenerator.GetProcedureParameter(fuelPrice, SPConstants.spSetDailyUpdateFuelPrice);
                var result = await _connectContext.spSetDailyUpdateFuelPrice
                             .FromSqlRaw(sp, fuelPrice.PRD_Id, fuelPrice.PRD_UID_UserId, fuelPrice.PRD_Mrp)
                             .ToListAsync();

                return(result.FirstOrDefault().Result);
            }
            catch (Exception ex)
            {
                _ILogger.Log(LogLevel.Critical, "Exception while calling SpRegistrationTeam ", ex);
                return(0);
            }
        }
Ejemplo n.º 7
0
        public static Price ToEntity(this FuelPriceModel model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new Price
            {
                Row = model.Row,
                CashPrice = model.CashPrice,
                CreditPrice = model.CreditPrice,
                Grade = model.Grade,
                GradeId = model.GradeId,
                Level = model.Level,
                LevelId = model.LevelId,
                TaxExemptedCashPrice = model.TaxExemptedCashPrice,
                TaxExemptedCreditPrice = model.TaxExemptedCreditPrice,
                Tier = model.Tier,
                TierId = model.TierId
            });
        }
Ejemplo n.º 8
0
        public ActionResult GetFuelPrice(FuelPriceModel model)
        {
            var data = BusinessAccessLayer.BALFuel.BALGetFuelPrice(model.pumpid, model.fuelid);

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        public FuelPriceModel SaveFuelPrice(FuelPriceModel fuelPrice)
        {
            var fuelPriceModel = _fuelPriceRepository.SaveFuelPrice(fuelPrice);

            return(fuelPriceModel);
        }