public async Task <IActionResult> Create([Bind("CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CategoryID,CategoryName,Description")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("ProductID,ProductName,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryName", product.CategoryID); return(View(product)); }
public async Task <IActionResult> Create([Bind("EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Notes,ReportsTo")] Employee employee) { if (ModelState.IsValid) { db.Add(employee); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ReportsTo"] = new SelectList(db.Employees, "EmployeeID", "FirstName", employee.ReportsTo); return(View(employee)); }
public async Task <IActionResult> CreateEmployee([FromBody] EmployeeData empData) { if (ModelState.IsValid) { Employee e = empData.Employee; _context.Add(e); await _context.SaveChangesAsync(); return(Ok(e.EmployeeID)); // 200 OK } else { return(BadRequest(ModelState)); // return error } }