Esempio n. 1
0
        public override void update(object obj)
        {
            try
            {
                BillEntity entity = obj as BillEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    BillHistory billHistory = context.BillHistories.Find(entity.BillID);
                    context.Entry(billHistory).CurrentValues.SetValues(entity);
                    billHistory.TotalPrice = CalculateTotalPrice(entity.ListProduct);

                    Dictionary <int, int> listProduct = entity.ListProduct;

                    foreach (KeyValuePair <int, int> product in listProduct)
                    {
                        BillDetail billDetail = context.BillDetails.Find(entity.BillID, product.Key);

                        if (billDetail != null && billDetail.Quantity != product.Value)
                        {
                            Product pro = context.Products.Find(product.Key);
                            pro.Quantity = pro.Quantity + billDetail.Quantity - product.Value;

                            context.Entry(billDetail)
                            .CurrentValues.SetValues(new
                            {
                                BillID    = billDetail.BillID,
                                ProductID = product.Key,
                                Quantity  = product.Value
                            });
                        }
                        else if (billDetail == null)
                        {
                            Product pro = context.Products.Find(product.Key);
                            pro.Quantity = pro.Quantity - product.Value;

                            BillDetail detail = new BillDetail()
                            {
                                BillID    = entity.BillID,
                                ProductID = product.Key,
                                Quantity  = product.Value
                            };

                            context.BillDetails.Add(detail);
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 2
0
        public override void update(object obj)
        {
            try
            {
                GoodsImportEntity entity = obj as GoodsImportEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    GoodsImportHistory old = context.GoodsImportHistories.Find(entity.ImportDate, entity.ProductID);
                    int oldQuantity        = old.Quantity;

                    context.Entry(old).CurrentValues.SetValues(entity);

                    Product product = context.Products.Find(entity.ProductID);
                    product.Quantity = product.Quantity - oldQuantity + entity.Quantity;

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
Esempio n. 3
0
        public override void update(object obj)
        {
            try
            {
                UserEntity user = obj as UserEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    User oldUser = context.Users.Find(user.UserID);
                    context.Entry(oldUser).CurrentValues.SetValues(user);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }
        public override void update(object obj)
        {
            try
            {
                ProductEntity product = obj as ProductEntity;

                using (StoreManagementEntities context = new StoreManagementEntities())
                {
                    Product oldProduct = context.Products.Find(product.ProductID);
                    context.Entry(oldProduct).CurrentValues.SetValues(product);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                CustomException ex = new CustomException(GetType().Name + " : Update " + obj.ToString() + "\n" + e.Message);
                ex.showPopupError();
            }
        }