Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("ProductId,AvgRating,CategoryId,Discontinued,Discount,IsDelete,IsNew,Note,Picture,ProductName,ReorderLevel,SupplierId,UnitPrice,UnitsInStock")] Products products, ICollection <IFormFile> files)
        {
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", products.CategoryId);
            ViewData["SupplierId"] = new SelectList(_context.Suppliers, "SupplierId", "CompanyName", products.SupplierId);

            string tempImageURL = "";

            if (ModelState.IsValid)
            {
                var uploads = Path.Combine(_environment.WebRootPath, "Image/products");
                foreach (var file in files)
                {
                    if (file != null)
                    {
                        string URL = uploads + "/" + file.FileName;
                        Bitmap img = convertImage.ResizeImage(Image.FromStream(file.OpenReadStream(), true, true), 600, 600);
                        img.Save(URL);
                        tempImageURL += "~/Image/products/" + file.FileName + ";";
                    }
                }
                products.Discontinued = false;
                products.IsNew        = true;
                products.IsDelete     = false;
                products.AvgRating    = 0;
                products.Picture      = tempImageURL;
                _context.Add(products);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(products));
        }
Esempio n. 2
0
 public IActionResult GetContactInfor([FromBody] Contacts contact)
 {
     if (contact != null)
     {
         _context.Add(contact);
         _context.SaveChanges();
         return(new JsonResult(new { message = "success!" }));
     }
     return(new JsonResult(new { message = "Error!" }));
 }
        public async Task <IActionResult> Create([Bind("ShipperId,CompanyName,Description,Phone")] Shippers shippers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shippers);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(shippers));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("UserId,AvatarPicture,Birthday,CoverPicture,Email,FirstName,IsActive,LastName,Looked,Lpoint,Password,PhoneNumber,ReferUserId,Sex,Token")] Users users)
        {
            if (ModelState.IsValid)
            {
                _context.Add(users);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(users));
        }
        public async Task <IActionResult> Create([Bind("SupplierId,Address,City,CompanyName,ContactName,Country,Fax,HomePage,Phone")] Suppliers suppliers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(suppliers);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(suppliers));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("SupplierId,Address,City,CompanyName,ContactName,Country,Fax,HomePage,Phone")] Suppliers suppliers)
        {
            if (HttpContext.Session.GetString("UserID") == null && HttpContext.Session.GetString("Email") == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(suppliers);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(suppliers));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("ShipperId,CompanyName,Description,Phone")] Shippers shippers)
        {
            if (HttpContext.Session.GetString("UserID") == null && HttpContext.Session.GetString("Email") == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(shippers);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(shippers));
        }