public async Task <ActionResult> Insert([FromBody] CRUDModel <Orders> param) { _context.Orders.Add(param.Value); await _context.SaveChangesAsync(); return(Json(param.Value)); }
public async Task <IActionResult> PutCategory(int id, Category category) { if (id != category.CategoryId) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// PUT odata/Categories(5) public async Task <IHttpActionResult> Put([FromODataUri] int key, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (key != category.CategoryID) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(key)) { return(NotFound()); } else { throw; } } return(Updated(category)); }
public async Task <ActionResult <Employee> > PostEmployee(Employee employee) { _context.Employees.Add(employee); await _context.SaveChangesAsync(); return(CreatedAtAction("GetEmployee", new { id = employee.EmployeeId }, employee)); }
public async Task <ActionResult <Order> > PostProduct([FromBody] Order order) { _context.Orders.Add(order); await _context.SaveChangesAsync(); var result = CreatedAtAction( nameof(GetOrder), new { Id = order.OrderId }, order); return(result); }
public async Task <ActionResult <Employee> > PostEmployee([FromForm] Employee employee) { string savedImagePath = await UploadEmployeeImageAsync(); employee.PhotoPath = savedImagePath; _context.Employees.Add(employee); await _context.SaveChangesAsync(); return(CreatedAtAction("GetEmployee", new { id = employee.EmployeeId }, employee)); }
public async Task <ActionResult <Product> > PostProduct([FromBody] Product item) { _context.Products.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetProducts), new Product { ProductId = item.ProductId }, item)); }
public async Task <HttpStatusCode> InsertCustomer(CategoryDTO Category) { var newCategory = new Category() { CategoryId = Category.CategoryId, CategoryName = Category.CategoryName, Description = Category.Description, Picture = Category.Picture, }; DBContext.Categories.Add(newCategory); await DBContext.SaveChangesAsync(); return(HttpStatusCode.Created); }
public async Task <IActionResult> DeleteSuppliers([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var suppliers = await _context.Suppliers.FindAsync(id); if (suppliers == null) { return(NotFound()); } _context.Database.ExecuteSqlCommand("DELETE FROM [Order Details] WHERE ProductID IN (SELECT ProductID FROM Products WHERE SupplierID = @supplierId)", new SqlParameter("@supplierId", suppliers.SupplierId)); _context.Database.ExecuteSqlCommand("DELETE FROM Products WHERE SupplierID = @supplierId", new SqlParameter("@supplierId", suppliers.SupplierId)); _context.Suppliers.Remove(suppliers); await _context.SaveChangesAsync(); return(Ok(suppliers)); }
public async Task <ActionResult <Category> > PostCategory([FromBody] Category item) { Category category = new Category() { CategoryName = item.CategoryName, Description = item.Description }; _context.Categories.Add(category); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCategory), new { Id = item.CategoryId }, category)); }
public async Task <HttpStatusCode> InsertEmployee(EmployeeDTO Employee) { var newEmployee = new Employee() { EmployeeId = Employee.EmployeeId, LastName = Employee.LastName, FirstName = Employee.FirstName, Title = Employee.Title, TitleOfCourtesy = Employee.TitleOfCourtesy, Address = Employee.Address, City = Employee.City, Region = Employee.Region, PostalCode = Employee.PostalCode, Country = Employee.Country, HomePhone = Employee.HomePhone, Notes = Employee.Notes, ReportsTo = Employee.ReportsTo, }; DBContext.Employees.Add(newEmployee); await DBContext.SaveChangesAsync(); return(HttpStatusCode.Created); }
public async Task <HttpStatusCode> InsertCustomer(CustomerDTO Customer) { var newCustomer = new Customer() { CustomerId = Customer.CustomerId, CompanyName = Customer.CompanyName, ContactName = Customer.ContactName, ContactTitle = Customer.ContactTitle, Address = Customer.Address, City = Customer.City, Region = Customer.Region, PostalCode = Customer.PostalCode, Country = Customer.Country, Phone = Customer.Phone, Fax = Customer.Fax, //Orders = Customer.Orders, //CustomerCustomerDemos = Customer.CustomerCustomerDemos, }; DBContext.Customers.Add(newCustomer); await DBContext.SaveChangesAsync(); return(HttpStatusCode.Created); }
public async Task <T> SaveAsync(T entity) { await _context.SaveChangesAsync(); return(entity); }
public async Task SaveChangesAsync() { await _context.SaveChangesAsync(); }
public async Task <int> Add(Product session) { _context.Products.Add(session); return(await _context.SaveChangesAsync()); }
public void Update(Products product) { _context.Entry(product).State = EntityState.Modified; _context.SaveChangesAsync(); }
public void Update(Customers customer) { _context.Entry(customer).State = EntityState.Modified; _context.SaveChangesAsync(); }