Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CategroyName")] Category category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,HomePhoneNo,MobileNo,Email")] Supplier supplier)
        {
            if (id != supplier.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(supplier);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SupplierExists(supplier.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
        public async Task <IActionResult> EnableDisable(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var order = await _context.Orders.SingleOrDefaultAsync(m => m.OrderId == id);

            if (order == null)
            {
                return(NotFound());
            }
            order.OrderStatus = !order.OrderStatus;
            _context.Update(order);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public async Task <IActionResult> EnableDisable(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            IEnumerable <ApplicationUser> members = ReturnAllMembers().Result;
            ApplicationUser member = (ApplicationUser)members.Single(u => u.Id == id);

            if (member == null)
            {
                return(NotFound());
            }
            member.Enabled = !member.Enabled;
            _context.Update(member);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryId,SupplierId,ProductName,ProductPrice,ProductImage, Description")] Product product, IFormFile uploadFile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (uploadFile != null)
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await uploadFile.CopyToAsync(memoryStream);

                            product.ProductImage = memoryStream.ToArray();
                        }
                    }


                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PopulateCategoryDropDown(product.CategoryId);
            PopulateSupplierDropDown(product.SupplierId);
            return(View(product));
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryId,SupplierId,ProductName,ProductPrice,ProductImage, Description")] Product product, IFormFile uploadFile)
        {
            /*
             * var relativeName = "";
             * var fileName = "";
             *
             * if (id != product.Id)
             * {
             *  return NotFound();
             * }
             *
             * if (uploadFile != null && uploadFile.Length > 0)
             * {
             *  fileName = ContentDispositionHeaderValue.Parse(uploadFile.ContentDisposition).FileName.Trim('"');
             *  relativeName = "/ProductImages/" + DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName;
             *  using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
             *  {
             *      await uploadFile.CopyToAsync(fs);
             *      fs.Flush();
             *  }
             * } else {
             *  relativeName = product.ProductImage;
             * }
             *
             * product.ProductImage = relativeName;
             */


            if (ModelState.IsValid)
            {
                try
                {
                    if (uploadFile != null)
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await uploadFile.CopyToAsync(memoryStream);

                            product.ProductImage = memoryStream.ToArray();
                        }
                    }


                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PopulateCategoryDropDown(product.CategoryId);
            PopulateSupplierDropDown(product.SupplierId);
            return(View(product));
        }