Ejemplo n.º 1
0
 protected void rptPromoDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.IsItem())
     {
         PromoItem currentPromo = e.Item.DataItem as PromoItem;
         if (currentPromo != null)
         {
             Panel pnlImageType = e.FindControlAs <Panel>("pnlImageType");
             if (pnlImageType != null)
             {
                 if (currentPromo.ShowMediaFile.Checked == true)
                 {
                     pnlImageType.CssClass += " video";
                 }
                 HyperLink hlPromoMedia = e.FindControlAs <HyperLink>("hlPromoMedia");
                 if (hlPromoMedia != null)
                 {
                     FieldRenderer frPromoMedia = e.FindControlAs <FieldRenderer>("frPromoMedia");
                     if (frPromoMedia != null)
                     {
                         frPromoMedia.Item = currentPromo;
                     }
                 }
                 FieldRenderer frPromoTitle = e.FindControlAs <FieldRenderer>("frPromoTitle");
                 if (frPromoTitle != null)
                 {
                     frPromoTitle.Item = currentPromo;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public async Task UpdateAsync(PromoItem item)
 {
     _context.PromoItems.Update(item);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 3
0
 public async Task Delete(PromoItem item)
 {
     _context.PromoItems.Remove(item);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 4
0
 public async Task AddAsync(PromoItem item)
 {
     _context.Add(item);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 5
0
 public ActionResult Promotions(PromoItem model)
 {
     return(View());
 }
Ejemplo n.º 6
0
        public async Task <ActionResult <BuyResponse> > BuyItem([FromBody] BuyGoodRequest goodRequest)
        {
            var userId = GetUserId();
            var user   = await _userRepository.GetByEmailAsync(userId);

            var good = await _goodsRepository.GetAsync(goodRequest.Id);

            if (good == null)
            {
                return(new ActionResult <BuyResponse>(new BuyResponse {
                    Msg = "Товар не найден!", IsError = true
                }));
            }

            Serilog.Log.Logger.Information($"UserId={userId} Good={good.Id} Price={good.Cost}");

            if (user.Balance >= good.Cost)
            {
                PromoItem promoItem = null;
                if (good.IsAutoIssuance && good.PromoCategoryId.HasValue)
                {
                    promoItem = await _goodsRepository.PickUpPromoItem(good);
                }

                //user.Balance = user.Balance - good.Cost;
                await _userRepository.Update(user);

                var order = new Order
                {
                    GoodId    = goodRequest.Id,
                    UserId    = user.Id,
                    OrderedAt = DateTime.UtcNow,
                    PromoItem = promoItem,
                };

                if (promoItem != null)
                {
                    order.Completed   = true;
                    order.CompletedAt = DateTime.UtcNow;
                }

                await _orderRepository.AddAsync(order);

                //add user transaction
                await _userScoreRepository.AddAsync(new UserTransaction
                {
                    Score     = -good.Cost,
                    UserId    = user.Id,
                    CreatedAt = DateTime.UtcNow,
                    Type      = TransactionType.GoodBuy
                });

                //var transactions = await _userScoreRepository.GetAllAsync(user.Id);
                //var sum = transactions.Sum(p => p.Score);
                user.Balance -= good.Cost;

                await _userRepository.Update(user);

                if (promoItem != null)
                {
                    return(new ActionResult <BuyResponse>(new BuyResponse {
                        Msg = $"Товар приобретен: {promoItem.Code}", IsAuto = true, PromoCode = promoItem.Code
                    }));
                }
            }
            else
            {
                return(new ActionResult <BuyResponse>(new BuyResponse {
                    Msg = "Не хватает баллов", IsError = true
                }));
            }

            return(new ActionResult <BuyResponse>(new BuyResponse {
                Msg = "Товар приобретен, ждет подтверждения"
            }));
        }