Exemplo n.º 1
0
        public GeneralResponse DeleteStores(IEnumerable <DeleteRequest> requests)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                foreach (DeleteRequest request in requests)
                {
                    Infrastructure.Querying.Query query = new Query();
                    Criterion CriteriaStoreID           = new Criterion("Store.ID", request.ID, CriteriaOperator.Equal);
                    query.Add(CriteriaStoreID);

                    StoreProduct storeProduct = _storeProductRepository.FindBy(query).FirstOrDefault();
                    if (storeProduct == null)
                    {
                        Store store = new Store();

                        store = _storeRepository.FindBy(request.ID);

                        _storeRepository.Remove(store);
                    }
                    else
                    {
                        response.ErrorMessages.Add("در سیستم برای انبار " + storeProduct.Store.StoreName + " تراکنش وجود داد. لذا امکان حذف این انبار وجود ندارد");
                        return(response);
                    }
                }
                _uow.Commit();
            }

            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
Exemplo n.º 2
0
        public GeneralResponse AddProductLogToStore(AddProductLogStoreRequest request, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            ProductLog productLog = new ProductLog();


            productLog.ID = Guid.NewGuid();

            productLog.CreateDate        = PersianDateTime.Now;
            productLog.CreateEmployee    = _employeeRepository.FindBy(CreateEmployeeID);
            productLog.Note              = request.Note;
            productLog.Closed            = request.Closed;
            productLog.InputSerialNumber = GetNewSerialNumber;
            productLog.LogDate           = request.LogDate;
            productLog.Product           = this._productRepository.FindBy(request.ProductID);

            productLog.ProductSerialFrom  = request.ProductSerialFrom;
            productLog.ProductSerialTo    = request.ProductSerialTo;
            productLog.PurchaseBillNumber = request.PurchaseBillNumber;
            productLog.PurchaseDate       = request.PurchaseDate;
            productLog.PurchaseUnitPrice  = request.PurchaseUnitPrice;
            productLog.SellerName         = request.SellerName;

            productLog.RowVersion = 1;
            productLog.Store      = _storRepository.FindBy(request.StoreID);

            Product product = productLog.Product;

            if (request.IO == -1)
            {
                productLog.UnitsIO = +request.DisplayUnitsIO;
            }
            else
            {
                productLog.UnitsIO = -request.DisplayUnitsIO;
            }



            #region If record exists, Edit UnitsInStock

            StoreProduct storeProduct = new StoreProduct();
            storeProduct = _storeProductrepository.FindBy(request.StoreID, request.ProductID);

            if (storeProduct != null)
            {
                storeProduct.ModifiedDate     = PersianDateTime.Now;
                storeProduct.ModifiedEmployee = _employeeRepository.FindBy(CreateEmployeeID);
                if (request.ProductID != null)
                {
                    storeProduct.Product = this._productRepository.FindBy(request.ProductID);
                }
                if (request.StoreID != null)
                {
                    storeProduct.Store = this._storRepository.FindBy(request.StoreID);
                }

                if (request.IO == -1)
                {
                    if (storeProduct.UnitsInStock < request.DisplayUnitsIO)
                    {
                        response.ErrorMessages.Add("موجودی انبار مجازی کافی نیست");
                        return(response);
                    }
                    else
                    {
                        product.UnitsInStock      += request.DisplayUnitsIO;
                        storeProduct.UnitsInStock -= request.DisplayUnitsIO;
                    }
                }
                if (request.IO == 1)
                {
                    if (productLog.Product.UnitsInStock < request.DisplayUnitsIO)
                    {
                        response.ErrorMessages.Add("موجودی انبار اصلی کافی نیست");
                        return(response);
                    }
                    else
                    {
                        product.UnitsInStock      -= request.DisplayUnitsIO;
                        storeProduct.UnitsInStock += request.DisplayUnitsIO;
                    }
                }
                storeProduct.RowVersion += 1;

                _storeProductrepository.Save(storeProduct);
            }

            else
            {
                StoreProduct _storeProduct = new StoreProduct();
                _storeProduct.ID             = Guid.NewGuid();
                _storeProduct.CreateDate     = PersianDateTime.Now;
                _storeProduct.CreateEmployee = _employeeRepository.FindBy(CreateEmployeeID);
                _storeProduct.Product        = this._productRepository.FindBy(request.ProductID);
                _storeProduct.Store          = this._storRepository.FindBy(request.StoreID);
                _storeProduct.UnitsInStock   = 0;
                if (request.IO == -1)
                {
                    if (storeProduct.UnitsInStock < request.DisplayUnitsIO)
                    {
                        response.ErrorMessages.Add("موجودی انبار مجازی کافی نیست");
                        return(response);
                    }
                    else
                    {
                        product.UnitsInStock       += request.DisplayUnitsIO;
                        _storeProduct.UnitsInStock -= request.DisplayUnitsIO;
                    }
                }
                else
                {
                    if (productLog.Product.UnitsInStock < request.DisplayUnitsIO)
                    {
                        response.ErrorMessages.Add("موجودی انبار اصلی کافی نیست");
                        return(response);
                    }
                    else
                    {
                        product.UnitsInStock       -= request.DisplayUnitsIO;
                        _storeProduct.UnitsInStock += request.DisplayUnitsIO;
                    }
                }
                _storeProduct.RowVersion = 1;

                _storeProductrepository.Add(_storeProduct);
            }


            _productRepository.Save(product);
            _productLogRepository.Add(productLog);
            #endregion

            _uow.Commit();

            return(response);
        }
Exemplo n.º 3
0
        public GeneralResponse AddStoreProduct(AddStoreProductRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                StoreProduct storeProduct = new StoreProduct();

                #region If record exists, Edit UnitsInStock
                if (_storeProductRepository.FindBy(request.StoreID, request.ProductID) != null)
                {
                    EditStoreProductRequest editreq = new EditStoreProductRequest()
                    {
                        ModifiedEmployeeID = request.CreateEmployeeID,
                        ProductID          = request.ProductID,
                        StoreID            = request.StoreID,
                        UnitsInStock       = _storeProductRepository.FindBy(request.StoreID, request.ProductID).UnitsInStock + request.UnitsInStock,
                        RowVersion         = _storeProductRepository.FindBy(request.StoreID, request.ProductID).RowVersion
                    };
                    GeneralResponse editRes = new GeneralResponse();
                    editRes = EditStoreProduct(editreq);

                    foreach (string err in editRes.ErrorMessages)
                    {
                        response.ErrorMessages.Add(err);
                    }
                    return(response);
                }
                #endregion

                storeProduct.ID             = Guid.NewGuid();
                storeProduct.CreateDate     = PersianDateTime.Now;
                storeProduct.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID);
                storeProduct.Product        = this._productRepository.FindBy(request.ProductID);
                storeProduct.Store          = this._storeRepository.FindBy(request.StoreID);
                storeProduct.UnitsInStock   = request.UnitsInStock;
                storeProduct.RowVersion     = 1;

                #region Edit UnitsInStock Of Product Entity
                Product product = new Product();
                product = _productRepository.FindBy(request.ProductID);
                product.UnitsInStock -= request.UnitsInStock;
                if (product.UnitsInStock < 0)
                {
                    response.ErrorMessages.Add("تعداد وارد شده از موجودی انبار مرکزی بیشتر است.");

                    return(response);
                }
                else
                {
                    _productRepository.Save(product);
                }

                #endregion

                #region Validation
                if (storeProduct.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in storeProduct.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }
                #endregion

                _storeProductRepository.Add(storeProduct);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }