public async Task <IActionResult> Create([Bind(include: "Name, Price,DiscountPrice, Photo")] NewArrival newArrival)
        {
            if (!ModelState.IsValid)
            {
                return(View(newArrival));
            }

            if (newArrival.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo can't be null...");
                return(View(newArrival));
            }

            if (!newArrival.Photo.isImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid...");
                return(View(newArrival));
            }

            newArrival.Image = await newArrival.Photo.SaveAsync(_env.WebRootPath, "images", "asbabphotos");

            newArrival.Date = DateTime.Now;

            _context.NewArrivals.Add(newArrival);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "NewArrival"));
        }
        public async Task <IActionResult> Edit(int id, [Bind(include: "Name, Price,DiscountPrice, Photo")] NewArrival newArrival)
        {
            if (!ModelState.IsValid)
            {
                return(View(newArrival));
            }

            var newArrivalBefore = _context.NewArrivals.Find(id);

            if (newArrival.Photo != null)
            {
                if (!newArrival.Photo.isImage())
                {
                    ModelState.AddModelError("Photo", "Photo type is not valid...");
                    return(View(newArrival));
                }
                //Utilities.Remove before image
                RemoveFile(_env.WebRootPath, "images", newArrivalBefore.Image);
                //Add new Image
                newArrivalBefore.Image = await newArrival.Photo.SaveAsync(_env.WebRootPath, "images", "asbabphotos");
            }

            newArrivalBefore.Name          = newArrival.Name;
            newArrivalBefore.Price         = newArrival.Price;
            newArrivalBefore.DiscountPrice = newArrival.DiscountPrice;

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public IActionResult Create()
        {
            NewArrival model = new NewArrival();

            return(View(model));
        }