Пример #1
0
        public ListResult <ProductDto> GetPackageProductListById_UI(long packageId)
        {
            try
            {
                var post           = new PostServiceProvider();
                var postpriceparam = new PostGetDeliveryPriceParam
                {
                    Price       = 1000000,
                    Weight      = 1000,
                    ServiceType = 2,// (int)customerOrder.PostTypeId,
                    ToCityId    = 39751
                };
                var postresult = post.GetDeliveryPrice(postpriceparam).Result;


                var res = _repository.PackageProduct
                          .FindByCondition(c => c.PackageId == packageId && c.DaDate == null && c.Ddate == null)
                          .Include(c => c.Product).Select(c => c.Product).ToList();
                var result = _mapper.Map <List <ProductDto> >(res);

                var finalresult = ListResult <ProductDto> .GetSuccessfulResult(result);

                return(finalresult);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), packageId);
                return(ListResult <ProductDto> .GetFailResult(e.Message));
            }
        }
Пример #2
0
        public SingleResult <InsertOrderResultDto> GetProductByIdList_UI(OrderModel order)
        {
            try
            {
                var userId          = ClaimPrincipalFactory.GetUserId(User);
                var cc              = _repository.Customer.FindByCondition(c => c.UserId == userId).FirstOrDefault();
                var customerId      = cc.Id;
                var today           = DateTime.Now.AddDays(-1).Ticks;
                var orerProductList = new List <CustomerOrderProduct>();


                var orderNo = customerId.ToString() + DateTimeFunc.TimeTickToShamsi(DateTime.Now.Ticks).Replace("/", "") +
                              (_repository.CustomerOrder.FindByCondition(c => c.CustomerId == customerId && today > c.Cdate)
                               .Count() + 1).ToString().PadLeft(3, '0');


                order.ProductList.ForEach(c =>
                {
                    var product     = _repository.Product.FindByCondition(x => x.Id == c.ProductId).First();
                    var ofer        = _repository.Offer.FindByCondition(x => x.Id == c.OfferId).FirstOrDefault();
                    var packingType = _repository.ProductPackingType.FindByCondition(x => x.Id == c.PackingTypeId)
                                      .FirstOrDefault();
                    var statusId     = _repository.Status.GetSatusId("CustomerOrderProduct", 2);
                    var orderproduct = new CustomerOrderProduct
                    {
                        OrderCount           = c.Count,
                        ProductId            = c.ProductId,
                        Cdate                = DateTime.Now.Ticks,
                        CuserId              = userId,
                        OrderType            = 1,
                        ProductCode          = product.Coding,
                        ProductIncreasePrice = null,
                        ProductName          = product.Name,
                        ProductPrice         = product.Price,
                        ProductOfferId       = c.OfferId,
                        ProductOfferCode     = ofer?.OfferCode,
                        ProductOfferPrice    = (long?)(ofer != null ? (ofer.Value / 100 * product.Price) : 0),
                        ProductOfferValue    = ofer?.Value,
                        PackingTypeId        = packingType?.PackinggTypeId,
                        PackingWeight        = packingType == null ? 0 : packingType.Weight,
                        PackingPrice         = packingType == null ? 0 : packingType.Price,
                        SellerId             = product.SellerId,
                        Weight               = c.Count * product.Weight,
                        FinalWeight          = (c.Count * product.Weight) + (c.Count * (packingType == null ? 0 : packingType.Weight)),
                        FinalStatusId        = statusId
                    };
                    orerProductList.Add(orderproduct);
                });

                var offer         = _repository.Offer.FindByCondition(c => c.Id == order.OfferId).FirstOrDefault();
                var paking        = _repository.PackingType.FindByCondition(c => c.Id == order.PaymentTypeId).FirstOrDefault();
                var customerOrder = new CustomerOrder
                {
                    Cdate               = DateTime.Now.Ticks,
                    CuserId             = userId,
                    CustomerAddressId   = order.CustomerAddressId,
                    CustomerDescription = order.CustomerDescription,
                    CustomerId          = customerId,
                    FinalStatusId       = _repository.Status.GetSatusId("CustomerOrder", 1),
                    OfferId             = order.OfferId,
                    OrderPrice          = orerProductList.Sum(x =>
                                                              ((x.PackingPrice + x.ProductPrice - x.ProductOfferPrice) * x.OrderCount))
                };

                customerOrder.OrderPrice = orerProductList.Sum(c =>
                                                               (c.ProductPrice + c.PackingPrice - c.ProductOfferPrice) * c.OrderCount);
                customerOrder.OfferPrice =
                    (long?)(customerOrder.OrderPrice * (offer == null ? 0 : offer.Value / 100));
                customerOrder.OfferValue       = (int?)offer?.Value;
                customerOrder.OrderDate        = DateTime.Now.Ticks;
                customerOrder.FinalWeight      = orerProductList.Sum(x => x.FinalWeight);
                customerOrder.OrderNo          = Convert.ToInt64(orderNo);
                customerOrder.OrderProduceTime = 0;
                customerOrder.OrderType        = 1;
                customerOrder.OrderWeight      = customerOrder.FinalWeight;
                customerOrder.PackingPrice     = 0;
                customerOrder.PackingWeight    = 0;
                customerOrder.PaymentTypeId    = order.PaymentTypeId;
                customerOrder.PostServicePrice = 0;
                customerOrder.PostTypeId       = order.PostTypeId;

                //customerOrder.TaxPrice = (long?)((customerOrder.OrderPrice - customerOrder.OfferPrice) * 0.09);
                //customerOrder.TaxValue = 9;
                customerOrder.TaxPrice = 0;
                customerOrder.TaxValue = 9;


                customerOrder.CustomerOrderProduct = orerProductList;
                var toCityId = _repository.CustomerAddress.FindByCondition(c => c.Id == order.CustomerAddressId).Include(c => c.City).Select(c => c.City.PostCode).FirstOrDefault();


                var postType = _repository.PostType.FindByCondition(c => c.Id == order.PostTypeId).FirstOrDefault();
                var payType  = _repository.PaymentType.FindByCondition(c => c.Id == order.PaymentTypeId)
                               .FirstOrDefault();

                if (postType.IsFree.Value)
                {
                    customerOrder.PostServicePrice = 0;
                }
                else
                {
                    var post           = new PostServiceProvider();
                    var postpriceparam = new PostGetDeliveryPriceParam
                    {
                        Price       = (int)customerOrder.OrderPrice.Value,
                        Weight      = (int)customerOrder.FinalWeight.Value,
                        ServiceType = postType?.Rkey ?? 2,// (int)customerOrder.PostTypeId,
                        ToCityId    = (int)toCityId,
                        PayType     = (int)(payType?.Rkey ?? 88)
                    };
                    var postresult = post.GetDeliveryPrice(postpriceparam).Result;
                    if (postresult.ErrorCode != 0)
                    {
                        throw new BusinessException(XError.IncomingSerivceErrors.PostSeerivcError());
                    }
                    customerOrder.PostServicePrice = (postresult.PostDeliveryPrice + postresult.VatTax) / 10;
                }


                customerOrder.FinalPrice = customerOrder.OrderPrice + customerOrder.TaxPrice + customerOrder.PostServicePrice;
                _repository.CustomerOrder.Create(customerOrder);



                var request = new ZarinPallRequest
                {
                    //  amount = (int)((customerOrder.FinalPrice.Value + customerOrder.PostServicePrice) * 10),
                    amount      = (int)((customerOrder.FinalPrice.Value) * 10),
                    description = "order NO: " + customerOrder.OrderNo,
                    metadata    = new ZarinPalRequestMetaData
                    {
                        mobile = "0" + cc.Mobile.ToString(),
                        email  = cc.Email
                    }
                };
                var zarinPal = new ZarinPal();
                var res      = zarinPal.Request(request);

                var customerOrderPayment = new CustomerOrderPayment
                {
                    OrderNo          = customerOrder.OrderNo.ToString(),
                    TraceNo          = res.authority,
                    TransactionPrice = customerOrder.FinalPrice,
                    TransactionDate  = DateTime.Now.Ticks,
                    Cdate            = DateTime.Now.Ticks,
                    CuserId          = userId,
                    PaymentPrice     = customerOrder.FinalPrice,
                    FinalStatusId    = 26
                };
                customerOrder.CustomerOrderPayment.Add(customerOrderPayment);
                _repository.Save();

                var result = new InsertOrderResultDto
                {
                    OrderNo         = customerOrder.OrderNo,
                    CustomerOrderId = customerOrder.Id,
                    BankUrl         = "https://www.zarinpal.com/pg/StartPay/" + res.authority,
                    RedirectToBank  = true,
                    PostPrice       = customerOrder.PostServicePrice
                };
                var finalres = SingleResult <InsertOrderResultDto> .GetSuccessfulResult(result);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, order);
                return(finalres);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), order);
                return(SingleResult <InsertOrderResultDto> .GetFailResult(e.Message));
            }
        }
Пример #3
0
        public SingleResult <OrderPreViewResultDto> CustomerOrderPreview_UI(OrderModel order)
        {
            try
            {
                var orerProductList = new List <CustomerOrderProduct>();



                order.ProductList.ForEach(c =>
                {
                    var product     = _repository.Product.FindByCondition(x => x.Id == c.ProductId).First();
                    var ofer        = _repository.Offer.FindByCondition(x => x.Id == c.OfferId).FirstOrDefault();
                    var packingType = _repository.ProductPackingType.FindByCondition(x => x.Id == c.PackingTypeId)
                                      .FirstOrDefault();
                    var statusId     = _repository.Status.GetSatusId("CustomerOrderProduct", 2);
                    var orderproduct = new CustomerOrderProduct
                    {
                        OrderCount        = c.Count,
                        ProductId         = c.ProductId,
                        ProductCode       = product.Coding,
                        ProductName       = product.Name,
                        ProductPrice      = product.Price,
                        ProductOfferId    = c.OfferId,
                        ProductOfferCode  = ofer?.OfferCode,
                        ProductOfferPrice = (long?)(ofer != null ? (ofer.Value / 100 * product.Price) : 0),
                        ProductOfferValue = ofer?.Value,
                        PackingTypeId     = c.PackingTypeId,
                        PackingWeight     = packingType == null ? 0 : packingType.Weight,
                        PackingPrice      = packingType == null ? 0 : packingType.Price,
                        SellerId          = product.SellerId,
                        Weight            = c.Count * product.Weight,
                        FinalWeight       = (c.Count * product.Weight) + (c.Count * (packingType == null ? 0 : packingType.Weight)),
                        FinalStatusId     = statusId
                    };
                    orerProductList.Add(orderproduct);
                });

                var offer         = _repository.Offer.FindByCondition(c => c.Id == order.OfferId).FirstOrDefault();
                var paking        = _repository.PackingType.FindByCondition(c => c.Id == order.PaymentTypeId).FirstOrDefault();
                var customerOrder = new OrderPreViewResultDto();

                customerOrder.OrderPrice = orerProductList.Sum(c =>
                                                               (c.ProductPrice + c.PackingPrice - c.ProductOfferPrice) * c.OrderCount);
                customerOrder.OfferPrice =
                    (long?)(customerOrder.OrderPrice * (offer == null ? 0 : offer.Value / 100));
                customerOrder.OfferValue       = (int?)offer?.Value;
                customerOrder.FinalWeight      = orerProductList.Sum(x => x.FinalWeight);
                customerOrder.OrderWeight      = customerOrder.FinalWeight;
                customerOrder.PaymentTypeId    = order.PaymentTypeId;
                customerOrder.PostServicePrice = 0;



                customerOrder.ProductList = orerProductList;
                var toCityId = _repository.CustomerAddress.FindByCondition(c => c.Id == order.CustomerAddressId).Include(c => c.City).Select(c => c.City.PostCode).FirstOrDefault();


                var postType = _repository.PostType.FindByCondition(c => c.Id == order.PostTypeId).FirstOrDefault();
                var payType  = _repository.PaymentType.FindByCondition(c => c.Id == order.PaymentTypeId)
                               .FirstOrDefault();
                if (postType.IsFree.Value)
                {
                    customerOrder.PostServicePrice = 0;
                }
                else
                {
                    var post           = new PostServiceProvider();
                    var postpriceparam = new PostGetDeliveryPriceParam
                    {
                        Price       = (int)customerOrder.OrderPrice.Value,
                        Weight      = (int)customerOrder.FinalWeight.Value,
                        ServiceType = postType?.Rkey ?? 2,// (int)customerOrder.PostTypeId,
                        ToCityId    = (int)toCityId,
                        PayType     = (int)(payType?.Rkey ?? 88)
                    };
                    var postresult = post.GetDeliveryPrice(postpriceparam).Result;
                    if (postresult.ErrorCode != 0)
                    {
                        throw new BusinessException(XError.IncomingSerivceErrors.PostSeerivcError());
                    }
                    customerOrder.PostServicePrice = (postresult.PostDeliveryPrice + postresult.VatTax) / 10;
                }


                customerOrder.FinalPrice = customerOrder.OrderPrice + customerOrder.PostServicePrice;
                var finalres = SingleResult <OrderPreViewResultDto> .GetSuccessfulResult(customerOrder);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, order);
                return(finalres);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), order);
                return(SingleResult <OrderPreViewResultDto> .GetFailResult(e.Message));
            }
        }