Пример #1
0
        public SingleResult <string> MakePaymentByOrderId(long customerOrderId)
        {
            try
            {
                var userId        = ClaimPrincipalFactory.GetUserId(User);
                var customerId    = _repository.Customer.FindByCondition(c => c.UserId == userId).Select(c => c.Id).FirstOrDefault();
                var customerOrder = _repository.CustomerOrder.FindByCondition(c => c.Id == customerOrderId && c.CustomerId == customerId).FirstOrDefault();

                if (customerOrder == null)
                {
                    throw new BusinessException(XError.BusinessErrors.InvalidOrder());
                }

                var request = new ZarinPallRequest
                {
                    amount      = (int)((customerOrder.FinalPrice.Value + customerOrder.PostServicePrice) * 10),
                    description = "order NO: " + customerOrder.OrderNo
                };
                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
                };
                _repository.CustomerOrderPayment.Create(customerOrderPayment);
                _repository.Save();
                var finalres = SingleResult <string> .GetSuccessfulResult("https://www.zarinpal.com/pg/StartPay/" + res.authority);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, customerOrderId);
                return(finalres);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), customerOrderId);

                return(SingleResult <string> .GetFailResult(e.Message));
            }
        }
Пример #2
0
        public SingleResult <CustomerOrderFullDto> GetCustomerOrder_byId_UI(long orderId)
        {
            try
            {
                var res    = _repository.CustomerOrder.GetCustomerOrderFullInfoById(orderId);
                var result = _mapper.Map <CustomerOrderFullDto>(res);

                var finalresult = SingleResult <CustomerOrderFullDto> .GetSuccessfulResult(result);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalresult, null, orderId);
                return(finalresult);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), orderId);

                return(SingleResult <CustomerOrderFullDto> .GetFailResult(e.Message));
            }
        }
        public SingleResult <long> InsertCustomerAddress_UI(CustomerAddressDto addressdto)
        {
            try
            {
                var userId     = ClaimPrincipalFactory.GetUserId(User);
                var customerId = _repository.Customer.FindByCondition(c => c.UserId == userId).Select(c => c.Id)
                                 .FirstOrDefault();
                if (customerId == 0)
                {
                    return(SingleResult <long> .GetFailResult("مشتری یافت نشد"));
                }
                var address = _mapper.Map <CustomerAddress>(addressdto);

                address.CustomerId = customerId;
                address.CuserId    = userId;
                address.Cdate      = DateTime.Now.Ticks;
                _repository.CustomerAddress.Create(address);
                if (address.DefualtAddress.HasValue && address.DefualtAddress.Value)
                {
                    var addresslist = _repository.CustomerAddress.FindByCondition(c => c.CustomerId == customerId && c.Ddate == null && c.DaDate == null && c.DefualtAddress == true)
                                      .FirstOrDefault();
                    if (addresslist != null)
                    {
                        addresslist.DefualtAddress = false;
                        addresslist.Mdate          = DateTime.Now.Ticks;
                        addresslist.MuserId        = userId;
                        _repository.CustomerAddress.Update(addresslist);
                    }
                }

                _repository.Save();
                return(SingleResult <long> .GetSuccessfulResult(address.Id));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, addressdto);
                return(SingleResult <long> .GetFailResult(e.Message));
            }
        }
Пример #4
0
        public SingleResult <SellerFullInfoDto> GetSellerFullInfo_UI()
        {
            try
            {
                var userId = ClaimPrincipalFactory.GetUserId(User);

                var res = _repository.Seller.FindByCondition(c => c.UserId == userId)
                          .Include(c => c.SellerAddress)
                          .Include(c => c.SellerDocument).ThenInclude(c => c.Document).FirstOrDefault();
                var result = _mapper.Map <SellerFullInfoDto>(res);

                var finalres = SingleResult <SellerFullInfoDto> .GetSuccessfulResult(result);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null);
                return(finalres);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod());
                return(SingleResult <SellerFullInfoDto> .GetFailResult(e.Message));
            }
        }
Пример #5
0
        public SingleResult <string> VerifyPayment(string authority, string status)
        {
            try
            {
                var orderpeymnt = _repository.CustomerOrderPayment.FindByCondition(c => c.TraceNo == authority)
                                  .FirstOrDefault();
                if (orderpeymnt == null)
                {
                    throw new BusinessException(XError.BusinessErrors.PaymentInfoNotFound());
                }


                var customerOrderId = orderpeymnt.CustomerOrderId;
                var customer        = _repository.CustomerOrder.FindByCondition(c => c.Id == customerOrderId)
                                      .Include(c => c.Customer).Select(c => c.Customer).First();

                var zarinPalVerifyRequest = new ZarinPalVerifyRequest
                {
                    authority = authority,
                    amount    = (int)orderpeymnt.TransactionPrice.Value * 10
                };

                var zarinPal = new ZarinPal();
                var result   = zarinPal.VerifyPayment(zarinPalVerifyRequest);
                if (result.code == 100 || result.code == 101)
                {
                    orderpeymnt.FinalStatusId   = 24;
                    orderpeymnt.RefNum          = result.ref_id.ToString();
                    orderpeymnt.TransactionDate = DateTime.Now.Ticks;
                    orderpeymnt.CardPan         = result.card_pan;
                    _repository.CustomerOrderPayment.Update(orderpeymnt);

                    var sendSms = new SendSMS();
                    sendSms.SendSuccessOrderPayment(customer.Mobile.Value, orderpeymnt.OrderNo, orderpeymnt.PaymentPrice.Value);

                    var sendEmail = new SendEmail();
                    var email     = customer.Email;
                    sendEmail.SendSuccessOrderPayment(email, orderpeymnt.OrderNo, customerOrderId.Value);



                    var productist = _repository.CustomerOrderProduct.FindByCondition(c => c.CustomerOrderId == customerOrderId).Select(c => c.Product).ToList();
                    productist.ForEach(c =>
                    {
                        c.Count = c.Count--;
                        _repository.Product.Update(c);
                    });


                    var sellerList = _repository.CustomerOrderProduct.FindByCondition(c => c.CustomerOrderId == customerOrderId).Select(c => c.Seller.Mobile).ToList();

                    sellerList.ForEach(c =>
                    {
                        if (c == null)
                        {
                            return;
                        }
                        var sendSms = new SendSMS();
                        sendSms.SendOrderSmsForSeller(c.Value);
                    });


                    _repository.Save();

                    var finalres = SingleResult <string> .GetSuccessfulResult("عملیات پرداخت با موفقیت انجام شد.");

                    _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, customerOrderId);
                    return(finalres);
                }
                else
                {
                    orderpeymnt.FinalStatusId   = 25;
                    orderpeymnt.TransactionDate = DateTime.Now.Ticks;
                    _repository.CustomerOrderPayment.Update(orderpeymnt);
                    _repository.Save();

                    throw new BusinessException(XError.BusinessErrors.FailedPayment());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), authority, status);

                return(SingleResult <string> .GetFailResult("خطا در سامانه"));
            }
        }
Пример #6
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));
            }
        }
Пример #7
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));
            }
        }
Пример #8
0
        public SingleResult <ProductListDto> GetProductList_Paging_Filtering_UI(ProductListParam filter)
        {
            try
            {
                List <Product> res        = new List <Product>();
                int            totalcount = 0;
                long?          MinPrice   = 0;
                long?          MaxPrice   = 0;
                switch (filter.SortMethod)
                {
                case 2:
                    res = _repository.Product.GetProductListFullInfo()
                          .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) &&
                                 (c.CatProductId == filter.CatProductId || filter.CatProductId == null) &&
                                 (filter.MinPrice <= c.Price || filter.MinPrice == null) &&
                                 (c.Price <= filter.MaxPrice || filter.MaxPrice == null) &&
                                 (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0))
                          .OrderByDescending(c => c.ProductCustomerRate.Average(x => x.Rate)).ToList();
                    MinPrice   = res.Min(c => c.Price);
                    MaxPrice   = res.Max(c => c.Price);
                    totalcount = res.Count;
                    res        = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
                    break;

                case 3:
                    res = _repository.Product.GetProductListFullInfo()
                          .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) &&
                                 (c.CatProductId == filter.CatProductId || filter.CatProductId == null) &&
                                 (filter.MinPrice <= c.Price || filter.MinPrice == null) &&
                                 (c.Price <= filter.MaxPrice || filter.MaxPrice == null) &&
                                 (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0))
                          .OrderByDescending(c => c.CustomerOrderProduct.Count()).ToList();
                    MinPrice   = res.Min(c => c.Price);
                    MaxPrice   = res.Max(c => c.Price);
                    totalcount = res.Count;
                    res        = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
                    break;

                case 4:
                    res = _repository.Product.GetProductListFullInfo()
                          .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) &&
                                 (c.CatProductId == filter.CatProductId || filter.CatProductId == null) &&
                                 (filter.MinPrice <= c.Price || filter.MinPrice == null) &&
                                 (c.Price <= filter.MaxPrice || filter.MaxPrice == null) &&
                                 (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0))
                          .OrderBy(c => c.Price).ToList();
                    MinPrice   = res.Min(c => c.Price);
                    MaxPrice   = res.Max(c => c.Price);
                    totalcount = res.Count;
                    res        = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
                    break;

                case 5:
                    res = _repository.Product.GetProductListFullInfo()
                          .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) &&
                                 (c.CatProductId == filter.CatProductId || filter.CatProductId == null) &&
                                 (filter.MinPrice <= c.Price || filter.MinPrice == null) &&
                                 (c.Price <= filter.MaxPrice || filter.MaxPrice == null) &&
                                 (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0))
                          .OrderByDescending(c => c.Price).ToList();
                    MinPrice   = res.Min(c => c.Price);
                    MaxPrice   = res.Max(c => c.Price);
                    totalcount = res.Count;
                    res        = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
                    break;

                case 6:
                    res = _repository.Product.GetProductListFullInfo()
                          .Where(c => c.MelliFlag == true &&
                                 (filter.ProductName == null || c.Name.Contains(filter.ProductName)) &&
                                 (c.CatProductId == filter.CatProductId || filter.CatProductId == null) &&
                                 (filter.MinPrice <= c.Price || filter.MinPrice == null) &&
                                 (c.Price <= filter.MaxPrice || filter.MaxPrice == null) &&
                                 (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0))
                          .OrderByDescending(c => c.Cdate).ToList();
                    MinPrice   = res.Min(c => c.Price);
                    MaxPrice   = res.Max(c => c.Price);
                    totalcount = res.Count;
                    res        = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
                    break;

                case 7:
                    res = _repository.Product.GetProductListFullInfo()
                          .Where(c => c.UnescoFlag == true &&
                                 (filter.ProductName == null || c.Name.Contains(filter.ProductName)) &&
                                 (c.CatProductId == filter.CatProductId || filter.CatProductId == null) &&
                                 (filter.MinPrice <= c.Price || filter.MinPrice == null) &&
                                 (c.Price <= filter.MaxPrice || filter.MaxPrice == null) &&
                                 (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0))
                          .OrderByDescending(c => c.Cdate).ToList();
                    MinPrice   = res.Min(c => c.Price);
                    MaxPrice   = res.Max(c => c.Price);
                    totalcount = res.Count;
                    res        = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
                    break;

                default:
                    res = _repository.Product.GetProductListFullInfo()
                          .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) &&
                                 (c.CatProductId == filter.CatProductId || filter.CatProductId == null) &&
                                 (filter.MinPrice <= c.Price || filter.MinPrice == null) &&
                                 (c.Price <= filter.MaxPrice || filter.MaxPrice == null) &&
                                 (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0))
                          .OrderByDescending(c => c.Cdate).ToList();
                    MinPrice   = res.Min(c => c.Price);
                    MaxPrice   = res.Max(c => c.Price);
                    totalcount = res.Count;
                    res        = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
                    break;
                }

                ProductListDto result = new ProductListDto
                {
                    MaxPrice    = MaxPrice,
                    MinPrice    = MinPrice,
                    TotalCount  = totalcount,
                    ProductList = _mapper.Map <List <ProductDto> >(res)
                };



                var finalresult = SingleResult <ProductListDto> .GetSuccessfulResult(result);

                return(finalresult);
            }
            catch (Exception e)
            {
                return(SingleResult <ProductListDto> .GetFailResult(null));
            }
        }
Пример #9
0
        public SingleResult <string> VerifyWalletCharge(string authority, string status)
        {
            try
            {
                var wallet = _repository.CustomerWalletCharge.FindByCondition(c => c.TraceNo == authority)
                             .FirstOrDefault();
                if (wallet == null)
                {
                    throw new BusinessException(XError.BusinessErrors.PaymentInfoNotFound());
                }



                var customer = _repository.CustomerOrder.FindByCondition(c => c.Id == wallet.CustomerId)
                               .Include(c => c.Customer).Select(c => c.Customer).First();

                var zarinPalVerifyRequest = new ZarinPalVerifyRequest
                {
                    authority = authority,
                    amount    = (int)wallet.ChargePrice.Value * 10
                };

                var zarinPal = new ZarinPal();
                var result   = zarinPal.VerifyPayment(zarinPalVerifyRequest);
                if (result.code == 100 || result.code == 101)
                {
                    wallet.FinalStatusId = 40;
                    wallet.RefNum        = result.ref_id.ToString();
                    wallet.ChargeDate    = DateTime.Now.Ticks;
                    wallet.BankCard      = result.card_pan;
                    _repository.CustomerWalletCharge.Update(wallet);



                    customer.WalletFinalPrice += wallet.ChargePrice;
                    _repository.Customer.Update(customer);
                    _repository.Save();

                    var sendSms = new SendSMS();
                    sendSms.SendWalletSuccessChargeSms(customer.Mobile.Value, wallet.ChargePrice.ToString(), customer.Name + " " + customer.Name);

                    var finalres = SingleResult <string> .GetSuccessfulResult("عملیات پرداخت با موفقیت انجام شد.");

                    _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, authority, status);
                    return(finalres);
                }
                else
                {
                    wallet.FinalStatusId = 41;
                    wallet.ChargeDate    = DateTime.Now.Ticks;
                    _repository.CustomerWalletCharge.Update(wallet);
                    _repository.Save();

                    throw new BusinessException(XError.BusinessErrors.FailedPayment());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), authority, status);

                return(SingleResult <string> .GetFailResult(e.Message));
            }
        }