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)); }
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()); }
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(); }
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")); }