예제 #1
0
        public IActionResult MyPackage()
        {
            CustomerCard    card    = _cardService.GetCurrentUserCard(_userManager.GetUserId(HttpContext.User));
            Package         package = _packageService.GetById(card.Package.Id);
            SetBox          SetBox  = _sbService.GetById(card.SetBox.Id);
            Customer        cus     = _cusService.GetByUser(_userManager.GetUserId(HttpContext.User));
            DateTime        expire  = _cpService.GetExpirationTime(cus.Id);
            CustomerPackage cp      = _cpService.GetByCardId(card.Id);

            string status = UpdatePakageStatus(cp, expire);

            MyPackageViewModel model = new MyPackageViewModel
            {
                MyPackage = new PackageDetailViewModel
                {
                    PackageName  = package.PackageName,
                    NoOfChannels = package.NoOfChannels,
                    Charges      = package.Charges,
                    ImageUrl     = package.ImageUrl
                },
                MySetBox = new SetBoxDetailModel
                {
                    Name          = SetBox.Name,
                    Specification = SetBox.Specification,
                    Price         = SetBox.Price,
                    ImageUrl      = SetBox.ImageUrl
                },
                GetExpiration = expire,
                State         = status
            };

            return(View(model));
        }
예제 #2
0
        public async Task<IActionResult> Create([Bind("Name,Specification,Price,Image")] SetboxDetailModel model)
        {
            if (ModelState.IsValid)
            {
                var file = model.Image;

                var parsedContentDisposition =
                    ContentDispositionHeaderValue.Parse(file.ContentDisposition);
                var filename = Path.Combine(_hostingEnvironment.WebRootPath,
                    "images","setbox", parsedContentDisposition.FileName.ToString().Trim('"'));

                using (var stream = System.IO.File.OpenWrite(filename))
                {
                    await file.CopyToAsync(stream);
                }

                SetBox setBox = new SetBox()
                {
                    Name = model.Name,
                    ImageUrl =$"/images/setbox/{parsedContentDisposition.FileName.ToString().Trim('"')}",
                    Price = model.Price,
                    Specification = model.Specification

                };

                _context.Add(setBox);
                await _context.SaveChangesAsync();

                return RedirectToAction(nameof(Index));
            }
            return View(model);
        }
예제 #3
0
        public async Task<IActionResult> Edit(int id, [Bind("Id,Name,Specification,Price,ImageUrl")] SetBox model)
        {
            if (id != model.Id)
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(model);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SetBoxExists(model.Id))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return RedirectToAction(nameof(Index));
            }
            return View(model);
        }
예제 #4
0
        public IActionResult AddToCart(int Id, int qty)
        {
            List <CartItem> CartItems;
            var             CartSession = HttpContext.Session.GetString("Cart");
            Cart            Cart;

            if (CartSession == null)
            {
                Cart      = new Cart();
                CartItems = new List <CartItem>();
            }
            else
            {
                Cart      = JsonConvert.DeserializeObject <Cart>(HttpContext.Session.GetString("Cart"));
                CartItems = Cart.ItemList;
            }

            SetBox sb = _setBoxService.GetById(Id);

            if (CartItems.Any(i => i.Product.Name == sb.Name))
            {
                CartItems.SingleOrDefault(i => i.Id == Id).Qty   += qty;
                CartItems.SingleOrDefault(i => i.Id == Id).Price += (qty * sb.Price);
            }
            else
            {
                CartItem item = new CartItem
                {
                    Id      = ++CartItemId,
                    Product = sb,
                    Qty     = qty,
                    Price   = qty * sb.Price
                };

                CartItems.Add(item);
            }
            Cart.ItemList   = CartItems;
            Cart.TotalPrice = Cart.ItemList.Sum(m => m.Price);
            Cart.TotalItems = Cart.ItemList.Sum(m => m.Qty);

            HttpContext.Session.SetString("Cart", JsonConvert.SerializeObject(Cart));
            return(RedirectToAction("Index"));
        }
예제 #5
0
 public void AddSetBox(SetBox newDevice)
 {
     _context.SetBoxes.Add(newDevice);
 }