public IHttpActionResult PutEmployeee(int id, Employeee employeee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeee.Id) { return(BadRequest()); } db.Entry(employeee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Post(EmployeeModel model) { if (!ModelState.IsValid) { return(BadRequest("Invalid Data")); } if (model.ID == 0) { Employeee empEntity = new Employeee { EmpName = model.EmpName, EmpCode = model.EmpCode, Age = model.Age, AddedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, Address = new Address { Address1 = model.Address1, Address2 = model.Address2, Pincode = model.Pincode, AddedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow } }; employeeService.InsertEmployee(empEntity); } return(Ok()); }
public ActionResult DeleteConfirmed(int id) { Employeee employeee = db.Employeees.Find(id); db.Employeees.Remove(employeee); db.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult Delete(int id) { if (id != 0) { Employeee empEntity = employeeService.GetEmployee(id); employeeService.DeleteEmployee(empEntity); } return(Ok()); }
public ActionResult Edit([Bind(Include = "Id,Name,Department")] Employeee employeee) { if (ModelState.IsValid) { db.Entry(employeee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeee)); }
public IHttpActionResult GetEmployeee(int id) { Employeee employeee = db.Employeees.Find(id); if (employeee == null) { return(NotFound()); } return(Ok(employeee)); }
public ActionResult Create([Bind(Include = "Id,Name,Department")] Employeee employeee) { if (ModelState.IsValid) { db.Employeees.Add(employeee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeee)); }
public IHttpActionResult PostEmployeee(Employeee employeee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Employeees.Add(employeee); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = employeee.Id }, employeee)); }
public IHttpActionResult DeleteEmployeee(int id) { Employeee employeee = db.Employeees.Find(id); if (employeee == null) { return(NotFound()); } db.Employeees.Remove(employeee); db.SaveChanges(); return(Ok(employeee)); }
// GET: EmployeeesMvc/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Employeee employeee = db.Employeees.Find(id); if (employeee == null) { return(HttpNotFound()); } return(View(employeee)); }
public IHttpActionResult Get(int?id) { EmployeeModel model = new EmployeeModel(); if (id.HasValue && id != 0) { Employeee empEntity = employeeService.GetEmployee(id.Value); model.EmpName = empEntity.EmpName; model.EmpCode = empEntity.EmpCode; model.Age = empEntity.Age; model.Address1 = empEntity.Address.Address1; model.Address2 = empEntity.Address.Address2; model.Pincode = empEntity.Address.Pincode; } return(Ok(model)); }
public IHttpActionResult Put(EmployeeModel model) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } Employeee empEntity = employeeService.GetEmployee(model.ID); empEntity.EmpName = model.EmpName; empEntity.EmpCode = model.EmpCode; empEntity.Age = model.Age; empEntity.ModifiedDate = DateTime.UtcNow; empEntity.Address.Address1 = model.Address1; empEntity.Address.Address2 = model.Address2; empEntity.Address.Pincode = model.Pincode; empEntity.Address.ModifiedDate = DateTime.UtcNow; employeeService.UpdateEmployee(empEntity); return(Ok()); }
public void DeleteEmployee(Employeee emp) { addressRepository.Delete(emp.Address); empRepository.Delete(emp); }
public void UpdateEmployee(Employeee emp) { empRepository.Update(emp); }
public void InsertEmployee(Employeee emp) { empRepository.Insert(emp); }