public IActionResult Edit(int id, [Bind("Id,ProductId,RetailerId,DeliveryStatus")] ProductRetailerRegistration productRetailerRegistration)
        {
            if (id != productRetailerRegistration.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productRetailerRegistration);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductRetailerRegistrationExists(productRetailerRegistration.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"]  = new SelectList(_context.Product, "Id", "Id", productRetailerRegistration.ProductId);
            ViewData["RetailerId"] = new SelectList(_context.Set <Retailer>(), "Id", "Id", productRetailerRegistration.RetailerId);
            return(View(productRetailerRegistration));
        }
        public async Task <IActionResult> Create([Bind("Id,ProductId,RetailerId,DeliveryStatus")] ProductRetailerRegistration productRetailerRegistration)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productRetailerRegistration);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"]  = new SelectList(_context.Product, "Id", "Id", productRetailerRegistration.ProductId);
            ViewData["RetailerId"] = new SelectList(_context.Set <Retailer>(), "Id", "Id", productRetailerRegistration.RetailerId);

            return(View(productRetailerRegistration));
        }
Ejemplo n.º 3
0
        //Gets the retailer product registration mapping using a lamda query.
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductRetailerRegistration = _context.ProductRetailerRegistration
                                          .Include(p => p.Product)
                                          .Include(p => p.Retailer).FirstOrDefault(m => m.Id == id);

            if (ProductRetailerRegistration == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 4
0
        //Removes the retailer product registraion. Uses a linq query to check availability.
        public IActionResult OnPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductRetailerRegistration = (from retailerProd in _context.ProductRetailerRegistration
                                           where retailerProd.Id == id
                                           select retailerProd).FirstOrDefault();

            if (ProductRetailerRegistration != null)
            {
                _context.ProductRetailerRegistration.Remove(ProductRetailerRegistration);
                _context.SaveChanges();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 5
0
        //Gets the retailer -product mapping record for update. Uses  a lamda query to get the
        //Related data.
        public ActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductRetailerRegistration = _context.ProductRetailerRegistration
                                          .Include(p => p.Product)
                                          .Include(p => p.Retailer).FirstOrDefault(m => m.Id == id);

            if (ProductRetailerRegistration == null)
            {
                return(NotFound());
            }
            ViewData["ProductId"]      = new SelectList(_context.Set <Product>(), "Id", "ProductDisplayName");
            ViewData["RetailerId"]     = new SelectList(_context.Set <Retailer>(), "Id", "RetailerDisplayName");
            ViewData["DeliveryStatus"] = new SelectList(Enum.GetValues(typeof(DeliveryStatus)), ProductRetailerRegistration.DeliveryStatus);
            return(Page());
        }