Beispiel #1
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();
        }
Beispiel #2
0
        public Data.Entities.Component RegisterComponent(Domain.PizzaComponent pc)
        {
            Data.Entities.Component _pc = new Data.Entities.Component();
            _pc.Name = pc.Name;
            _pc.Cost = pc.Cost;
            _pc.Kind = pc.GetKind();

            db.Add(_pc);
            db.SaveChanges();
            return(_pc);
        }
Beispiel #3
0
        public Data.Entities.Component GetComponentEntity(Domain.PizzaComponent pc)
        {
            string kind = pc.GetKind();

            try
            {
                List <Data.Entities.Component> component = db.Component
                                                           .Where(p => p.Name.ToLower().Equals(pc.Name.ToLower()) &&
                                                                  p.Kind.ToLower().Equals(kind.ToLower()))
                                                           .ToList();
                Data.Entities.Component comp = component.First();
                return(comp);
            }
            catch (System.InvalidOperationException)
            {
                return(null);
            }
        }