public async Task <IActionResult> PutProducts(int id, Products products) { if (id != products.ProductId) { return(BadRequest()); } _context.Entry(products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEmployees([FromRoute] int id, [FromBody] Employees employees) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employees.EmployeeId) { return(BadRequest()); } _context.Entry(employees).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("EmployeeId,EmpName,Position,DeptId")] Employees employees) { if (ModelState.IsValid) { _context.Add(employees); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employees)); }
public async Task <IActionResult> Create([Bind("DeptId,DeptName,NoOfEmp,AvgAge")] Departments departments) { if (ModelState.IsValid) { _context.Add(departments); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DeptId"] = new SelectList(_context.Employees, "EmployeeId", "EmployeeId", departments.DeptId); return(View(departments)); }
public async Task <int> AddPost(Post post) { if (db != null) { try { await db.Post.AddAsync(post); await db.SaveChangesAsync(); } catch (Exception ex) { } return(post.PostId); } return(0); }