예제 #1
0
        public GeneralResponse AddProductLog(AddProductLogRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                ProductLog productLog = new ProductLog();

                productLog.ID                 = Guid.NewGuid();
                productLog.CreateDate         = PersianDateTime.Now;
                productLog.CreateEmployee     = _employeeRepository.FindBy(request.CreateEmployeeID);
                productLog.Note               = request.Note;
                productLog.Closed             = request.Closed;
                productLog.InputSerialNumber  = request.InputSerialNumber;
                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.UnitsIO            = request.UnitsIO;
                productLog.RowVersion         = 1;

                #region Validation

                if (productLog.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in productLog.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }

                #endregion

                Product product = productLog.Product;
                product.UnitsInStock += productLog.UnitsIO;
                _productRepository.Save(product);

                _productLogRepository.Add(productLog);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }
예제 #2
0
        public GeneralResponse AddProductLog(AddProductLogRequest request, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                ProductLog productLog = new ProductLog();


                //if (request.IO == -1)
                //    productLog.UnitsIO = -request.DisplayUnitsIO;
                //else
                //    productLog.UnitsIO = request.DisplayUnitsIO;


                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;


                #region Validation

                if (productLog.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in productLog.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }

                #endregion

                Product product = productLog.Product;


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

                //product.UnitsInStock += productLog.UnitsIO;
                _productRepository.Save(product);



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

            return(response);
        }
예제 #3
0
        public GeneralResponse EditProductLog(EditProductLogRequest request)
        {
            GeneralResponse response   = new GeneralResponse();
            ProductLog      productLog = new ProductLog();

            productLog = _productLogRepository.FindBy(request.ID);

            if (productLog != null)
            {
                try
                {
                    productLog.ModifiedDate     = PersianDateTime.Now;
                    productLog.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (request.Note != null)
                    {
                        productLog.Note = request.Note;
                    }
                    productLog.Closed = request.Closed;
                    if (request.InputSerialNumber != null)
                    {
                        productLog.InputSerialNumber = request.InputSerialNumber;
                    }
                    if (request.LogDate != null)
                    {
                        productLog.LogDate = request.LogDate;
                    }
                    if (request.ProductID != null)
                    {
                        productLog.Product = this._productRepository.FindBy(request.ProductID);
                    }
                    if (request.ProductSerialFrom != null)
                    {
                        productLog.ProductSerialFrom = request.ProductSerialFrom;
                    }
                    if (request.ProductSerialTo != null)
                    {
                        productLog.ProductSerialTo = request.ProductSerialTo;
                    }
                    if (request.PurchaseBillNumber != null)
                    {
                        productLog.PurchaseBillNumber = request.PurchaseBillNumber;
                    }
                    if (request.PurchaseDate != null)
                    {
                        productLog.PurchaseDate = request.PurchaseDate;
                    }
                    productLog.PurchaseUnitPrice = request.PurchaseUnitPrice;
                    if (request.SellerName != null)
                    {
                        productLog.SellerName = request.SellerName;
                    }

                    // بدست آوردن اختلاف تعداد
                    Product product = productLog.Product;
                    if (productLog.UnitsIO != request.UnitsIO)
                    {
                        product.UnitsInStock += request.UnitsIO - productLog.UnitsIO;
                        _productRepository.Save(product);
                    }

                    productLog.UnitsIO = request.UnitsIO;

                    #region RowVersion

                    if (productLog.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        productLog.RowVersion += 1;
                    }

                    #endregion

                    #region Validation

                    if (productLog.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in productLog.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    #endregion

                    _productLogRepository.Save(productLog);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }