예제 #1
0
        public async Task <IActionResult> Create([Bind("Amount,CreatedDate,Id")] Invoice invoice)
        {
            if (ModelState.IsValid)
            {
                invoice.Id = Guid.NewGuid();
                _context.Add(invoice);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(invoice));
        }
        public async Task <IActionResult> Create([Bind("Surname,Name,Phone,Passport,SecondName,Email,CreatedDate,Id")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.Id = Guid.NewGuid();
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("CategoryId,Price,ImageLink,CreatedDate,Id")] Kit kit)
        {
            if (ModelState.IsValid)
            {
                kit.Id = Guid.NewGuid();
                _context.Add(kit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", kit.CategoryId);
            return(View(kit));
        }
        public async Task <IActionResult> Create([Bind("KitId,Name,Value,CreatedDate,Id")] Description description)
        {
            if (ModelState.IsValid)
            {
                description.Id = Guid.NewGuid();
                _context.Add(description);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KitId"] = new SelectList(_context.Kits, "Id", "Id", description.KitId);
            return(View(description));
        }
        public async Task <IActionResult> Create([Bind("KitId,OrderId,Quantity,CreatedDate,Id")] OrderItem orderItem)
        {
            if (ModelState.IsValid)
            {
                orderItem.Id = Guid.NewGuid();
                _context.Add(orderItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KitId"]   = new SelectList(_context.Kits, "Id", "Id", orderItem.KitId);
            ViewData["OrderId"] = new SelectList(_context.Orders, "Id", "Id", orderItem.OrderId);
            return(View(orderItem));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("InvoiceId,AccountId,Quantity,Status,CreatedDate,Id")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.Id = Guid.NewGuid();
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["AccountId"] = new SelectList(_context.Accounts, "Id", "Id", order.AccountId);
            //ViewData["InvoiceId"] = new SelectList(_context.Invoices, "Id", "Id", order.InvoiceId);
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("Name,Description,Price,CategoryId")] Computer product,
                                                 int amountInStock, [FromForm(Name = "imageFile")] IFormFile imageFile)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;

                string extension = Path.GetExtension(imageFile.FileName);

                bool isImage = extension == ".jpg" || extension == ".jpeg" || extension == ".png";

                if (imageFile != null)
                {
                    if (isImage)
                    {
                        string uploadFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + imageFile.FileName;
                        string filePath = Path.Combine(uploadFolder, uniqueFileName);
                        imageFile.CopyTo(new FileStream(filePath, FileMode.Create));

                        product.Image = uniqueFileName;
                    }
                    else
                    {
                        ViewData["ErrorMessage"] = "Image file must have .jpg, .jpeg or .png file extension";

                        return(View(product));
                    }
                }
                _context.Add(product);
                await _context.SaveChangesAsync();

                //StockItem stockItem = new StockItem()
                //{
                //    ProductId = product.Id,
                //    AmountInStock = amountInStock
                //};

                //await _apiClient.ApiStockPostAsync(stockItem);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }