public async Task <IActionResult> Create([Bind("Id,Discount")] Promotion promotion)
        {
            if (DiscountExists(promotion.Discount))
            {
                return(View(promotion)
                       .WithWarning("Promo Exists", "An equivalent promotion exists. Try a different value."));
            }

            if (ModelState.IsValid)
            {
                if (promotion.Discount > 0)
                {
                    _context.Add(promotion);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(View(promotion)
                           .WithWarning("Invalid Promo", "Promo must be a value greater than zero."));
                }

                return(RedirectToAction(nameof(Index))
                       .WithSuccess("Success", "$" + promotion.Discount + " promotion successfully created."));;
            }
            return(View(promotion)
                   .WithWarning("Uh-Oh!", "Something went wrong. Try again."));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,CustomerId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Email", order.CustomerId);
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index))
                       .WithSuccess("Registration Successful", customer.Name + " was successfully registered as a new customer."));
            }
            return(View(customer)
                   .WithWarning("Uh-Oh!", "Something went wrong. Try again."));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,ChannelName")] Channel channel)
        {
            if (ModelState.IsValid)
            {
                if (ChannelExists(channel.ChannelName))
                {
                    return(View(channel)
                           .WithWarning("Channel Exists", "Channel already exists. Try a different name."));
                }

                _context.Add(channel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index))
                       .WithSuccess("Success", channel.ChannelName + " channel created successfully"));
            }
            return(View(channel));
        }