示例#1
0
        public IQueryable <ProductDto> GetAll(Guid?brandId, Guid?categoryRootId, Guid?subCategoryId)
        {
            var result = _repository.AsQuery();

            if (brandId != null)
            {
                result = result.Where(p => p.Brand.Id == brandId);
            }

            if (subCategoryId != null)
            {
                result = result.Where(p => p.Category.Id == subCategoryId);
            }
            else if (categoryRootId != null)
            {
                var category = _categoryRepository.AsQuery().SingleOrDefault(p => p.Id == categoryRootId);
                if (category == null)
                {
                    return(result.ProjectTo <ProductDto>());
                }
                {
                    var subCategory = category.SubCategories.Select(p => p.Id);
                    result = result.Where(p => subCategory.Contains(p.Category.Id));
                }
            }
            return(result.ProjectTo <ProductDto>());
        }
        public IQueryable <IMarketerSalaryPaymentDto> GetAll()
        {
            var marketerSalaryPayment = _repository.AsQuery();
            var result = marketerSalaryPayment.Select(p => new MarketerSalaryPaymentDto
            {
                Id           = p.Id,
                Amount       = p.Amount / 10,
                CreationTime = p.CreationTime,
                Marketer     = new MarketerDto
                {
                    Id                 = p.Marketer.Id,
                    FirstName          = p.Marketer.FirstName,
                    LastName           = p.Marketer.LastName,
                    MaxMarketerAllowed = p.Marketer.MaxMarketerAllowed,
                    CreationTime       = p.Marketer.CreationTime,
                    IsActive           = p.Marketer.IsActive,
                },
                PeriodSalary = new PeriodSalaryDto
                {
                    FromDate = p.PeriodSalary.FromDate,
                    ToDate   = p.PeriodSalary.ToDate
                },
            });

            return(result);
        }
        public IOrderSuggestionDto GetByOrderId(long orderId)
        {
            var      order                    = _orderRepository.Find(orderId);
            var      now                      = DateTime.Now;
            DateTime startDateTime            = DateTime.Today;                         //Today at 00:00:00
            DateTime endDateTime              = DateTime.Today.AddDays(1).AddTicks(-1); //Today at 23:59:59
            var      havePercentDiscountToday = _factorRepository.AsQuery()
                                                .Where(p => p.CreationTime >= startDateTime &&
                                                       p.CreationTime <= endDateTime &&
                                                       p.Customer.Id == order.Customer.Id &&
                                                       p.FactorState == FactorState.Paid)
                                                .SelectMany(p => p.FactorRaws)
                                                .Any(p => p.Discount != null && p.Discount is FactorRawPercentDiscount &&
                                                     p.Discount.FromDate <= now &&
                                                     p.Discount.ToDate >= now &&
                                                     (p.Discount as FactorRawPercentDiscount).FromTime <= now.TimeOfDay &&
                                                     (p.Discount as FactorRawPercentDiscount).ToTime >= now.TimeOfDay);
            //todo autho
            var t = _repository.AsQuery().Where(p => p.OrderId == orderId).ToList();
            var orderSuggestion = _repository.AsQuery().SingleOrDefault(p => p.OrderId == orderId);

            if (!havePercentDiscountToday)
            {
                return(orderSuggestion.ToDo());
            }
            if (orderSuggestion == null)
            {
                return(((OrderSuggestion)null).ToDo());
            }
            foreach (var item in orderSuggestion.OrderSuggestionItems)
            {
                item.OrderItem.Discount = null;
            }
            return(orderSuggestion.ToDo());
        }
示例#4
0
        public IQueryable <CustomerProductSuggestionDto> GetAll()
        {
            var customers          = _personRepository.AsQuery().OfType <Customer>();
            var productSuggestions = _repository.AsQuery();
            var join = productSuggestions.Join(customers, ps => ps.PersonId, s => s.Id, (psu, shop) => new
            {
                ProductSuggestion = psu,
                customer          = shop
            });

            return(join.Select(item => new CustomerProductSuggestionDto
            {
                CreationTime = item.ProductSuggestion.CreationTime,
                Id = item.ProductSuggestion.Id,
                Title = item.ProductSuggestion.Title,
                Description = item.ProductSuggestion.Description,
                ProductSuggestionStatusDescription = item.ProductSuggestion.ProductSuggestionStatusDescription,
                ProductImage = item.ProductSuggestion.ProductImage,
                FullName = item.customer.FirstName + item.customer.LastName,
                ProductSuggestionGroup = new ProductSuggestionGroupDto
                {
                    BrandName = item.ProductSuggestion.ProductSuggestionGroup.BrandName,
                    BrandId = item.ProductSuggestion.ProductSuggestionGroup.BrandId,
                    CategoryId = item.ProductSuggestion.ProductSuggestionGroup.CategoryId,
                    CategoryName = item.ProductSuggestion.ProductSuggestionGroup.CategoryName,
                    CategoryRootId = item.ProductSuggestion.ProductSuggestionGroup.CategoryRootId,
                    CategoryRootName = item.ProductSuggestion.ProductSuggestionGroup.CategoryRootName
                },
                ProductSuggestionStatus = item.ProductSuggestion.ProductSuggestionStatus,
            }));;
        }
示例#5
0
        public IList <IFakeOrderIosDto> GetOrders(FakeOrderIosState?state)
        {
            if (state == null)
            {
                var result = _repository.AsQuery().ToList().Select(p => p.ToDto()).ToList();
                return(result);
            }
            var result1 = _repository.AsQuery().Where(p => p.State == state).ToList().Select(p => p.ToDto()).ToList();

            return(result1);
        }
示例#6
0
        public IDashboardCountDto GetAppInfoCountByCityId(Guid cityId)
        {
            var dashboardCount = new DashboardCountDto
            {
                CustomerActiveCount   = _personRepository.AsQuery().OfType <Customer>().Count(p => p.IsActive && p.DefultCustomerAddress.CityId != null && p.DefultCustomerAddress.CityId == cityId),
                CustomerDeActiveCount = _personRepository.AsQuery().OfType <Customer>().Count(p => !p.IsActive && p.DefultCustomerAddress.CityId != null && p.DefultCustomerAddress.CityId == cityId),
                ShopActiveCount       = _personRepository.AsQuery().OfType <Shop>().Count(p => p.IsActive && p.ShopAddress.CityId == cityId),
                ShopDeActiveCount     = _personRepository.AsQuery().OfType <Shop>().Count(p => p.IsActive == false && p.ShopAddress.CityId == cityId),
                FactorPaidCount       = _factorRepository.AsQuery().Count(p => p.FactorState == FactorState.Paid && p.FactorAddress.CityId == cityId),
                FactorPendingCount    = _factorRepository.AsQuery().Count(p => p.FactorState != FactorState.Paid && p.FactorAddress.CityId == cityId)
            };

            return(dashboardCount);
        }
        public IEnumerable <IShopPositionWithDistanceDto> GetShopsInCustomerAddressArea(Guid userId, Guid customerAddressId)
        {
            var customer = _customerRepository.AsQuery().SingleOrDefault(item => item.UserId == userId);

            if (customer == null)
            {
                throw new DomainException("مشتری یافت نشد");
            }
            var customerAddress = customer.CustomerAddresses.SingleOrDefault(item => item.Id == customerAddressId);

            if (customerAddress == null)
            {
                throw new DomainException("آدرس مشتری یافت نشد");
            }

            var shops = _repository.AsQuery()
                        .Where(item =>
                               item.ShopStatus == ShopStatus.Accept && item.IsActive &&
                               item.ShopAddress.Geography.Distance(customerAddress.Geography) <= item.AreaRadius)
                        .OrderBy(item => item.ShopAddress.Geography.Distance(customerAddress.Geography)).ToList().Select(item =>
                                                                                                                         new ShopPositionWithDistanceDto
            {
                Id       = item.Id,
                Name     = item.Name,
                Distance = item.ShopAddress.Geography.Distance(customerAddress.Geography),
                Position = new PositionDto(item.ShopAddress.Geography.ToPosition().Latitude, item.ShopAddress.Geography.ToPosition().Longitude)
            });

            return(shops);
        }
        public async Task <IList <IShopMarketersHistoryDto> > GetShopMarketers(Guid shopId)
        {
            var result = await _repository.AsQuery().Where(item => item.Shop.Id == shopId)
                         .OrderBy(item => item.CreationTime).ToListAsync();

            return(result.Select(item => item.ToDto()).ToList());
        }
示例#9
0
        public MobilePagingResultDto <IFactorWithShopDto> GetCustomerFactors(Guid userId, PagedInputDto pagedInput)
        {
            var appSetting       = _applicationSettingRepository.AsQuery().FirstOrDefault();
            var factorExpireTime = appSetting?.FactorExpireTime;
            var customer         = _customerRepository.AsQuery().SingleOrDefault(p => p.UserId == userId);

            if (customer == null)
            {
                throw new DomainException("مشتری یافت نشد");
            }
            var expireTime = DateTime.Now.AddMinutes(-appSetting.FactorExpireTime);
            var data       = _repository.AsQuery().Where(p => p.Customer.Id == customer.Id &&
                                                         (p.FactorState == FactorState.Paid ||
                                                          (p.FactorState != FactorState.Paid && p.CreationTime > expireTime)));
            var result = data.OrderByDescending(p => p.CreationTime)
                         .Skip(pagedInput.Skip)
                         .Take(pagedInput.Count)
                         .ToList()
                         .Select(item => item.ToFactorWithShopDto())
                         .ToList();

            foreach (var factorWithCustomer in result)
            {
                var factorExpireTimeDate = factorWithCustomer.CreationTime.AddMinutes((double)factorExpireTime);
                factorWithCustomer.TimeLeft = (int)factorExpireTimeDate.Subtract(DateTime.Now).TotalMinutes;
            }
            return(new MobilePagingResultDto <IFactorWithShopDto>
            {
                Count = data.Count(),
                Result = result
            });
        }
示例#10
0
        public bool CheckUserTodayHavePercentDiscount(Guid userId)
        {
            var customer = _customerRepository.AsQuery().SingleOrDefault(item => item.UserId == userId);

            if (customer == null)
            {
                throw new DomainException("مشتری یافت نشد");
            }
            var      now           = DateTime.Now;
            var      today         = DateTime.Today;
            DateTime startDateTime = DateTime.Today;                         //Today at 00:00:00
            DateTime endDateTime   = DateTime.Today.AddDays(1).AddTicks(-1); //Today at 23:59:59

            return(_factorRepository.AsQuery()
                   .Where(p => p.CreationTime >= startDateTime &&
                          p.CreationTime <= endDateTime &&
                          p.Customer.Id == customer.Id &&
                          p.FactorState == FactorState.Paid)
                   .SelectMany(p => p.FactorRaws)
                   .Any(p => p.Discount != null && p.Discount is FactorRawPercentDiscount &&
                        p.Discount.FromDate <= today &&
                        p.Discount.ToDate >= today &&
                        (p.Discount as FactorRawPercentDiscount).FromTime <= now.TimeOfDay &&
                        (p.Discount as FactorRawPercentDiscount).ToTime >= now.TimeOfDay));
        }
        public async Task <IShopCustomerSubsetReportDto> GetShopCustomerSubsetReport(Guid shopId)
        {
            var appSetting = _applicationSettingRepository.AsQuery().FirstOrDefault();
            var shop       = await _repository.FindAsync(shopId);

            if (shop == null)
            {
                throw new DomainException("فروشگاه یافت نشد");
            }
            var countShopCustomerSubsetNotSettlement =
                shop.CustomerSubsets.Count(p => !p.IsSettlement && !p.HavePaidFactor);
            var countShopCustomerSubsetHaveFactorPaidSumAmount =
                shop.CustomerSubsets.Count(p => !p.IsSettlement && p.HavePaidFactor);

            var result = new ShopCustomerSubsetReportDto
            {
                Count              = shop.CustomerSubsets.Count,
                PaidFactorCount    = shop.CustomerSubsets.Count(p => p.HavePaidFactor),
                SettlementCount    = shop.CustomerSubsets.Count(p => p.IsSettlement),
                NotSettlementCount = shop.CustomerSubsets.Count(p => !p.IsSettlement),
                ShopCustomerSubsetHaveFactorPaidSumAmount = countShopCustomerSubsetHaveFactorPaidSumAmount * appSetting.ShopCustomerSubsetHaveFactorPaidAmount,
                ShopCustomerSubsetSumAmount = countShopCustomerSubsetNotSettlement * appSetting.ShopCustomerSubsetAmount
            };

            return(result);
        }
示例#12
0
        public async Task <IList <IPanelNotificationDto> > GetUnSeenPanelNotification()
        {
            var result = await _repository.AsQuery().OfType <PanelNotification>()
                         .Where(item => !item.IsVisited)
                         .OrderByDescending(item => item.CreationTime).ToListAsync();

            return(result.Select(item => item.ToDto()).ToList());
        }
        public IEnumerable <IShopFactorChart> GetShopDailyCharts(Guid shopId)
        {
            var date      = DateTime.Now;
            var startDate = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
            var factors   = _factorRepository.AsQuery()
                            .Where(p => p.CreationTime >= startDate && p.Shop.Id == shopId && p.FactorState == FactorState.Paid).ToList();
            var shopFactorDailyCharts = new List <ShopFactorChart>();
            var label = 1;

            foreach (var day in EachHours(startDate, date))
            {
                var endDate = day.AddHours(1);
                var shopFactorDailyChart = new ShopFactorChart
                {
                    Label      = Convert.ToString(label),
                    TotalCount = factors.Count(p => p.CreationTime >= day && p.CreationTime <= endDate),
                    TotalSum   = factors.Where(p => p.CreationTime >= day && p.CreationTime <= endDate)
                                 .Sum(p => p.DiscountPrice)
                };
                shopFactorDailyCharts.Add(shopFactorDailyChart);
                label++;
            }

            return(shopFactorDailyCharts);
        }
示例#14
0
        public IQueryable <IShopAcceptorsDto> GetAll()
        {
            var pastDate     = DateTime.Today.AddDays(-15);
            var shopAcceptor = _repository.AsQuery().Where(item => item.CreationTime >= pastDate);
            var result       = shopAcceptor.Select(p => new ShopAcceptorsDto
            {
                id                 = p.Id,
                firstName          = p.FirstName,
                lastName           = p.LastName,
                phoneNumber        = p.PhoneNumber,
                mobileNumber       = p.MobileNumber,
                shopName           = p.ShopName,
                creationTime       = p.CreationTime,
                shopAcceptorStatus = p.ShopAcceptorStatus
            });

            return(result);
        }
        public IQueryable <ShopDto> GetAll()
        {
            var marketers = _marketerRepository.AsQuery();
            var shops     = _repository.AsQuery();
            var join      = shops.GroupJoin(marketers, s => s.MarketerId, m => m.Id,
                                            (shop, marketer) => new
            {
                Shop     = shop,
                Marketer = marketer
            })
                            .SelectMany(x => x.Marketer.DefaultIfEmpty(),
                                        (x, y) => new
            {
                x.Shop,
                Marketer = y
            });

            var result = join
                         .Select(item => new ShopDto
            {
                Id                = item.Shop.Id,
                UserId            = item.Shop.UserId,
                IsActive          = item.Shop.IsActive,
                Description       = item.Shop.Description,
                Name              = item.Shop.Name,
                EmailAddress      = item.Shop.EmailAddress,
                DefaultDiscount   = item.Shop.DefaultDiscount,
                DescriptionStatus = item.Shop.DescriptionStatus,
                FirstName         = item.Shop.FirstName,
                LastName          = item.Shop.LastName,
                NationalCode      = item.Shop.NationalCode,
                ShopStatus        = item.Shop.ShopStatus,
                MobileNumber      = item.Shop.MobileNumber,
                CreationTime      = item.Shop.CreationTime,
                PersonNumber      = item.Shop.PersonNumber,
                HasMarketer       = item.Shop.MarketerId == null,
                MarketerId        = item.Shop.MarketerId,
                Metrage           = item.Shop.Metrage,
                AreaRadius        = item.Shop.AreaRadius,
                MarketerFullName  = item.Marketer.FirstName + " " + item.Marketer.LastName
            });

            return(result);
        }
        public IQueryable <IPublicMessageDto> GetAllPublicMessage()
        {
            var result = _publicMessageRepository.AsQuery()
                         .OrderByDescending(p => p.CreationTime)
                         .Select(item => new PublicMessageDto
            {
                Body              = item.Body,
                CreationTime      = item.CreationTime,
                PublicMessageType = item.PublicMessageType,
                Title             = item.Title,
                UserInfo          = new UserInfoDto
                {
                    UserId    = item.UserInfo.UserId,
                    FirstName = item.UserInfo.FirstName,
                    LastName  = item.UserInfo.LastName
                }
            });

            return(result);
        }
        public IQueryable <IPrivateMessageDto> GetAllPrivateMessageByPersonId(Guid personId)
        {
            var result = _privateMessageRepository.AsQuery()
                         .Where(p => p.PersonId == personId)
                         .OrderByDescending(p => p.CreationTime)
                         .Select(item => new PrivateMessageDto
            {
                Body         = item.Body,
                CreationTime = item.CreationTime,
                Title        = item.Title,
                PersonId     = item.PersonId,
                UserInfo     = new UserInfoDto
                {
                    UserId    = item.UserInfo.UserId,
                    FirstName = item.UserInfo.FirstName,
                    LastName  = item.UserInfo.LastName
                }
            });

            return(result);
        }
        public IList <ICategoryBaseWithImageDto> GetActiveBrandSubCategories(Guid categoryId, Guid brandId)
        {
            var category = _categoryRepository.Find(categoryId);

            if (category == null)
            {
                throw new DomainException("دسته بندی یافت نشد");
            }
            var subCategories = category.SubCategories.Where(item => item.IsActive)
                                .Select(item => item.ToCategoryBaseWithImageDto());
            var result = new List <ICategoryBaseWithImageDto>();

            foreach (var item in subCategories)
            {
                if (_productRepository.AsQuery().Any(p => p.Category.Id == item.Id && p.Brand.Id == brandId))
                {
                    result.Add(item);
                }
            }
            return(result.OrderBy(p => p.Order).ToList());
        }
        public int GetPendingShopOrdersCount(Guid userId)
        {
            var shop = _personRepository.AsQuery().OfType <Shop>().SingleOrDefault(item => item.UserId == userId);

            if (shop == null)
            {
                throw new DomainException("فروشگاه یافت نشد");
            }

            var privateOrdersCount = _orderRepository.AsQuery().OfType <PrivateOrder>().Count(item =>
                                                                                              item.Shop.Id == shop.Id && !item.IsConvertToAreaOrder &&
                                                                                              (item.OrderStatus == OrderStatus.Pending && (DateTime.Now <= item.ExpireOpenTime) ||
                                                                                               (item.OrderStatus == OrderStatus.SelfOpened && DateTime.Now <= item.ResponseExpireTime)));

            var areaOrdersCount = _orderRepository.AsQuery().OfType <AreaOrder>().Count(item =>
                                                                                        item.Shop.Id == shop.Id &&
                                                                                        (item.OrderStatus == OrderStatus.Pending && DateTime.Now <= item.ExpireOpenTime) ||
                                                                                        (item.OrderStatus == OrderStatus.SelfOpened && DateTime.Now <= item.ResponseExpireTime));

            return(privateOrdersCount + areaOrdersCount);
        }
        public IEnumerable <ICategoryBaseWithSubCategoriesDto> GetAll()
        {
            var result = _categoryRepository.AsQuery().OfType <CategoryRoot>().OrderBy(p => p.Order).ToList()
                         .Select(item => item.ToCategoryBaseWithSubCategoriesDto());

            return(result);
        }
        public long CheckHasPendingOrder(Guid userId)
        {
            var customer = _personRepository.AsQuery().OfType <Customer>().SingleOrDefault(p => p.UserId == userId);

            if (customer == null)
            {
                throw new DomainException("کاربر یافت نشد");
            }
            var privateOrder = _privateOrderRepository.AsQuery().OrderByDescending(p => p.CreationTime)
                               .FirstOrDefault(p =>
                                               p.Customer.Id == customer.Id);

            if (privateOrder == null)
            {
                return(0);
            }

            if (privateOrder.OrderStatus == OrderStatus.Pending && privateOrder.ExpireOpenTime >= DateTime.Now)
            {
                return(privateOrder.Id);
            }

            if (privateOrder.OrderStatus == OrderStatus.SelfOpened && privateOrder.ResponseExpireTime >= DateTime.Now)
            {
                return(privateOrder.Id);
            }

            if (privateOrder.IsConvertToAreaOrder)
            {
                var areaOrders = _orderRepository.AsQuery().OfType <AreaOrder>()
                                 .Where(p => p.PrivateOrder.Id == privateOrder.Id);
                if (areaOrders.All(p => p.OrderStatus == OrderStatus.Pending))
                {
                    var areaOrder = areaOrders.FirstOrDefault();

                    if (areaOrder != null && areaOrder.ExpireOpenTime >= DateTime.Now)
                    {
                        return(areaOrder.PrivateOrder.Id);
                    }
                }
                if (areaOrders.Any(p => p.OrderStatus == OrderStatus.SelfOpened))
                {
                    var openAreOrder = areaOrders.FirstOrDefault(p => p.OrderStatus == OrderStatus.SelfOpened);
                    if (openAreOrder != null && openAreOrder.ResponseExpireTime >= DateTime.Now)
                    {
                        return(openAreOrder.PrivateOrder.Id);
                    }
                }
            }
            return(0);
        }
示例#22
0
        public IFactorDto GetLastFactorWithoutComment(Guid userId)
        {
            var factor = _repository.AsQuery().Where(p => p.Customer.UserId == userId &&
                                                     p.ShipmentState == ShipmentState.Delivery)
                         .OrderByDescending(p => p.CreationTime).FirstOrDefault();

            if (factor == null)
            {
                return(null);
            }
            var comment = _commentRepository.AsQuery().SingleOrDefault(p => p.FactorId == factor.Id);

            return(comment == null?factor.ToDto() : null);
        }
        public MobilePagingResultDto <IPrivateMessageDto> GetCustomerPrivateMessageByUserId(Guid userId, PagedInputDto pagedInput)
        {
            var person = _personRepository.AsQuery().OfType <Customer>().SingleOrDefault(p => p.UserId == userId);

            if (person == null)
            {
                throw new DomainException("شخص یافت نشد");
            }
            var data = _privateMessageRepository.AsQuery()
                       .Where(p => p.PersonId == person.Id);
            var result = data.OrderByDescending(p => p.CreationTime)
                         .Skip(pagedInput.Skip)
                         .Take(pagedInput.Count)
                         .ToList()
                         .Select(item => item.ToDto())
                         .ToList();

            return(new MobilePagingResultDto <IPrivateMessageDto>
            {
                Count = data.Count(),
                Result = result
            });
        }
        public IQueryable <IMarketerDto> GetAll()
        {
            var marketers = _repository.AsQuery();
            var shops     = _shopRepository.AsQuery().Where(item => item.IsActive && item.ShopStatus == ShopStatus.Accept);

            var join = marketers.GroupJoin(shops, m => m.Id, s => s.MarketerId,
                                           (mar, sp) => new
            {
                Marketer = mar,
                Shop     = sp
            }).SelectMany(x => x.Shop.DefaultIfEmpty(), (m, s) => new
            {
                m.Marketer,
                ShopCount = m.Shop.Count()
            }).GroupBy(p => p.Marketer.Id)
                       .Select(p => new
            {
                p.FirstOrDefault().Marketer,
                p.FirstOrDefault().ShopCount
            });

            var result = join.Select(item => new MarketerDto
            {
                CreationTime       = item.Marketer.CreationTime,
                Id                 = item.Marketer.Id,
                IsActive           = item.Marketer.IsActive,
                FirstName          = item.Marketer.FirstName,
                LastName           = item.Marketer.LastName,
                MaxMarketerAllowed = item.Marketer.MaxMarketerAllowed,
                SubsetShopCount    = item.ShopCount,
                Image              = item.Marketer.Image,
                BarcodeId          = item.Marketer.BarcodeId
            });

            return(result);
        }
示例#25
0
        public async Task <IAppInfoDto> GetAppInfo(Guid userId, string authDeviceId, AppType appType)
        {
            switch (appType)
            {
            case AppType.Shop:
                var shop = await _repository.AsQuery().OfType <Shop>().SingleOrDefaultAsync(p => p.UserId == userId);

                if (shop == null)
                {
                    throw new DomainException("فروشگاه یافت نشد");
                }
                var appInfo = shop.AppInfos.SingleOrDefault(p => p.AuthDeviceId == authDeviceId);
                if (appInfo == null)
                {
                    throw new DomainException("تنظیمات یافت نشد");
                }
                return(appInfo.ToDto());

            case AppType.Customer:
                var customer = await _repository.AsQuery().OfType <Customer>().SingleOrDefaultAsync(p => p.UserId == userId);

                if (customer == null)
                {
                    throw new DomainException("مشتری یافت نشد");
                }
                var appInfoCustomer = customer.AppInfos.SingleOrDefault(p => p.AuthDeviceId == authDeviceId);
                if (appInfoCustomer == null)
                {
                    throw new DomainException("تنظیمات یافت نشد");
                }
                return(appInfoCustomer.ToDto());

            default:
                throw new DomainException("پارامترهای ارسالی نامعتبر می باشد");
            }
        }
示例#26
0
        public object GetShopRemain(Guid userId, string fromDate, string toDate)
        {
            var shop = _shopRepository.AsQuery().SingleOrDefault(item => item.UserId == userId);

            if (shop == null)
            {
                throw new DomainException("فروشگاه یافت نشد");
            }
            if (shop.Accounting == null)
            {
                throw new DomainException("اطلاعات حسابرسی یافت نشد لطفا با پشتیبانی تماس حاصل فرمایید");
            }
            using (var helper = HttpHelper.Create(ConfigurationManager.AppSettings["AccountingBaseUrl"]))
            {
                var response = helper.Post <object>(ShopStatementServiceName, new ShopStatementServiceRequest
                {
                    ToDate     = toDate,
                    FromDate   = fromDate,
                    RequestId  = Guid.NewGuid(),
                    DetailCode = shop.Accounting.DetailCode
                });
                return(response);
            }
        }
示例#27
0
        public async Task <MobilePagingResultDto <IProductDiscountDto> > GetProductPercentDiscountByIdPaging(Guid percentDiscountId, PagedInputDto pagedInput)
        {
            var percentDiscount = _percentRepository.Find(percentDiscountId);

            if (percentDiscount == null)
            {
                throw new DomainException("تخفیف یافت نشد");
            }
            if (!(percentDiscount.FromDate <= DateTime.Today &&
                  percentDiscount.ToDate >= DateTime.Today))
            {
                throw new DomainException("تخفیف در این بازه زمانی روز موجود نمی باشد");
            }
            if (!(percentDiscount.FromTime <= DateTime.Now.TimeOfDay &&
                  percentDiscount.ToTime >= DateTime.Now.TimeOfDay))
            {
                throw new DomainException("تخفیف در این بازه زمانی ساعت موجود نمی باشد");
            }
            if (percentDiscount.RemainOrderCount <= 0)
            {
                throw new DomainException("تخفیف در این بازه زمانی ساعت موجود نمی باشد");
            }
            var data = _percentRepository.AsQuery().Where(item => item.Id == percentDiscountId)
                       .SelectMany(item => item.ProductDiscounts);
            var result = await data.OrderByDescending(p => p.CreationTime)
                         .Skip(pagedInput.Skip)
                         .Take(pagedInput.Count)
                         .ToListAsync();

            return(new MobilePagingResultDto <IProductDiscountDto>
            {
                Result = result.Select(item => item.ToDto())
                         .ToList(),
                Count = data.Count()
            });
        }
        public MobilePagingResultDto <IOrderFactorDto> GetCustomerOrdersByUserId(Guid userId, PagedInputDto pagedInput)
        {
            var setting  = _settingRepository.AsQuery().FirstOrDefault();
            var customer = _personRepository.AsQuery().OfType <Customer>().SingleOrDefault(p => p.UserId == userId);

            if (customer == null)
            {
                throw new DomainException("مشتری یافت نشد");
            }
            var privateOrders = _orderRepository.AsQuery().OfType <PrivateOrder>()
                                .Where(p => p.Customer.Id == customer.Id);
            var factors      = _factorRepository.AsQuery().Where(p => p.Customer.Id == customer.Id);
            var orderFactors = privateOrders.GroupJoin(
                factors,
                o => o.Id,
                f => f.OrderId,
                (order, factor) => new { Order = order, Factors = factor })
                               .SelectMany(item => item.Factors.DefaultIfEmpty(),
                                           (order, factor) => new { order.Order, Factor = factor });

            var result = orderFactors.OrderByDescending(p => p.Order.CreationTime)
                         .Skip(pagedInput.Skip)
                         .Take(pagedInput.Count)
                         .ToList()
                         .Select(p => new OrderFactorDto
            {
                Factor = p.Factor.ToFactorDto(),
                Order  = p.Order.ToOrderBaseFullInfoDto()
            })
                         .ToList();

            foreach (var item in result)
            {
                if (item.Factor != null)
                {
                    var expireTime           = DateTime.Now.AddMinutes(-setting.FactorExpireTime);
                    var factorExpireTimeDate = item.Factor.CreationTime.AddMinutes((double)setting.FactorExpireTime);
                    item.Factor.TimeLeft = (int)factorExpireTimeDate.Subtract(DateTime.Now).TotalMinutes;

                    item.Factor.IsExpired = item.Factor.CreationTime <= expireTime;
                }
            }
            return(new MobilePagingResultDto <IOrderFactorDto>
            {
                Count = orderFactors.Count(),
                Result = result
            });
        }
示例#29
0
        public IList <IBrandDto> GetActiveCategoryBrands(Guid categoryId)
        {
            var category = _categoryBaseRepository.Find(categoryId);

            if (category == null)
            {
                throw new DomainException("دسته بندی یافت نشد");
            }
            var categoryProducts = _productRepository.AsQuery().Where(p => p.Category.Id == category.Id);
            var brands           = categoryProducts.GroupBy(p => p.Brand).Where(item => item.Key.IsActive).Select(item => new
            {
                item.Key
            }).ToList().Select(item => item.Key.ToDto()).ToList();

            return(brands);
        }
        public IQueryable <PromoterDto> GetAll()
        {
            var result = _repository.AsQuery().Select(item => new PromoterDto
            {
                Id                  = item.Id,
                MobileNumber        = item.MobileNumber,
                NationalCode        = item.NationalCode,
                Code                = item.Code,
                LastName            = item.LastName,
                FirstName           = item.FirstName,
                CustomerSubsetCount = item.CustomerSubsetCount,
                CustomerSubsetHavePaidFactorCount = item.CustomerSubsets.Count(p => p.HavePaidFactor)
            });

            return(result);
        }