public async Task <IActionResult> Edit(int id, [Bind("Id")] OffersCategory offersCategory)
        {
            if (id != offersCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(offersCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OffersCategoryExists(offersCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(offersCategory));
        }
예제 #2
0
        public ActionResult AddOffer(Offer offer)
        {
            // Provides a default image url in the text box, in case the user does not enter one
            if (offer.Picture == null)
            {
                offer.Picture = "https://5.imimg.com/data5/GV/DP/MY-3831378/500ml-plastic-water-bottle-500x500.jpg";
            }

            // second part of validation
            if (!ModelState.IsValid)
            {
                var validationviewmodel = new OffersCategory
                {
                    Category = _context.Categories.ToList(),
                    Offer    = offer
                };

                return(View("AddOffer", validationviewmodel));
            }

            _context.Offers.Add(offer);

            _context.SaveChanges();

            return(RedirectToAction("Index", "Offers"));
        }
예제 #3
0
        public ActionResult Create(Offer offer)
        {
            // Provides a default image url in the text box, in case the user does not enter one
            if (offer.Picture == null)
            {
                offer.Picture = "https://5.imimg.com/data5/GV/DP/MY-3831378/500ml-plastic-water-bottle-500x500.jpg";
            }

            // second part of validation
            if (!ModelState.IsValid)
            {
                var validationviewmodel = new OffersCategory
                {
                    Category = _context.Categories.ToList(),
                    Offer    = offer
                };

                return(View("New", validationviewmodel));
            }

            var offerindb = _context.Offers.Single(o => o.ID == offer.ID);

            offerindb.ID            = offer.ID;
            offerindb.Name          = offer.Name;
            offerindb.Sale_Price    = offer.Sale_Price;
            offerindb.NumberInStock = offer.NumberInStock;
            offerindb.Picture       = offer.Picture;
            offerindb.CategoryId    = offer.CategoryId;

            _context.SaveChanges();

            return(RedirectToAction("Index", "Offers"));
        }
예제 #4
0
        // Action for Adding Offer Page
        public ActionResult AddOffer()
        {
            var categories = _context.Categories.ToList();
            var categoryVM = new OffersCategory
            {
                Category = categories
            };

            return(View("AddOffer", categoryVM));
        }
        public async Task <IActionResult> Create([Bind("Id")] OffersCategory offersCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(offersCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(offersCategory));
        }
예제 #6
0
        // Action for Offers Edit Page
        public ActionResult Edit(int id)
        {
            var offers = _context.Offers.SingleOrDefault(o => o.ID == id);

            if (offers == null)
            {
                return(HttpNotFound());
            }

            var OffersCategoryVM = new OffersCategory
            {
                Offer    = offers,
                Category = _context.Categories.ToList()
            };

            return(View("New", OffersCategoryVM));
        }
예제 #7
0
 partial void DeleteOffersCategory(OffersCategory instance);
예제 #8
0
 partial void UpdateOffersCategory(OffersCategory instance);
예제 #9
0
 partial void InsertOffersCategory(OffersCategory instance);