Пример #1
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);
        }
Пример #2
0
        public GeneralResponse EditStoreProduct(EditStoreProductRequest request)
        {
            GeneralResponse response     = new GeneralResponse();
            StoreProduct    storeProduct = new StoreProduct();

            storeProduct = _storeProductRepository.FindBy(request.StoreID, request.ProductID);

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

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

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

                    storeProduct.UnitsInStock = request.UnitsInStock;

                    #region RowVersion Check
                    if (storeProduct.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("کارشناس محترم، یک کاربر همزمان با شما در حال ویرایش این رکورد است. بنابراین اطلاعات شما ذخیره نمی شود.");
                        return(response);
                    }
                    else
                    {
                        storeProduct.RowVersion += 1;
                    }
                    #endregion

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

                        return(response);
                    }
                    #endregion

                    _storeProductRepository.Save(storeProduct);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("هیچ موردی جهت ویرایش وجود ندارد.");
            }
            return(response);
        }