Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("id,number,pole,available_bikes,code_insee,lng,availability,availabilitycode,etat,startdate,langue,bike_stands,last_update,available_bike_stands,gid,titre,status,commune,description,nature,bonus,address2,address,lat,last_update_fme,enddate,name,banking,nmarrond")] Stations stations)
        {
            if (ModelState.IsValid)
            {
                _context.Add(stations);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stations));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Developer> > Post(Developer developer)
        {
            if (developer == null)
            {
                return(BadRequest());
            }

            db.Developers.Add(developer);
            await db.SaveChangesAsync();

            return(Ok(developer));
        }
        public async Task <ActionResult <Post> > Post(Post post)
        {
            if (post == null)
            {
                return(BadRequest());
            }

            db.Posts.Add(post);
            await db.SaveChangesAsync();

            return(Ok(post));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Game> > Post(Game game)
        {
            if (game == null)
            {
                return(BadRequest());
            }

            db.Games.Add(game);
            await db.SaveChangesAsync();

            return(Ok(game));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <Country> > Post(Country country)
        {
            if (country == null)
            {
                return(BadRequest());
            }

            db.Countries.Add(country);
            await db.SaveChangesAsync();

            return(Ok(country));
        }
        public async Task <ActionResult <Platform> > Post(Platform platform)
        {
            if (platform == null)
            {
                return(BadRequest());
            }

            db.Platforms.Add(platform);
            await db.SaveChangesAsync();

            return(Ok(platform));
        }
Ejemplo n.º 7
0
        public async Task <bool> Post(FuelPrelevement myPrelevement)
        {
            using (var db = new StationContext())
            {
                if (myPrelevement.PrelevementGuid == Guid.Empty)
                {
                    myPrelevement.PrelevementGuid = Guid.NewGuid();
                }

                var citerneGuid = db.Pompes.Find(myPrelevement.PompeGuid).CiterneGuid;
                if (citerneGuid != null)
                {
                    myPrelevement.CiterneGuid = (Guid)citerneGuid;
                }
                else
                {
                    throw new ArgumentException("CAN_NOT_FIND_CITERNE");
                }

                myPrelevement.CurrentPrice = (await FuelManager.GetFuelCurrentPrice(db.Pompes.Find(myPrelevement.PompeGuid).Citerne.FuelGuid));

                myPrelevement.DateAdded    = DateTime.Now;
                myPrelevement.LastEditDate = DateTime.Now;

                db.Set <FuelPrelevement>().Add(myPrelevement);
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 8
0
        public async Task <bool> Post(Fuel myFuel)
        {
            using (var db = new StationContext())
            {
                if (myFuel.FuelGuid == Guid.Empty)
                {
                    myFuel.FuelGuid = Guid.NewGuid();
                }

                myFuel.DateAdded    = DateTime.Now;
                myFuel.LastEditDate = DateTime.Now;

                db.Fuels.Add(myFuel);
                if (!myFuel.Prices.Any())
                {
                    return(db.SaveChanges() > 0);
                }

                if (myFuel.Prices.First().PriceGuid == Guid.Empty)
                {
                    myFuel.Prices.First().PriceGuid = Guid.NewGuid();
                }
                myFuel.Prices.First().ProductGuid = myFuel.FuelGuid;
                myFuel.Prices.First().FromDate    = DateTime.Now;
                db.Set <Price>().Add(myFuel.Prices.First());

                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 9
0
        public async Task <bool> Post(Purchase myPurchase)
        {
            using (var db = new StationContext())
            {
                switch (myPurchase.ProductType)
                {
                case ProductType.Fuel:
                    myPurchase.Sum         = myPurchase.Quantity * (await FuelManager.GetFuelCurrentPrice(myPurchase.ProductGuid));
                    myPurchase.Description = $"{myPurchase.Quantity.ToString("0.##\\ L")} {(await db.Fuels.FindAsync(myPurchase.ProductGuid)).Libel}";
                    break;

                case ProductType.Oil:
                    myPurchase.Sum         = myPurchase.Quantity * (await OilManager.StaticGet(myPurchase.ProductGuid)).CurrentUnitPrice;
                    myPurchase.Description = $"{"Bidon".ToQuantity((int) myPurchase.Quantity)} {(await db.Oils.FindAsync(myPurchase.ProductGuid)).Libel}";
                    break;
                }

                if (myPurchase.PurchaseGuid == Guid.Empty)
                {
                    myPurchase.PurchaseGuid = Guid.NewGuid();
                }
                if (myPurchase.PurchaseState == PurchaseState.Paid)
                {
                    myPurchase.PurchaseDate = DateTime.Now;
                }
                myPurchase.DateAdded    = myPurchase.PurchaseDate;
                myPurchase.LastEditDate = DateTime.Now;

                db.Purchases.Add(myPurchase);
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 10
0
        public async Task <bool> Put(Fuel myFuel)
        {
            using (var db = new StationContext())
            {
                myFuel.LastEditDate = DateTime.Now;

                db.Fuels.Attach(myFuel);
                db.Entry(myFuel).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 11
0
        public async Task <bool> Put(Company myCompany)
        {
            bool result;

            using (var db = new StationContext())
            {
                myCompany.LastEditDate = DateTime.Now;

                db.Companies.Attach(myCompany);
                db.Entry(myCompany).State = EntityState.Modified;
                result = await db.SaveChangesAsync() > 0;
            }
            return(result);
        }
Ejemplo n.º 12
0
        public async Task <bool> Post(FuelDelivery fuelDelivery)
        {
            using (var db = new StationContext())
            {
                if (fuelDelivery.FuelDeliveryGuid == Guid.Empty)
                {
                    fuelDelivery.FuelDeliveryGuid = Guid.NewGuid();
                }

                fuelDelivery.DateAdded    = DateTime.Now;
                fuelDelivery.LastEditDate = DateTime.Now;

                db.FuelDeliverys.Add(fuelDelivery);
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 13
0
        public async Task <bool> Post(Citerne myCiternes)
        {
            using (var db = new StationContext())
            {
                if (myCiternes.CiterneGuid == Guid.Empty)
                {
                    myCiternes.CiterneGuid = Guid.NewGuid();
                }

                myCiternes.DateAdded    = DateTime.Now;
                myCiternes.LastEditDate = DateTime.Now;

                db.Citernes.Add(myCiternes);
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 14
0
        public async Task <bool> ChangePrice(Guid oilGuid, double newPrice)
        {
            using (var db = new StationContext())
            {
                var myOil = db.Oils.Find(oilGuid);

                myOil.CurrentUnitPrice = newPrice;
                myOil.LastPriceUpdate  = DateTime.Now;

                myOil.LastEditDate = DateTime.Now;

                db.Oils.Attach(myOil);
                db.Entry(myOil).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 15
0
        public async Task <bool> DeletePurchase(Guid purchaseGuid)
        {
            using (var db = new StationContext())
            {
                var myPurchase = await db.Purchases.FindAsync(purchaseGuid);

                if (myPurchase == null)
                {
                    throw new InvalidOperationException("PURCHASE_NOT_FOUND");
                }

                myPurchase.LastEditDate = DateTime.Now;
                myPurchase.IsDeleted    = true;

                db.Purchases.Attach(myPurchase);
                db.Entry(myPurchase).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 16
0
        public async Task <bool> Delete(Guid fuelGuid)
        {
            using (var db = new StationContext())
            {
                var myObject = await db.Fuels.FindAsync(fuelGuid);

                if (myObject == null)
                {
                    throw new InvalidOperationException("FUEL_NOT_FOUND");
                }

                myObject.LastEditDate = DateTime.Now;
                myObject.IsDeleted    = true;

                db.Fuels.Attach(myObject);
                db.Entry(myObject).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 17
0
        public async Task <bool> DeletePrelevement(Guid oilPrelevementGuid)
        {
            using (var db = new StationContext())
            {
                var myObject = await db.OilPrelevements.FindAsync(oilPrelevementGuid);

                if (myObject == null)
                {
                    throw new InvalidOperationException("PRELEVEMENT_NOT_FOUND");
                }

                myObject.LastEditDate = DateTime.Now;
                myObject.DeleteDate   = DateTime.Now;
                myObject.IsDeleted    = true;

                db.OilPrelevements.Attach(myObject);
                db.Entry(myObject).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 18
0
        public async Task <bool> AddStaff(Staff myStaff)
        {
            using (var db = new StationContext())
            {
                if (myStaff.StaffGuid == Guid.Empty)
                {
                    myStaff.StaffGuid = Guid.NewGuid();
                }
                if (myStaff.Person.PersonGuid == Guid.Empty)
                {
                    myStaff.Person.PersonGuid = Guid.NewGuid();
                }

                await myStaff.Person.Validate();

                db.Set <Person>().Add(myStaff.Person);
                db.Staffs.Add(myStaff);
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 19
0
        public async Task <bool> CheckOut(Guid purchaseGuid, PurchaseState purchaseState = PurchaseState.Paid)
        {
            using (var db = new StationContext())
            {
                var myPurchase = await db.Purchases.FindAsync(purchaseGuid);

                if (myPurchase == null)
                {
                    throw new InvalidOperationException("ITEM_NOT_FOUND");
                }
                if (myPurchase.PurchaseState == purchaseState)
                {
                    throw new InvalidOperationException("ITEM_ALREADY_PAID");
                }

                myPurchase.PurchaseState = purchaseState;
                db.Purchases.Attach(myPurchase);
                db.Entry(myPurchase).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 20
0
        public async Task <bool> Post(Price newPrice)
        {
            using (var db = new StationContext())
            {
                if (!db.Fuels.Any(f => f.FuelGuid == newPrice.ProductGuid))
                {
                    throw new InvalidOperationException("FUEL_REFERENCE_NOT_FOUND");
                }

                if (newPrice.PriceGuid == Guid.Empty)
                {
                    newPrice.PriceGuid = Guid.NewGuid();
                }

                newPrice.DateAdded    = DateTime.Now;
                newPrice.LastEditDate = DateTime.Now;

                db.Set <Price>().Add(newPrice);
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 21
0
        public async Task <bool> Post(Company newCompany)
        {
            using (var db = new StationContext())
            {
                if (newCompany.CompanyGuid == Guid.Empty)
                {
                    newCompany.CompanyGuid = Guid.NewGuid();
                }
                if (newCompany.AddressGuid == Guid.Empty)
                {
                    newCompany.AddressGuid = Guid.NewGuid();
                }
                newCompany.Address.AddressGuid = newCompany.AddressGuid;

                newCompany.DateAdded    = DateTime.Now;
                newCompany.LastEditDate = DateTime.Now;

                db.Companies.Add(newCompany);
                db.Set <Address>().Add(newCompany.Address);
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 22
0
        public async Task <bool> Post(List <OilPrelevement> oilPrelevements, DateTime fromDate)
        {
            using (var db = new StationContext())
            {
                foreach (var prelevement in oilPrelevements)
                {
                    if (prelevement.OilPrelevementGuid == Guid.Empty)
                    {
                        prelevement.OilPrelevementGuid = Guid.NewGuid();
                    }
                    prelevement.CurrentPrice = db.Oils.Find(prelevement.OilGuid).CurrentUnitPrice;

                    var lastOne = StaticGetLastPrelevement(prelevement.OilGuid);

                    prelevement.Result = -prelevement.Meter + lastOne.Meter + GetDeliveries(prelevement.OilGuid, lastOne.DatePrelevement.GetValueOrDefault(), fromDate);

                    if (prelevement.Result < 0)
                    {
                        throw new CoolException(
                                  $"{db.Oils.Find(prelevement.OilGuid).Libel} : Le stock restant ne doit pas etre Supérieur a " + lastOne.Meter + GetDeliveries(prelevement.OilGuid, lastOne.DatePrelevement.GetValueOrDefault(), fromDate));
                    }

                    if (prelevement.Result > StaticGetOilBalance(prelevement.OilGuid))
                    {
                        throw new CoolException(
                                  $"{db.Oils.Find(prelevement.OilGuid).Libel}: Le stock restant ne doit pas etre Supérieur a " + StaticGetOilBalance(prelevement.OilGuid));
                    }

                    prelevement.DatePrelevement = fromDate;
                    prelevement.DateAdded       = DateTime.Now;
                    prelevement.LastEditDate    = DateTime.Now;

                    db.OilPrelevements.Add(prelevement);
                }
                return(await db.SaveChangesAsync() > 0);
            }
        }