public Fueling Update(Fueling fueling)
        {
            _context.Update(fueling);
            _context.SaveChanges();

            return(fueling);
        }
示例#2
0
        public async Task UpdateFueling(Fueling oldFueling, Fueling newFueling)
        {
            var rec = new GasRecord {
                Id      = oldFueling.Id,
                Date    = newFueling.Date,
                Vendor  = newFueling.Vendor.Name,
                State   = newFueling.State,
                Gallons = newFueling.Gallons,
                Price   = newFueling.Price,
                Total   = newFueling.Total
            };

            var fields = new List <string>();

            fields.Add(GasRecord.DATE);
            fields.Add(GasRecord.VENDOR);
            fields.Add(GasRecord.STATE);
            if (newFueling.Gallons != oldFueling.Gallons)
            {
                fields.Add(GasRecord.GALLONS);
            }
            if (newFueling.Price != oldFueling.Price)
            {
                fields.Add(GasRecord.PRICE);
            }
            if (newFueling.Total != oldFueling.Total)
            {
                fields.Add(GasRecord.TOTAL);
            }

            rec = await GasTable.UpdateRecord(rec, fields.ToArray());
        }
示例#3
0
        public async Task AddFueling(Fueling fueling)
        {
            var rec = new GasRecord {
                Date    = fueling.Date,
                Vendor  = fueling.Vendor.Name,
                State   = fueling.State,
                Gallons = fueling.Gallons,
                Price   = fueling.Price,
                Total   = fueling.Total
            };

            var fields = new List <string>();

            fields.Add(GasRecord.DATE);
            fields.Add(GasRecord.VENDOR);
            fields.Add(GasRecord.STATE);
            if (rec.Gallons > 0)
            {
                fields.Add(GasRecord.GALLONS);
            }
            if (rec.Price > 0)
            {
                fields.Add(GasRecord.PRICE);
            }
            if (rec.Total > 0)
            {
                fields.Add(GasRecord.TOTAL);
            }

            rec = await GasTable.CreateRecord(rec, fields.ToArray());

            fueling.Id = rec.Id;
        }
示例#4
0
        public ActionResult <Fueling> Create([FromBody] FuelingDto fuelingDto)
        {
            try
            {
                var userId = _user.GetUserId();

                var fueling = new Fueling
                {
                    FuelingDateTime = fuelingDto.FuelingDateTime,
                    FuelingMileage  = fuelingDto.FuelingMileage,
                    FuelStation     = fuelingDto.FuelStation,
                    Liters          = fuelingDto.Liters,
                    Value           = fuelingDto.Value,
                    FuelType        = fuelingDto.FuelType,
                    VehicleId       = fuelingDto.VehicleId,
                    UserId          = userId
                };

                var result = _fuelingService.Create(fueling);
                return(Ok(result));
            }

            catch (ArgumentException ex)
            {
                return(NotFound("Invalid data: " + ex.Message));
            }

            catch (Exception e)
            {
                return(BadRequest("An error occured: " + e.Message));
            }
        }
示例#5
0
        private void createFueling(int idGasPump)
        {
            Random rnd          = new Random();
            var    zbiornikiDys = _context.PumpTank.Where(pt => pt.IdGasPump == idGasPump)
                                  .Select(pt => pt.IdFuelTank)
                                  .ToList();
            var zbiorniki = _context.FuelTank.Where(ft => zbiornikiDys.Contains(ft.IdFuelTank))
                            .Select(ft => ft.IdFuel)
                            .ToList();
            var     paliwa       = _context.Fuel.Where(f => zbiorniki.Contains(f.IdFuel)).ToList();
            int     rodzajPaliwa = rnd.Next(0, paliwa.Count());
            decimal ilosc        = Convert.ToDecimal(rnd.NextDouble() * Math.Abs(200 - 10) + 10);

            ilosc = Math.Round(ilosc, 2);
            Fueling randomFueling = new Fueling
            {
                Date      = DateTime.Now,
                IdFuel    = paliwa[rodzajPaliwa].IdFuel,
                IdGasPump = idGasPump,
                Quantity  = (float)ilosc
            };

            _context.Add(randomFueling);
            _context.SaveChanges();
        }
        public Fueling Create(Fueling fueling)
        {
            _context.Add(fueling);
            _context.SaveChanges();

            return(fueling);
        }
示例#7
0
        public ActionResult DeleteConfirmed(int id)
        {
            Fueling fueling = db.Fuelings.Find(id);

            db.Fuelings.Remove(fueling);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult <Fueling> > Add(Fueling fueling, CancellationToken cancellationToken)
        {
            if (fueling == null)
            {
                return(new BadRequestResult());
            }

            return(await _mediator.Send(new AddFueling(fueling.Name), cancellationToken));
        }
示例#9
0
 public ActionResult Edit([Bind(Include = "Id,Liters,Kilometers,Date")] Fueling fueling)
 {
     if (ModelState.IsValid)
     {
         db.Entry(fueling).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(PartialView(fueling));
 }
示例#10
0
        public static async Task UpdateFueling(Fueling oldFueling, Fueling newFueling)
        {
            await AppStorage.Instance.UpdateFueling(oldFueling, newFueling);

            oldFueling.Date    = newFueling.Date;
            oldFueling.Vendor  = newFueling.Vendor;
            oldFueling.State   = newFueling.State;
            oldFueling.Gallons = newFueling.Gallons;
            oldFueling.Price   = newFueling.Price;
            oldFueling.Total   = newFueling.Total;
        }
 public void Create(Fueling fueling)
 {
     try
     {
         _context.Add(fueling);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
示例#12
0
        public ActionResult Create([Bind(Include = "Id,Liters,Kilometers")] Fueling fueling)
        {
            fueling.Date = DateTime.Now.ToShortDateString();
            fueling.KilometersPerLiter = fueling.Kilometers / fueling.Liters;
            if (ModelState.IsValid)
            {
                db.Fuelings.Add(fueling);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(PartialView(fueling));
        }
示例#13
0
        public static async Task DeleteFueling(Fueling fueling)
        {
            if (fueling == null)
            {
                return;
            }

            Fuelings.Remove(fueling);

            if (!fueling.IsNew)
            {
                await AppStorage.Instance.DeleteFueling(fueling);
            }
        }
示例#14
0
        // GET: Fuelings/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Fueling fueling = db.Fuelings.Find(id);

            if (fueling == null)
            {
                return(HttpNotFound());
            }
            return(PartialView(fueling));
        }
示例#15
0
        public FuelingViewModel(Fueling fueling)
        {
            if (fueling == null)
            {
                return;
            }

            Date      = fueling.Date;
            Fuel      = fueling.Fuel;
            Mileage   = fueling.Mileage;
            Price     = fueling.Price;
            Quantity  = fueling.Quantity;
            VehicleId = fueling.VehicleId;
        }
示例#16
0
 async Task LoadFuelings(GasTable table, IList <Fueling> fuelings, string filter = null)
 {
     await table.ForEach((rec) => {
         var fueling = new Fueling {
             Id      = rec.Id,
             Date    = rec.Date,
             Vendor  = App.GetVendor(rec.Vendor),
             State   = rec.State,
             Gallons = rec.Gallons,
             Price   = rec.Price,
             Total   = rec.Total
         };
         fuelings.Add(fueling);
     },
                         filter, sortField : "Date");
 }
        public async Task <ActionResult> Update(int id, Fueling fueling, CancellationToken cancellationToken)
        {
            if (fueling == null)
            {
                return(new BadRequestResult());
            }

            try
            {
                await _mediator.Send(new UpdateFueling(id, fueling.Name), cancellationToken);

                return(new OkResult());
            }
            catch (ArgumentException ex)
            {
                return(new NotFoundObjectResult(ex.Message));
            }
        }
        public Fueling Create(Fueling fueling)
        {
            if (fueling == null)
            {
                throw new ArgumentException("Fueling cannot be null");
            }

            if (fueling.FuelingId != 0)
            {
                throw new ArgumentException("Create cannot have FuelingId");
            }

            if (_vehicleRepo.Find(fueling.VehicleId) == null)
            {
                throw new ArgumentException("Vehicle does not exists");
            }

            return(_repo.Create(fueling));
        }
示例#19
0
 public Task UpdateFueling(Fueling oldFueling, Fueling newFueling) => throw new NotImplementedException();
 public FuelingModel(Fueling fueling)
 {
     this.IsChecked = false;
     this.fueling   = fueling;
 }
示例#21
0
 public async Task DeleteFueling(Fueling fueling)
 {
     await GasTable.DeleteRecord(fueling.Id);
 }
示例#22
0
        //static ClassRef @class = new ClassRef(typeof(FuelingCell));

        public FuelingCell(Fueling fueling)
        {
            //Debug.EnableTracing(@class);
            Fueling = fueling ?? throw new ArgumentNullException(nameof(fueling));
            Fueling.PropertyChanged += (s, e) => FirePropertyChanged(e.PropertyName);
        }
示例#23
0
 public Task DeleteFueling(Fueling fueling) => throw new NotImplementedException();
 public void Delete(Fueling fueling)
 {
     _context.Remove(fueling);
     _context.SaveChanges();
 }
示例#25
0
        public static async Task NewFueling(Fueling fueling)
        {
            await AppStorage.Instance.AddFueling(fueling);

            Fuelings.Add(fueling);
        }
示例#26
0
        public void Create(TransactionCreate transactionCreate)
        {
            try
            {
                if (transactionCreate.SumOfLoyaltyCardPoints > 0 && transactionCreate.Transaction.LoyaltyCardId != null &&
                    transactionCreate.Transaction.LoyaltyCardId != 0)
                {
                    LoyaltyCard loyaltyCard = _loyaltyCardService.GetById((int)transactionCreate.Transaction.LoyaltyCardId);

                    loyaltyCard.Points -= transactionCreate.SumOfLoyaltyCardPoints;
                    _loyaltyCardService.Edit(loyaltyCard);
                }

                Invoice invoice = transactionCreate.Transaction.Invoice;
                if (invoice.NIP == 0 || invoice.InvoiceNumber == 0 || String.IsNullOrEmpty(invoice.RegistrationNumber) == true)
                {
                    transactionCreate.Transaction.Invoice = null;
                }

                Transaction transaction = transactionCreate.Transaction;
                transaction.ApplicationUserId = _accountService.GetCurrentUserId();
                transaction.ProductsLists     = new List <ProductsList>();
                transaction.Date = DateTime.Now;

                _context.Add(transaction);
                _context.SaveChanges();


                foreach (var transactionProduct in transactionCreate.TransactionProduct)
                {
                    if (transactionProduct.InTransaction)
                    {
                        var productList = _productsListService.CreateProductsLists(transaction.TransactionId, transactionProduct.ProductId, transactionProduct.Amount, transactionProduct.Price);
                        transaction.ProductsLists.Add(productList);


                        _productService.Edit(transactionProduct.ProductId, transactionProduct.Amount);

                        if (transaction.LoyaltyCardId != null && transaction.LoyaltyCardId != 0)
                        {
                            Product     product     = _productService.GetById(transactionProduct.ProductId);
                            LoyaltyCard loyaltyCard = _loyaltyCardService.GetById((int)transaction.LoyaltyCardId);
                            var         sumpoints   = transactionProduct.Amount * product.LoyaltyPointsPrice;
                            loyaltyCard.Points = (int)Math.Round((decimal)sumpoints);
                            _loyaltyCardService.Edit(loyaltyCard);
                        }
                    }
                }
                foreach (var distributor in transactionCreate.DistributorInTransaction)
                {
                    if (distributor.InTransaction)
                    {
                        Fueling fueling = new Fueling
                        {
                            TankId        = distributor.TankId,
                            DistributorId = distributor.DistributorId,
                            Date          = DateTime.Now,
                            Amount        = distributor.Counter,
                            Price         = distributor.Sum
                        };
                        _fuelingService.Create(fueling);

                        Tank tank = _tankService.GetById(distributor.TankId);
                        tank.Stock = tank.Stock - distributor.Counter;
                        _tankService.Edit(tank);
                        Product product = _productService.GetById(tank.ProductId);

                        var productList = _productsListService.CreateProductsLists(transaction.TransactionId, product.ProductId, distributor.Counter, distributor.PriceForLiter);
                        transaction.ProductsLists.Add(productList);
                        _productService.Edit(product.ProductId, distributor.Counter);

                        if (transaction.LoyaltyCardId != null && transaction.LoyaltyCardId != 0)
                        {
                            LoyaltyCard loyaltyCard = _loyaltyCardService.GetById((int)transaction.LoyaltyCardId);
                            var         sumpoints   = distributor.Counter * product.LoyaltyPointsPrice;
                            loyaltyCard.Points = (int)Math.Round((decimal)sumpoints);
                            _loyaltyCardService.Edit(loyaltyCard);
                        }
                    }
                }


                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 public Fueling Update(Fueling fueling)
 {
     return(_repo.Update(fueling));
 }