Beispiel #1
0
        public void PutProductToFridge(FridgeProductBindingModel model)
        {
            FridgeProduct element = context.FridgeProducts.FirstOrDefault(rec =>
                                                                          rec.FridgeId == model.FridgeId && rec.ProductId == model.ProductId);

            if (element != null)
            {
                element.Count += model.Count;
            }
            else
            {
                context.FridgeProducts.Add(new FridgeProduct
                {
                    FridgeId     = model.FridgeId,
                    ProductId    = model.ProductId,
                    ProductName  = model.ProductName,
                    ReceiptDate  = model.ReceiptDate,
                    FreshDate    = model.FreshDate,
                    FreshStatus  = model.FreshStatus,
                    DateNotFresh = model.DateNotFresh,
                    Count        = model.Count
                });
            }
            context.SaveChanges();
        }
        public void PutProductToFridge(FridgeProductBindingModel model)
        {
            FridgeProduct element = source.FridgeProducts.FirstOrDefault(rec =>
                                                                         rec.FridgeId == model.FridgeId && rec.ProductId == model.ProductId);

            if (element != null)
            {
                element.Count += model.Count;
            }
            else
            {
                int maxId = source.FridgeProducts.Count > 0 ?
                            source.FridgeProducts.Max(rec => rec.Id) : 0;
                source.FridgeProducts.Add(new FridgeProduct
                {
                    Id        = ++maxId,
                    FridgeId  = model.FridgeId,
                    ProductId = model.ProductId,
                    Count     = model.Count
                });
            }
        }