Ejemplo n.º 1
0
        public void RemoveDocument(int docId)
        {
            var loggedUser = _securityManager.GetLoggedUser();

            var document = _db.DocumentItems.FirstOrDefault(u => u.Id == docId && u.User.Id == loggedUser.Id);

            if (document != null)
            {
                _db.Entry <DocumentItem>(document).State = System.Data.Entity.EntityState.Deleted;
                _db.SaveChanges();
            }
            else
            {
                _log.ErrorFormat("Document with not found");
                throw new WarehouseException("Document with not found");
            }
        }
Ejemplo n.º 2
0
        public bool RemoveProducts(IEnumerable <int> producIds)
        {
            using (WarehouseDbContext _db = new WarehouseDbContext())
            {
                foreach (var id in producIds)
                {
                    var _removeItem = _db.Warehouse.FirstOrDefault(x => x.ProductId == id);
                    _db.Warehouse.Attach(_removeItem);
                    _db.Entry <Warehouse>(_removeItem).State = EntityState.Deleted;
                }

                return(_db.SaveChanges() > 0);
            }
        }
Ejemplo n.º 3
0
        //private static DataBaseManager _db=DataBaseManager.GetDatabaseInstance();



        //public static async Task<decimal> GetProductPriceById(int productId)
        //{
        //    using (DataBaseManager _db = new DataBaseManager())
        //    {
        //        var currentProduct =await _db.Warehouse.FirstOrDefaultAsync(x => x.ProductId == productId);

        //        return currentProduct != null ? currentProduct.RetailPrice : 0;
        //    }
        //}
        //public static async Task<List<Warehouse>> GetALLProductsFromWarehouse()
        //{
        //    using (DataBaseManager _db = new DataBaseManager())
        //    {
        //        return await _db.Warehouse.ToListAsync();
        //    }
        //}
        /// <summary>
        /// Binded to datasource
        /// </summary>
        /// <returns></returns>
        //public static  List<WareHouseViewer> GetRemindProductsFromWarehouseSearch(string filter)
        //{

        //    using (DataBaseManager _db = new DataBaseManager())
        //    {
        //        return (from wh in _db.Warehouse
        //                join product in _db.Product on wh.ProductId equals product.Id
        //                where (
        //                (filter == null || filter == "") ||
        //                product.Name.Trim().ToLower().Contains(filter.Trim().ToLower()))

        //                && wh.TotalRemind > 0
        //                select new WareHouseViewer
        //                {
        //                    BarCode = product.BarCode,
        //                    ProductName = product.Name,
        //                    RemindTotal = wh.TotalRemind,
        //                    RetailPrice = wh.RetailPrice
        //                }).ToList();

        //    }

        //}
        /// <summary>
        /// Update warehouse price and Count
        /// Or insert a row
        /// </summary>
        /// <param name="buys"></param>
        public void ComplateBuyAction()
        {
            using (WarehouseDbContext _db = new WarehouseDbContext())
            {
                foreach (var buy in buys)
                {
                    var warehouse = _db.Warehouse.Where(x => x.ProductId == buy.ProductId).FirstOrDefault();
                    if (warehouse == null)
                    {
                        //need to add product

                        _db.Warehouse.Add(new Warehouse()
                        {
                            ProductId      = buy.ProductId,
                            TotalRemind    = buy.Count,
                            RetailPrice    = buy.RetailPrice,
                            Price          = buy.Price,
                            WholeSalePrice = buy.WholeSalePrice,
                        });
                    }

                    else
                    {
                        //need to  update product

                        if (buy.RetailPrice != 0 && buy.RetailPrice != warehouse.RetailPrice)
                        {
                            warehouse.RetailPrice    = buy.RetailPrice;
                            warehouse.Price          = buy.Price;
                            warehouse.WholeSalePrice = buy.WholeSalePrice;
                        }
                        warehouse.TotalRemind += buy.Count;
                        _db.Warehouse.Attach(warehouse);
                        _db.Entry <Warehouse>(warehouse).State = EntityState.Modified;
                    }
                }

                _db.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void ComplateSale()
        {
            using (WarehouseDbContext _db = new WarehouseDbContext())
            {
                //using (var transact = _db.Database.BeginTransaction())
                //{
                try
                {
                    foreach (var sale in sales)
                    {
                        var _whProd = _db.Warehouse.Where(x => x.ProductId == sale.ProductId).FirstOrDefault();
                        if (_whProd == null)
                        {
                            throw new InvalidOperationException();
                        }

                        else
                        {
                            //need to  update product

                            if (_whProd.TotalRemind < sale.Count)
                            {
                                throw new Exception("Count not available");
                            }
                            _whProd.TotalRemind -= sale.Count;
                            _db.Warehouse.Attach(_whProd);
                            _db.Entry <Warehouse>(_whProd).State = EntityState.Modified;
                        }
                    }

                    _db.SaveChanges();
                    //transact.Commit();
                }
                catch
                {
                    //transact.Rollback();
                    throw;
                }
            }
        }