コード例 #1
0
        public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("StatusId,StatusName")] Status status)
        {
            if (ModelState.IsValid)
            {
                _context.Add(status);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(status));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("ParamId,ParamName")] Param @param)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@param);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@param));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("CompanyId,CompanyName,CompanyHeadquarters,CompanyNIP")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(company));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("PhotoId,PhotoUrl")] Photo photo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(photo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(photo));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("AssortmentId,AssortmentName,AssortmentBrand,AssortmentPrice,ParamId")] Assortment assortment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(assortment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ParamId"] = new SelectList(_context.Params, "ParamId", "ParamName", assortment.ParamId);
            return(View(assortment));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("LeasingId,LeasingStart,LeasingEnd,LeasingExtend,Id")] Leasing leasing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(leasing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Id"] = new SelectList(_context.ApplicationUsers, "Id", "Id", leasing.Id);
            return(View(leasing));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,ProductDescription,ProductPrice,ProductAvailability,ProductCode,ProductAdded,CategoryId")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", product.CategoryId);
            return(View(product));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("ReportId,ReportDescription,ReportAdded,LeasingDetailId,StatusId")] Report report)
        {
            if (ModelState.IsValid)
            {
                _context.Add(report);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LeasingDetailId"] = new SelectList(_context.LeasingDetails, "LeasingDetailId", "LeasingDetailId", report.LeasingDetailId);
            ViewData["StatusId"]        = new SelectList(_context.Statuses, "StatusId", "StatusName", report.StatusId);
            return(View(report));
        }
コード例 #10
0
        public async Task <IActionResult> Leasing()
        {
            List <ShoppingCart> cart = SessionHelper.GetObjectFromJson <List <ShoppingCart> >(HttpContext.Session, "cart");

            var id = _userManager.GetUserId(User);

            try
            {
                Leasing l = new Leasing
                {
                    LeasingStart = DateTime.Now,
                    Id           = id
                };
                _context.Add(l);

                LeasingDetail ld;

                foreach (var item in cart)
                {
                    ld = new LeasingDetail
                    {
                        LeasingId           = l.LeasingId,
                        LeasingDetailAmount = item.Quantity,
                        LeasingDetailExtend = true,
                        LeasingDetailEnd    = DateTime.Now.AddYears(1),
                        ProductId           = item.Product.ProductId
                    };
                    var product = _context.Products.Where(p => p.ProductId == item.Product.ProductId).ToList();
                    foreach (var prod in product)
                    {
                        prod.ProductAvailability -= item.Quantity;
                    }

                    _context.Add(ld);
                }

                SmtpClient client = new SmtpClient();
                client.Host                  = "smtp.gmail.com";
                client.Port                  = 587;
                client.EnableSsl             = true;
                client.UseDefaultCredentials = false;
                client.Credentials           = new NetworkCredential("*****@*****.**", "dup@1234");

                var user = await _userManager.GetUserAsync(User);

                var email = user.Email;

                MailMessage mailMessage = new MailMessage();
                mailMessage.From = new MailAddress("*****@*****.**");
                mailMessage.To.Add(email);
                mailMessage.Body    = "Order no. " + l.LeasingId;
                mailMessage.Subject = "Your order is completed. Please pay your bill.";
                mailMessage.Attachments.Add(new Attachment(@"C:\PDF\Leasing.pdf"));
                client.Send(mailMessage);

                _context.SaveChanges();
            }
            catch
            {
                ViewBag.ErrorMessage = "Your cart can't be empty";
                return(RedirectToAction("Index", "Leasings", new { id = _context.Leasings.Last().LeasingId }));
            }

            cart = null;
            SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);

            return(RedirectToAction("Index", "Leasings"));
        }