public bool Create(PromotionCreateRequest entity)
        {
            string   description = entity.Description;
            DateTime beginDate   = entity.BeginDate;
            DateTime expiredDate = entity.ExpiredDate;

            if (!util.ValidRangeLengthInput(description, 1, 250) ||
                beginDate == null ||
                expiredDate == null ||
                beginDate.CompareTo(expiredDate) >= 0)
            {
                return(false);
            }

            Promotion existed = _proRepo.GetAll()
                                .FirstOrDefault(e => e.Description.Trim().ToLower().Equals(description.Trim().ToLower()));

            if (existed != null)
            {
                return(false);
            }
            Promotion newEntity = new Promotion();

            newEntity.Description = description.Trim();
            newEntity.BeginDate   = beginDate;
            newEntity.BrandId     = entity.BrandId;

            return(_proRepo.Create(newEntity));
        }
Esempio n. 2
0
        public ActionResult List(PagerRequest request, BannerSearchOption search)
        {
            int totalCount;
            var linq = _bannerRepo.Get(e => (!search.PromotionId.HasValue || (e.SourceId == search.PromotionId.Value && e.SourceType == (int)SourceType.Promotion)) &&
                                       (!search.Status.HasValue || e.Status == (int)search.Status.Value) &&
                                       e.Status != (int)DataStatus.Deleted
                                       , out totalCount
                                       , request.PageIndex
                                       , request.PageSize
                                       , e =>
            {
                if (!search.OrderBy.HasValue)
                {
                    return(e.OrderByDescending(o => o.CreatedDate));
                }
                else
                {
                    switch (search.OrderBy.Value)
                    {
                    case GenericOrder.OrderByCreateUser:
                        return(e.OrderByDescending(o => o.CreatedUser));

                    case GenericOrder.OrderByCreateDate:
                    default:
                        return(e.OrderByDescending(o => o.CreatedDate));
                    }
                }
            });

            var linq_All = linq.Join(_proRepo.GetAll(),
                                     o => o.SourceId,
                                     i => i.Id,
                                     (o, i) => new { B = o, P = i })
                           .GroupJoin(_resourceRepo.Get(r => r.SourceType == (int)SourceType.BannerPromotion),
                                      o => o.B.Id,
                                      i => i.SourceId,
                                      (o, i) => new { B = o.B, P = o.P, R = i.FirstOrDefault() });
            var vo = from l in linq_All.ToList()
                     select new BannerViewModel()
            {
                Id         = l.B.Id,
                SourceId   = l.B.SourceId,
                SourceType = l.B.SourceType,
                Resource   = MappingManager.ResourceViewMapping(l.R),
                Promotion  = MappingManager.PromotionViewMapping(l.P),
                SortOrder  = l.B.SortOrder,
                Status     = l.B.Status
            };

            var v = new BannerCollectionViewModel(request, totalCount)
            {
                Banners = vo.ToList()
            };

            ViewBag.SearchOptions = search;
            return(View("List", v));
        }
        public IEnumerable <Promotion> GetAll(int count)
        {
            var result = _promotionRepository.GetAll();

            if (result.Count() > count)
            {
                return(result.Reverse().Take(count).Reverse());
            }
            return(result);
        }
Esempio n. 4
0
        public void AddProdut(string prodName, int quanity)
        {
            IProductModel productmodel = Factorypattern.GetProduct();

            productmodel.Product   = _productRepository.Get(prodName);
            productmodel.Quanity   = quanity;
            productmodel.Promotion = _promotionRepository.GetAll().FirstOrDefault(p => p.Products.Contains(productmodel.Product));

            cart.Add(productmodel);
        }
Esempio n. 5
0
 public async Task <IActionResult> LoadBox(int type = 1)
 {
     try
     {
         var AllPromotions = ((List <PromotionBoxModel>)(await _promotionrepo.GetAll()).Data).Where(x => x.B_Type == type).ToList();
         return(new JsonResult(ResponseModel.Success(data: AllPromotions)));
     }
     catch (Exception ex)
     {
         return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Juice of the program.
        /// </summary>
        public void CalculatePromotions()
        {
            //set sub total and total first
            calculateSubTotal();

            var allPromos = _promotionRepository.GetAll();

            //In real life we will filter promotions by date range.

            foreach (Promotion reward in allPromos)
            {
                //Get the combined dataset of Bucket and Basket. Make sure all products in Bucket has matched.
                var combo = from b in reward.BucketList
                            join l in _basketList on b.ProductTitle.ToUpper() equals l.ProductTitle.ToUpper()
                                where l.Quantity >= b.Quantity
                            select new { b.ProductTitle, b.Discount, b.Operator, b.Quantity, l.LinePrice, discountQualificationRatio = Math.Floor((decimal)l.Quantity / b.Quantity) };
                //full bucket with basket match check
                var fullBucketMatch = !reward.BucketList.Select(b => b.ProductTitle).Except(combo.Select(c => c.ProductTitle)).Any();
                var discountScale   = combo.Count() > 0 && fullBucketMatch?combo.Min(c => c.discountQualificationRatio) : 0;

                foreach (var line in combo)
                {
                    var absoluteDiscount = 0.0m;
                    switch (line.Operator)
                    {
                    case DiscountOperator.Fraction:
                        absoluteDiscount = line.LinePrice * line.Discount * line.Quantity * discountScale;
                        break;

                    case DiscountOperator.Absolute:
                        absoluteDiscount = line.Discount * discountScale;
                        break;

                    case DiscountOperator.ItemReduction:
                        absoluteDiscount = line.LinePrice * line.Discount * discountScale;
                        break;
                    }
                    _total = _total - absoluteDiscount;
                }
            }
        }
Esempio n. 7
0
 public IEnumerable <Promotion> GetAll()
 {
     return(_promotionRepository.GetAll());
 }
Esempio n. 8
0
 public string GetAll(int page)
 {
     return(_repo.GetAll(page));
 }
Esempio n. 9
0
 public IEnumerable <Promotion> GetAlls()
 {
     return(_promotion.GetAll(null));
 }
Esempio n. 10
0
 public IActionResult GetAll()
 {
     return(Ok(_promotionRepository.GetAll()));
 }
Esempio n. 11
0
        public ActionResult List(CouponInfoGetListRequest request, int?authuid, UserModel authUser)
        {
            request.AuthUid  = authuid.Value;
            request.AuthUser = authUser;
            if (request == null)
            {
                return new RestfulResult {
                           Data = new ExecuteResult <CouponInfoResponse>(null)
                }
            }
            ;
            var linq = _couponRepo.Get(c => c.User_Id == authUser.Id && c.Status != (int)CouponStatus.Deleted);

            if (request.Type.HasValue)
            {
                switch (request.Type.Value)
                {
                case CouponRequestType.Used:
                    linq = linq.Where(c => c.Status == (int)CouponStatus.Used);
                    break;

                case CouponRequestType.Expired:
                    linq = linq.Where(c => c.Status != (int)CouponStatus.Used && c.ValidEndDate < DateTime.Now);
                    break;

                case CouponRequestType.UnUsed:
                    linq = linq.Where(c => c.Status != (int)CouponStatus.Used && c.ValidEndDate >= DateTime.Now);
                    break;
                }
            }
            int totalCount = linq.Count();
            int skipCount  = request.Page > 0 ? (request.Page - 1) * request.Pagesize : 0;

            linq = linq.OrderByDescending(c => c.CreatedDate).Skip(skipCount).Take(request.Pagesize);
            var productLinq   = _productRepo.GetAll().Join(_storeRepo.GetAll(), o => o.Store_Id, i => i.Id, (o, i) => new { Pd = o, S = i });
            var promotionLinq = _promotionRepo.GetAll().Join(_storeRepo.GetAll(), o => o.Store_Id, i => i.Id, (o, i) => new { Pr = o, S = i });
            var linq2         = linq.GroupJoin(productLinq, o => o.FromProduct, i => i.Pd.Id, (o, i) => new { C = o, Pd = i.FirstOrDefault() })
                                .GroupJoin(promotionLinq, o => o.C.FromPromotion, i => i.Pr.Id, (o, i) => new { C = o.C, Pd = o.Pd, Pr = i.FirstOrDefault() });
            var responseData = from l in linq2.ToList()
                               select new CouponInfoResponse().FromEntity <CouponInfoResponse>(l.C,
                                                                                               c => {
                var prod = l.Pd;
                if (prod != null)
                {
                    c.ProductInfoResponse = new ProductInfoResponse().FromEntity <ProductInfoResponse>(prod.Pd, p => {
                        p.StoreInfoResponse = new StoreInfoResponse().FromEntity <StoreInfoResponse>(prod.S);
                    });
                    c.ProductId          = c.ProductInfoResponse.Id;
                    c.ProductName        = c.ProductInfoResponse.Name;
                    c.ProductDescription = c.ProductInfoResponse.Description;
                    c.ProductType        = (int)SourceType.Product;
                }
                var pro = l.Pr;
                if (pro != null)
                {
                    c.PromotionInfoResponse = new PromotionInfoResponse().FromEntity <PromotionInfoResponse>(pro.Pr, p => {
                        p.StoreInfoResponse = new StoreInfoResponse().FromEntity <StoreInfoResponse>(pro.S);
                    });
                    c.ProductId          = c.PromotionInfoResponse.Id;
                    c.ProductName        = c.PromotionInfoResponse.Name;
                    c.ProductDescription = c.PromotionInfoResponse.Description;
                    c.ProductType        = (int)SourceType.Promotion;
                }
            });
            var response = new CouponInfoCollectionResponse(request.PagerRequest, totalCount)
            {
                CouponInfoResponses = responseData.ToList()
            };

            return(new RestfulResult {
                Data = new ExecuteResult <CouponInfoCollectionResponse>(response)
            });
        }
Esempio n. 12
0
        public List <Promotion> GetAll()
        {
            List <Promotion> promotions = _promotionRepository.GetAll().ToList();

            return(promotions);
        }
Esempio n. 13
0
 public async Task <IEnumerable <Promotion> > GetAll()
 {
     return(await promotionRepository.GetAll());
 }
Esempio n. 14
0
        public async Task <Order> CreateOrderAsync(OrderAddViewModel orderAddVM)
        {
            Order order = new Order()
            {
                ContactPhone = orderAddVM.ContactPhone,
                CreateDate   = DateTime.Now,
                CusName      = orderAddVM.CusName,
                Description  = orderAddVM.Description,
                ShipAddress  = orderAddVM.ShipAddress,
                ShipDate     = orderAddVM.ShipDate,
                State        = "pending",
                DiscountCode = orderAddVM.DiscountCode,
                Sum          = 0,
                Total        = 0
            };

            order = _orderRepository.Add(order);

            OrderDetail orderDetail = null;

            foreach (var odd in orderAddVM.OrderDetailAdds)
            {
                ShoesHasSize shoesHasSize = _shoesHasSizeRepository.GetAll()
                                            .Where(h => h.SizeId == odd.SizeId && h.ShoesId == odd.ShoesId).FirstOrDefault();
                if (shoesHasSize != null)
                {
                    if (shoesHasSize.Quantity >= odd.Quantity)
                    {
                        orderDetail = new OrderDetail()
                        {
                            OrderId  = order.Id,
                            Quantity = odd.Quantity,
                            ShoesId  = odd.ShoesId,
                            SizeId   = odd.SizeId
                        };

                        _orderDetailRepository.Add(orderDetail);

                        double price = _shoesRepository.GetById(odd.ShoesId.Value).Price.Value;
                        order.Sum             += price * odd.Quantity;
                        shoesHasSize.Quantity -= odd.Quantity.Value;
                        _shoesHasSizeRepository.Update(shoesHasSize);

                        if (shoesHasSize.Quantity == 0)
                        {
                            Shoes shoes = _shoesRepository.GetById(odd.ShoesId.Value);
                            shoes.IsAvaiable = false;
                            _shoesRepository.Update(shoes);
                        }
                    }
                }
            }

            order.Total = order.Sum;
            if (order.DiscountCode != "")
            {
                order.Discount = _promotionRepository.GetAll()
                                 .Where(p => p.DiscountCode == order.DiscountCode).FirstOrDefault().Discount;
                order.Total -= order.Sum * order.Discount / 100;
            }

            if (order.Total == 0)
            {
                _orderRepository.Delete(order);
                return(null);
            }
            else
            {
                order = _orderRepository.Update(order);
                OrderViewModel orderVM = _mapper.Map <OrderViewModel>(order);
                FirebaseSerivce <OrderViewModel> firebaseSerivce = new FirebaseSerivce <OrderViewModel>();
                await firebaseSerivce.SetDataAsync("orders", orderVM);
            }

            return(order);
        }
 // GET api/promotion
 public IEnumerable<Promotion> GetAllPromotions()
 {
     return repo.GetAll();
 }
Esempio n. 16
0
 public ResultMessage <ICollection <Promotion> > GetAll(Expression <Func <Promotion, bool> > filter = null)
 {
     return(_promotionRepository.GetAll(filter));
 }