Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,Category,Color,UnitPrice,AvailableQuantity")] Products products)
        {
            if (ModelState.IsValid)
            {
                _context.Add(products);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(products));
        }
Exemplo n.º 2
0
        public async Task <ICommandBase> CreateOrder(Order order)
        {
            var hasOrderName = practiceContext.Order.Any(c => c.Name.ToLower().Equals(order.Name.ToLower()));

            if (hasOrderName)
            {
                return(new CommandResult(false, $"Order's name {order.Name} has already exists"));
            }

            practiceContext.Add(order);
            await practiceContext.SaveChangesAsync();

            return(new CommandResult());
        }
Exemplo n.º 3
0
        public static void CreateUser(PracticeContext context)
        {
            var user = new User()
            {
                Username      = "******",
                Password      = "",
                SecurityToken = "",
                Name          = "Ball",
                CreateDate    = DateTime.Now,
                UpdateDate    = DateTime.Now
            };

            context.Add(user);
            context.SaveChanges();
        }
Exemplo n.º 4
0
        public IActionResult Create(User NewUser)
        {
            User newUser = new User {
                FirstName = NewUser.FirstName,
                LastName  = NewUser.LastName,
                Email     = NewUser.Email,
                Password  = NewUser.Password
            };

            // We can take the User object created from a form submission
            // And pass this object to the .Add() method
            dbContext.Add(newUser);
            // OR dbContext.Users.Add(newUser);
            dbContext.SaveChanges();
            // Other code
            return(RedirectToAction("Index"));
        }