public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Email,IsActive,Designation,MobileNo")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
public ActionResult Create([Bind(Include = "Id,EmployeeId,Address1,Address2,City,State,Country")] EmployeeAddress employeeAddress) { if (ModelState.IsValid) { db.EmployeeAddresses.Add(employeeAddress); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "FirstName", employeeAddress.EmployeeId); return(View(employeeAddress)); }
public HttpResponseMessage EditEmployee(int id, [FromBody] employee emp) { try { using (EmpEntities entities = new EmpEntities()) { var eachEmployee = entities.employees.FirstOrDefault(x => x.id == id); if (eachEmployee != null) { eachEmployee.id = emp.id; eachEmployee.ename = emp.ename; eachEmployee.dept_id = emp.dept_id; entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.OK, "Updated Successfully!!"); return(message); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emp not found :" + id)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage DeleteEmployee(int id) { try { using (EmpEntities entities = new EmpEntities()) { var employee = entities.employees.FirstOrDefault(x => x.id == id); if (employee != null) { entities.employees.Remove(employee); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.OK, "Deleteed Successfully!!"); return(message); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emp not found :" + id)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult PostEmployee(Employee data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { empEntity.Employees.Add(data); empEntity.SaveChanges(); } catch (Exception) { throw; } return(Ok(data)); }
public HttpResponseMessage PostEmployee([FromBody] employee emp) { try { using (EmpEntities entities = new EmpEntities()) { entities.employees.Add(emp); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, emp); message.Headers.Location = new Uri(Request.RequestUri + emp.id.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }