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);
        }
        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);
        }