public async Task <IActionResult> PutEmp(int id, Emp emp) { if (id != emp.empid) { return(BadRequest()); } _context.Entry(emp).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmpExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutEmp(int id, Emp emp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != emp.Id) { return(BadRequest()); } db.Entry(emp).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmpExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> AddEmployee(Employee emp) { try { if (ModelState.IsValid) { if (emp.ID == 0) { _Db.tbl_Employee.Add(emp); await _Db.SaveChangesAsync(); } else { _Db.Entry(emp).State = EntityState.Modified; await _Db.SaveChangesAsync(); } return(RedirectToAction("EmployeeList")); } return(View()); } catch (Exception e) { return(RedirectToAction("EmployeeList")); } }
public async Task <string> Post([FromBody] EmpDetails value) { await _db.Entries.AddAsync(value); await _db.SaveChangesAsync(); return(value.EmployeeId + " - " + value.Name + " : " + value.Surname); }
public async Task <ActionResult <Employee> > CreateEmp(Employee emp) { emp.DateOfJoining = DateTime.Now; emp.IsActive = true; _context.EmpCollection.Add(emp); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetEmployee), new { id = emp.Id }, emp)); }
public async Task <IActionResult> Create([Bind("ID,LastName,FirstName,StartingDate")] Supervisor supervisor) { if (ModelState.IsValid) { _context.Add(supervisor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(supervisor)); }
public async Task <IActionResult> Create([Bind("EId,EName,EDesig,EDOJ")] Emp emp) { if (ModelState.IsValid) { _context.Add(emp); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(emp)); }
public async Task <IActionResult> Create([Bind("DepartmentID,Title,Budget")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create([Bind("ContractID,DepartmentID,StandardID,SupervisorID")] Contract contract) { if (ModelState.IsValid) { _context.Add(contract); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentID"] = new SelectList(_context.Departments, "DepartmentID", "Title", contract.DepartmentID); ViewData["StandardID"] = new SelectList(_context.Standards, "ID", "FirstName", contract.StandardID); ViewData["SupervisorID"] = new SelectList(_context.Supervisors, "ID", "FirstName", contract.SupervisorID); return(View(contract)); }
public async Task <int> InsertDepartment(Department d) { context.Department.Add(d); await context.SaveChangesAsync(); return(d.Id); }
public async Task <int> InsertEmployee(Employee e) { VMDepartmentQuery query = new VMDepartmentQuery(context); await ss.WaitAsync(); try { const int nrMaxEmp = 5; int nrEmps = await query.NumberEmployees(e.Iddepartment); if (nrEmps >= nrMaxEmp) { throw new NotSupportedException("department have more that ${nrMaxEmp} employees"); } context.Employee.Add(e); return(await context.SaveChangesAsync()); } finally { ss.Release(); } }