Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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
            }
        }