public static void AddTown(string name, string zipcode, string countryName, string continent)
        {
            using (AvalonContext context = new AvalonContext())
            {
                Country country = context.Countries.FirstOrDefault(c => c.Name.ToLower() == countryName.ToLower());

                if (country == null)
                {
                    country = new Country
                    {
                        Name      = name,
                        Continent = continent
                    };
                    context.Countries.Add(country);
                    context.SaveChanges();
                }
                Town town = new Town
                {
                    Name    = name,
                    ZipCode = zipcode,
                    Country = country
                };
                context.Towns.Add(town);
                context.SaveChanges();
            }
        }
        public static void UpdateBeer(Beer beerToUpdate, string newstyle, string newdistributor, string newbrewery)
        {
            using (AvalonContext context = new AvalonContext())
            {
                context.Beers.Attach(beerToUpdate);

                context.Entry(beerToUpdate).Reference(o => o.Style).Load();
                context.Entry(beerToUpdate).Reference(o => o.Brewery).Load();
                context.Entry(beerToUpdate).Reference(o => o.Distributor).Load();


                if (newstyle != String.Empty)
                {
                    Style newStyle = context.Styles.Where(s => s.Name == newstyle).Include("Beers").FirstOrDefault();
                    beerToUpdate.Style   = newStyle;
                    beerToUpdate.StyleId = newStyle.Id;
                }
                if (newdistributor != String.Empty)
                {
                    Distributor newDistributor = context.Distributors.Where(s => s.Name == newdistributor).Include("Breweries").Include("Beers").FirstOrDefault();
                    beerToUpdate.Distributor   = newDistributor;
                    beerToUpdate.DistributorId = newDistributor.Id;
                }
                if (newbrewery != String.Empty)
                {
                    Brewery newBrewery = context.Breweries.Where(s => s.Name == newbrewery).Include("Beers").Include("Distributors").FirstOrDefault();
                    beerToUpdate.Brewery   = newBrewery;
                    beerToUpdate.BreweryId = newBrewery.Id;
                }

                context.Entry(beerToUpdate).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
        public static void AddBrewery(Brewery brewery, string chosenTown, List <string> chosenBeers, List <string> chosenDistributors)
        {
            using (var context = new AvalonContext())
            {
                var town = context.Towns.Where(t => t.Name == chosenTown).FirstOrDefault();

                brewery.Town = town;

                foreach (var chosenBeer in chosenBeers)
                {
                    var beer = context.Beers.Where(b => b.Name == chosenBeer).FirstOrDefault();
                    brewery.Beers.Add(beer);
                }

                foreach (var chosenDistributor in chosenDistributors)
                {
                    var distro = context.Distributors.Where(b => b.Name == chosenDistributor).FirstOrDefault();
                    brewery.Distributors.Add(distro);
                }


                context.Breweries.Add(brewery);
                context.SaveChanges();
            }
        }
        public static void AddSale(Dictionary <string, int> beers, string customerName)
        {
            using (AvalonContext context = new AvalonContext())
            {
                var customer = context.Customers
                               .Where(c => c.Name.ToLower() == customerName.ToLower()).First();

                Sale sale = new Sale
                {
                    Date     = DateTime.Now,
                    Customer = customer,
                    SellerId = SecurityService.GetLoggedUser().Id
                };
                context.Sales.Add(sale);

                foreach (var b in beers)
                {
                    string beerName = b.Key;
                    int    quantity = b.Value;
                    var    beer     = context.Beers.Where(be => be.Name.ToLower() == beerName.ToLower()).First();
                    beer.Quantity -= quantity;

                    BeerSale beerSale = new BeerSale
                    {
                        Beer     = beer,
                        Quantity = quantity,
                        Sale     = sale
                    };
                    sale.Beers.Add(beerSale);
                }
                context.SaveChanges();
            }
        }
 public static void UpdateClient(Customer client)
 {
     using (var db = new AvalonContext())
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
 public static void DeleteBeer(string beerName)
 {
     using (AvalonContext context = new AvalonContext())
     {
         var beer = context.Beers.Where(b => b.Name == beerName).FirstOrDefault();
         context.Beers.Remove(beer);
         context.SaveChanges();
     }
 }
 public static void DeleteClient(string clientName)
 {
     using (var db = new AvalonContext())
     {
         var client = db.Customers.FirstOrDefault(x => x.Name == clientName);
         if (client != null)
         {
             db.Customers.Remove(client);
             db.SaveChanges();
         }
     }
 }
예제 #8
0
        public static void DeleteDistributor(string distributorName)
        {
            using (AvalonContext context = new AvalonContext())
            {
                Distributor distributorToDelete = context.Distributors
                                                  .FirstOrDefault(b => b.Name.ToLower() == distributorName.ToLower());
                distributorToDelete.Breweries.Clear();
                distributorToDelete.Town = null;
                distributorToDelete.Beers.Clear();

                context.Distributors.Remove(distributorToDelete);
                context.SaveChanges();
            }
        }
예제 #9
0
        public static void RegisterUser(string username, string password)
        {
            using (AvalonContext context = new AvalonContext())
            {
                User user = new User
                {
                    Username = username,
                    Password = password
                };

                context.Users.Add(user);
                context.SaveChanges();

                SecurityService.Login(username, password);
            }
        }
예제 #10
0
        public static void AddDistributor(Distributor distributor, string chosenTown, List <string> chosenBreweries)
        {
            using (var context = new AvalonContext())
            {
                var town = context.Towns.Where(t => t.Name == chosenTown).FirstOrDefault();
                distributor.Town = town;

                foreach (var brew in chosenBreweries)
                {
                    var brewery = context.Breweries.Where(b => b.Name == brew).FirstOrDefault();
                    distributor.Breweries.Add(brewery);
                }
                context.Distributors.Add(distributor);
                context.SaveChanges();
            }
        }
        public static void AddCustomer(string name, string address, string townName, string email, string phone, string styleName)
        {
            using (AvalonContext context = new AvalonContext())
            {
                Town  town  = context.Towns.FirstOrDefault(t => t.Name == townName);
                Style style = context.Styles.FirstOrDefault(s => s.Name == styleName);

                Customer customer = new Customer
                {
                    Name          = name,
                    Address       = address,
                    Town          = town,
                    FavoriteStyle = style,
                    Email         = email,
                    Phone         = phone
                };
                context.Customers.Add(customer);
                context.SaveChanges();
            }
        }
 public static void AddBeer(string beerName, decimal salePrice, int quantity, float rating, string styleName, string breweryName, string distributorName, decimal distributorPrice)
 {
     using (AvalonContext context = new AvalonContext())
     {
         Style       style      = context.Styles.FirstOrDefault(s => s.Name.ToLower() == styleName.ToLower());
         Brewery     brewery    = context.Breweries.FirstOrDefault(b => b.Name.ToLower() == breweryName.ToLower());
         Distributor distrbutor = context.Distributors.FirstOrDefault(d => d.Name.ToLower() == distributorName.ToLower());
         Beer        beer       = new Beer
         {
             Name             = beerName,
             SalePrice        = salePrice,
             Quantity         = quantity,
             Rating           = rating,
             Style            = style,
             Brewery          = brewery,
             Distributor      = distrbutor,
             DistributorPrice = distributorPrice
         };
         context.Beers.Add(beer);
         context.SaveChanges();
     }
 }
예제 #13
0
        public static void UpdateDistributor(string distributorToUpdateName, string newName, string town, string phone, string address, List <string> breweries)
        {
            using (AvalonContext context = new AvalonContext())
            {
                Town newTown = context.Towns.FirstOrDefault(t => t.Name.ToLower() == town.ToLower());

                Distributor distributor = context.Distributors
                                          .FirstOrDefault(d => d.Name.ToLower() == distributorToUpdateName.ToLower());
                distributor.Breweries.Clear();
                distributor.Name    = newName;
                distributor.Town    = newTown;
                distributor.Phone   = phone;
                distributor.Address = address;

                foreach (var brew in breweries)
                {
                    distributor.Breweries.Add(context.Breweries.FirstOrDefault(b => b.Name.ToLower() == brew.ToLower()));
                }

                context.SaveChanges();
            }
        }
예제 #14
0
 public void AddGame(Game game)
 {
     _avalonContext.Games.Add(game);
     _avalonContext.SaveChanges();
 }
예제 #15
0
 public void AddQuest(Quest quest)
 {
     _avalonContext.Quests.Add(quest);
     _avalonContext.SaveChanges();
 }
예제 #16
0
 public void AddPlayer(Player player)
 {
     _avalonContext.Players.Add(player);
     _avalonContext.SaveChanges();
 }