예제 #1
0
        public async Task <IActionResult> Create([Bind("CustomerId,FirstName,LastName,Phone,Email,AddressId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"] = new SelectList(_context.GeneralAddress, "AddressId", "City", customer.AddressId);
            return(View(customer));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("OrderId,CustomerId,OrderDate,DeliveryAddressId,StoreId,DiscountCode,PaymentId,OrderStatus")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"]        = new SelectList(_context.Customer, "CustomerId", "Email", order.CustomerId);
            ViewData["DeliveryAddressId"] = new SelectList(_context.DeliveryAddress, "DeliveryAddressId", "Email", order.DeliveryAddressId);
            ViewData["DiscountCode"]      = new SelectList(_context.Discount, "DiscountCode", "DiscountCode", order.DiscountCode);
            ViewData["PaymentId"]         = new SelectList(_context.Payment, "PaymentId", "PaymentId", order.PaymentId);
            ViewData["StoreId"]           = new SelectList(_context.Store, "StoreId", "City", order.StoreId);
            return(View(order));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,BrandId,Description,ProductPrice,ProductImage,Origin,InStock,CategoryId,ProductDiscountPercent")] Product product, IFormFile ProductImage)
        {
            if (ModelState.IsValid)
            {
                if (ProductImage.Length > 0)
                {
                    var ms = new MemoryStream();
                    ProductImage.CopyTo(ms);
                    var bytes = ms.ToArray();
                    product.ProductImage = Convert.ToBase64String(bytes);
                }
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]    = new SelectList(_context.Brand, "BrandId", "BrandName", product.BrandId);
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", product.CategoryId);

            return(View(product));
        }