Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CustomerId")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index))
                       .WithSuccess("Update Successful", "Order #" + order.Id + " updated successfully"));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Name", order.CustomerId);
            return(View(order)
                   .WithWarning("Uh-Oh!", "Something went wrong, try again."));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Discount")] Promotion promotion)
        {
            if (id != promotion.Id)
            {
                return(NotFound());
            }
            if (DiscountExists(promotion.Discount))
            {
                return(View(promotion)
                       .WithWarning("Promo Exists", "An equivalent promotion exists. Try a different value."));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (promotion.Discount > 0)
                    {
                        _context.Update(promotion);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        return(View(promotion)
                               .WithWarning("Invalid Promo", "Promo must be a value greater than zero."));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PromotionExists(promotion.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index))
                       .WithSuccess("Update Successful", "Promotion successfully changed to $" + promotion.Discount));
            }
            return(View(promotion)
                   .WithWarning("Uh-Oh!", "Something went wrong. Try again."));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ChannelName")] Channel channel)
        {
            if (id != channel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (ChannelExists(channel.ChannelName))
                {
                    return(View(channel)
                           .WithWarning("Channel Exists", "Channel already exists. Try a different name."));
                }

                try
                {
                    _context.Update(channel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ChannelExists(channel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index))
                       .WithSuccess("Update Successful", channel.ChannelName + " updated successfully"));;
            }
            return(View(channel)
                   .WithWarning("Uh-Oh!", "Something went wrong, try again."));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Phone")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (!CustomerExists(id))
            {
                return(RedirectToAction(nameof(Edit))
                       .WithDanger("Update Not Successful", "Customer Id: " + id + " doesn't exist"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index))
                       .WithSuccess("Update Successful", customer.Name + " updated successfully"));
            }
            return(View(customer));
        }