示例#1
0
        public async Task<IActionResult> Create(PackageDetailModel model)
        {
            if (ModelState.IsValid)
            {
                var file = model.Image;

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

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

                Package package = new Package
                {
                    Charges = model.Charges,
                    DocumentariesChannel = model.DocumentariesChannel,
                    EntertainmentChannel = model.EntertainmentChannel,
                    ImageUrl = $"/images/package/{parsedContentDisposition.FileName.ToString().Trim('"')}",
                    NewsChannel = model.NewsChannel,
                    NoOfChannels = model.NoOfChannels,
                    PackageName = model.PackageName,
                    SportsChannel = model.SportsChannel
                };

                _context.Add(package);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }
            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> Create([Bind("Id,Question,Answer")] Faq faq)
        {
            if (ModelState.IsValid)
            {
                _context.Add(faq);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(faq));
        }
        public async Task <IActionResult> Create([Bind("Id,OwnerName,ContactNumber,Address,CardNumber,SubscribeDate", "PackageId", "SetBoxId")] CardAddModel model)
        {
            if (ModelState.IsValid)
            {
                CustomerCard customerCard = new CustomerCard()
                {
                    Address       = model.Address,
                    SubscribeDate = model.SubscribeDate,
                    CardNumber    = model.CardNumber,
                    ContactNumber = model.ContactNumber,
                    OwnerName     = model.OwnerName,
                    Package       = await _context.Packages.FirstOrDefaultAsync(p => p.Id == model.PackageId),
                    SetBox        = await _context.SetBoxes.FirstOrDefaultAsync(s => s.Id == model.SetBoxId)
                };
                await _context.CustomerCards.AddAsync(customerCard);

                CustomerPackage cp = new CustomerPackage
                {
                    CustomerCard   = customerCard,
                    NumberOfMonths = 0,
                    ExpirationDate = DateTime.Now,
                    Package        = await _context.Packages.FirstOrDefaultAsync(p => p.Id == model.PackageId),
                    Status         = await _context.Status.SingleOrDefaultAsync(s => s.Name == "Recharged")
                };
                await _context.CustomerPackages.AddAsync(cp);

                NewSetBoxRequest request = new NewSetBoxRequest()
                {
                    Card   = customerCard,
                    Setbox = await _context.SetBoxes.FirstOrDefaultAsync(s => s.Id == model.SetBoxId),
                    Status = await _context.Status.SingleOrDefaultAsync(s => s.Name == "AdminApproved")
                };
                await _context.NewSetBoxRequest.AddAsync(request);

                var Subscriber = await _context.NewSubscribes.
                                 Include(s => s.Package).
                                 Include(s => s.SetBox).
                                 SingleOrDefaultAsync(s => s.Id == model.Id);

                _context.Update(Subscriber);
                Subscriber.Status = await _context.Status.FirstOrDefaultAsync(st => st.Name == "AdminApproved");

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
示例#5
0
        public async Task <int> PlacedOrderAsync(Dealer dealer, Cart cart, Order newOrder, Payment newPayment)
        {
            newOrder.Dealer = dealer;
            newOrder.Status = await _con.Status.SingleOrDefaultAsync(s => s.Name == "Pending");

            newOrder.TotalItems = cart.TotalItems;
            newOrder.TotalPrice = cart.TotalPrice;
            await _con.Orders.AddAsync(newOrder);

            foreach (var item in cart.ItemList)
            {
                OrderDetail orderDetail = new OrderDetail {
                    Order   = newOrder,
                    Product = await _con.SetBoxes.SingleOrDefaultAsync(s => s.Id == item.Product.Id),
                    Price   = item.Price,
                    Qty     = item.Qty
                };
                await _con.OrderDetails.AddAsync(orderDetail);
            }

            newPayment.Dealer = dealer;
            newPayment.Order  = newOrder;
            await _con.Payments.AddAsync(newPayment);

            int result = await _con.SaveChangesAsync();

            if (result > 0)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
示例#6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var newSubscribe = await _context.NewSubscribes.SingleOrDefaultAsync(m => m.Id == id);

            _context.NewSubscribes.Remove(newSubscribe);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#8
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var movieOnDemand = await _context.MoviesOnDemand.SingleOrDefaultAsync(m => m.Id == id);

            _context.MoviesOnDemand.Remove(movieOnDemand);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#9
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var feedBack = await _context.FeedBacks.SingleOrDefaultAsync(m => m.Id == id);

            _context.FeedBacks.Remove(feedBack);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Telephone,Address,City,JoinDate", "Email", "Password")] DealerAddModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser testUser = await _userManager.FindByEmailAsync(model.Email);

                if (testUser == null)
                {
                    ApplicationUser newUser = new ApplicationUser();
                    newUser.Email    = model.Email;
                    newUser.UserName = model.Email;

                    string         pass   = model.Password;
                    IdentityResult result = await _userManager.CreateAsync(newUser, pass);

                    if (result.Succeeded)
                    {
                        await _userManager.AddToRoleAsync(newUser, "Dealer");

                        Dealer dealer = new Dealer()
                        {
                            Address         = model.Address,
                            City            = model.City,
                            FirstName       = model.FirstName,
                            LastName        = model.LastName,
                            JoinDate        = DateTime.Now,
                            Telephone       = model.Telephone,
                            ApplicationUser = newUser
                        };
                        _context.Add(dealer);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                ModelState.AddModelError("testUser", "Already a Member");
                return(View(model));
            }
            return(View(model));
        }