예제 #1
0
        public Store(List <AIngredient> inv, Location loc)
        {
            Orders        = new List <Order>();
            StoreLocation = loc;
            Inventory     = inv;

            foreach (var item in inv)
            {
                item.Store = this;
            }

            var locToDb = new Data.Entities.Location
            {
                Address1 = loc.Address1,
                Address2 = loc.Address2,
                City     = loc.City,
                State    = loc.State,
                ZipCode  = loc.ZipCode
            };

            // _db.Location.Add(locToDb);
            // _db.SaveChanges();

            // var storeToDb = new Data.Entities.Store
            // {
            //     StoreNavigation = _db.Location.FirstOrDefault(l => l.Address1 == loc.Address1)
            // };

            // _db.Store.Add(storeToDb);
            // _db.SaveChanges();
        }
예제 #2
0
        public Domain.Location ReadLocation(string name)
        {
            try
            {
                List <Data.Entities.Location> location = db.Location
                                                         .Where(l => l.Name.ToLower().Equals(name.ToLower()))
                                                         .ToList();
                Data.Entities.Location loc = location.First();

                var invEntity = db.InventoryItem
                                .Include(c => c.C)
                                .Where(ie => ie.LocId == loc.LocId)
                                .ToList();



                var o = new Location(loc.Name, loc.Address);
                o.Inventory = GetInventory(invEntity);
                return(o);
            }
            catch (System.InvalidOperationException)
            {
                return(null);
            }
        }
예제 #3
0
        public void ModifyInventory(Domain.Location loc, Domain.PizzaComponent pc, int quantity)
        {
            Data.Entities.Location  locEntity  = GetLocationEntity(loc.Name);
            Data.Entities.Component compEntity = GetComponentEntity(pc);

            if (compEntity is null)
            {
                compEntity = RegisterComponent(pc);
            }
            Data.Entities.InventoryItem invEntity = locEntity.InventoryItem.ToList()
                                                    .Find(i => i.Cid.Equals(compEntity.Cid));
            if (!(invEntity is null))
            {
                invEntity.Quantity = quantity;
                db.SaveChanges();
                return;
            }
            invEntity          = new Data.Entities.InventoryItem();
            invEntity.Loc      = locEntity;
            invEntity.C        = compEntity;
            invEntity.Quantity = quantity;

            locEntity.InventoryItem.Add(invEntity);
            db.SaveChanges();
        }
예제 #4
0
        public User(string fn, string ln, string email, string pw, Location loc)
        {
            Orders = new List <Order>();

            var locToDb = new Data.Entities.Location
            {
                Address1 = loc.Address1,
                Address2 = loc.Address2,
                City     = loc.City,
                State    = loc.State,
                ZipCode  = loc.ZipCode
            };

            _db.Location.Add(locToDb);
            _db.SaveChanges();

            var usertoDb = new Data.Entities.User
            {
                FirstName    = fn,
                LastName     = ln,
                EmailAddress = email,
                Password     = pw,
                Location     = _db.Location.FirstOrDefault(l => l.Address1 == loc.Address1)
            };

            _db.User.Add(usertoDb);

            _db.SaveChanges();
        }
 public static Domain.Location Map(Data.Entities.Location deLocation) => new Domain.Location
 {
     Id      = deLocation.Id,
     Street  = deLocation.Street,
     City    = deLocation.City,
     State   = deLocation.State,
     ZipCode = deLocation.ZipCode,
     Phone   = deLocation.Phone
 };
예제 #6
0
 public static Domain.Location Map(Data.Entities.Location deLocation) => new Domain.Location
 {
     Locationid = deLocation.Locationid,
     Street1    = deLocation.Street1,
     Street2    = deLocation.Street2,
     City       = deLocation.City,
     State      = deLocation.State,
     Country    = deLocation.Country,
     Zipcode    = deLocation.Zipcode
 };
예제 #7
0
        public void RegisterLocation(string name, string address)
        {
            if (ReadLocation(name) is null)
            {
                Data.Entities.Location _loc = new Data.Entities.Location();
                _loc.Name    = name;
                _loc.Address = address;

                db.Add(_loc);
                db.SaveChanges();
            }
        }
예제 #8
0
        public void SaveOrder(Domain.Order order, Domain.Location loc, Domain.User u)
        {
            try
            {
                List <Data.Entities.Location> location = db.Location
                                                         .Where(l => l.Name.ToLower().Equals(loc.Name.ToLower()))
                                                         .ToList();
                Data.Entities.Location locEntity = location.First();

                List <Data.Entities.User> user = db.User
                                                 .Where(us => us.Username.ToLower().Equals(u.Username.ToLower()))
                                                 .ToList();
                Data.Entities.User userEntity = user.First();

                Data.Entities.Order result = new Data.Entities.Order();
                result.User = userEntity;
                result.Loc  = locEntity;

                foreach (var p in order._pizzas)
                {
                    Data.Entities.Pizza pizzaEntity = new Data.Entities.Pizza();

                    Data.Entities.PizzaComponent cheeseEntity = new Data.Entities.PizzaComponent();
                    cheeseEntity.C = GetComponentEntity(p.Cheese);

                    Data.Entities.PizzaComponent crustEntity = new Data.Entities.PizzaComponent();
                    crustEntity.C = GetComponentEntity(p.Crust);

                    Data.Entities.PizzaComponent sizeEntity = new Data.Entities.PizzaComponent();
                    sizeEntity.C = GetComponentEntity(p.Size);

                    pizzaEntity.PizzaComponent.Add(cheeseEntity);
                    pizzaEntity.PizzaComponent.Add(crustEntity);
                    pizzaEntity.PizzaComponent.Add(sizeEntity);

                    foreach (var t in p._toppings)
                    {
                        Data.Entities.PizzaComponent toppingEntity = new Data.Entities.PizzaComponent();
                        toppingEntity.C = GetComponentEntity(t);

                        pizzaEntity.PizzaComponent.Add(toppingEntity);
                    }

                    result.Pizza.Add(pizzaEntity);
                }

                db.Add(result);
                db.SaveChanges();
            }
            catch (System.InvalidOperationException)
            {
            }
        }
예제 #9
0
 public Data.Entities.Location GetLocationEntity(string name)
 {
     try
     {
         List <Data.Entities.Location> location = db.Location
                                                  .Where(l => l.Name.ToLower().Equals(name.ToLower()))
                                                  .ToList();
         Data.Entities.Location loc = location.First();
         return(loc);
     }
     catch (System.InvalidOperationException)
     {
         return(null);
     }
 }
예제 #10
0
        public Location(string a1, string a2, string city, string state, int zip)
        {
            Address1 = a1;
            Address2 = a2;
            City     = city;
            State    = state;
            ZipCode  = zip;

            var locToDb = new Data.Entities.Location
            {
                Address1 = a1,
                Address2 = a2,
                City     = city,
                State    = state,
                ZipCode  = zip
            };

            _db.Location.Add(locToDb);
            _db.SaveChanges();
        }