Exemplo n.º 1
0
        public GeneralResponse EditCreditSaleDetail(EditCreditSaleDetailRequest request)
        {
            GeneralResponse  response         = new GeneralResponse();
            CreditSaleDetail creditSaleDetail = new CreditSaleDetail();

            creditSaleDetail = _creditSaleDetailRepository.FindBy(request.ID);

            if (creditSaleDetail != null)
            {
                try
                {
                    creditSaleDetail.ModifiedDate     = PersianDateTime.Now;
                    creditSaleDetail.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (creditSaleDetail.CreditService.ID != request.CreditServiceID)
                    {
                        creditSaleDetail.CreditService = this._creditServiceRepository.FindBy(request.CreditServiceID);
                    }
                    creditSaleDetail.Discount   = request.Discount;
                    creditSaleDetail.Imposition = request.Imposition;
                    creditSaleDetail.UnitPrice  = request.UnitPrice;

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

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

                        return(response);
                    }

                    _creditSaleDetailRepository.Save(creditSaleDetail);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
Exemplo n.º 2
0
        public GeneralResponse DoCourierAction(Guid CourierID, int CourierStatuse, string ExpertComment, Guid CourierEmployeeID, Guid ModifiedEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Courier courier = new Courier();
                courier = _courierRepository.FindBy(CourierID);
                if (courier.CourierStatuse == Courier.CourierStatuses.Confirmed)
                {
                    response.ErrorMessages.Add("این اعزام پیک تایید شده است.  لذا دیگر قادر به تغییر وضعیت آن نیستید");
                    return(response);
                }

                courier.ExpertComment    = ExpertComment;
                courier.CourierStatuse   = (Courier.CourierStatuses)CourierStatuse;
                courier.ModifiedDate     = PersianDateTime.Now;
                courier.ModifiedEmployee = _employeeRepository.FindBy((ModifiedEmployeeID));
                courier.CourierEmployee  = _courierEmployeeRepository.FindBy(CourierEmployeeID);

                #region Add Courier To Bonus An Comissions

                if ((Courier.CourierStatuses)CourierStatuse == Courier.CourierStatuses.Confirmed)
                {
                    //برای خدمات غیر اعتباری
                    foreach (var item in courier.Sale.UncreditSaleDetails.Where(x => x.Rollbacked == false))
                    {
                        Query     query = new Query();
                        Criterion UncreditSaleDetailID = new Criterion("ID", item.ID,
                                                                       CriteriaOperator.Equal);
                        query.Add(UncreditSaleDetailID);
                        UncreditSaleDetail unCreditSaleDetail = _uncreditSaleDetailRepository.FindBy(query).FirstOrDefault();
                        if (unCreditSaleDetail != null)
                        {
                            unCreditSaleDetail.BonusDate = PersianDateTime.Now;

                            _uncreditSaleDetailRepository.Save(unCreditSaleDetail);
                        }
                    }

                    //برای خدمات  اعتباری
                    foreach (var item in courier.Sale.CreditSaleDetails.Where(x => x.Rollbacked == false))
                    {
                        Query     query = new Query();
                        Criterion UncreditSaleDetailID = new Criterion("ID", item.ID,
                                                                       CriteriaOperator.Equal);
                        query.Add(UncreditSaleDetailID);
                        CreditSaleDetail creditSaleDetail = _creditSaleDetailRepository.FindBy(query).FirstOrDefault();
                        if (creditSaleDetail != null)
                        {
                            creditSaleDetail.BonusDate = PersianDateTime.Now;
                            _creditSaleDetailRepository.Save(creditSaleDetail);
                        }
                    }

                    //برای کالاها
                    foreach (var item in courier.Sale.ProductSaleDetails.Where(x => x.Rollbacked == false))
                    {
                        Query     query = new Query();
                        Criterion UncreditSaleDetailID = new Criterion("ID", item.ID,
                                                                       CriteriaOperator.Equal);
                        query.Add(UncreditSaleDetailID);
                        ProductSaleDetail productsaleDetail = _productSaleDetailRepository.FindBy(query).FirstOrDefault();
                        if (productsaleDetail != null)
                        {
                            productsaleDetail.BonusDate = PersianDateTime.Now;
                            _productSaleDetailRepository.Save(productsaleDetail);
                        }
                    }
                }

                #endregion

                _courierRepository.Save(courier);

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

            return(response);
        }