예제 #1
0
        public GeneralResponse EditUncreditSaleDetail(EditUncreditSaleDetailRequest request)
        {
            GeneralResponse    response           = new GeneralResponse();
            UncreditSaleDetail uncreditSaleDetail = new UncreditSaleDetail();

            uncreditSaleDetail = _uncreditSaleDetailRepository.FindBy(request.ID);

            if (uncreditSaleDetail != null)
            {
                try
                {
                    uncreditSaleDetail.ModifiedDate     = PersianDateTime.Now;
                    uncreditSaleDetail.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    uncreditSaleDetail.Discount         = request.Discount;
                    uncreditSaleDetail.Imposition       = request.Imposition;
                    uncreditSaleDetail.RollbackNote     = request.RollbackNote;
                    //uncreditSaleDetail.Sale = this._saleRepository.FindBy(request.SaleID);
                    //uncreditSaleDetail.UncreditService = this._uncreditServiceRepository.FindBy(request.UncreditServiceID);
                    uncreditSaleDetail.UnitPrice = request.UnitPrice;
                    uncreditSaleDetail.Units     = request.Units;

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

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

                        return(response);
                    }

                    _uncreditSaleDetailRepository.Save(uncreditSaleDetail);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
예제 #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);
        }