public JsonResult Post(Department dep) { try { using (AngTestContext db = new AngTestContext()) { Department dep1 = new Department(); if (dep.DepartmentName != "") { dep1.DepartmentName = dep.DepartmentName; } else { return(new JsonResult("Enter name of the department!")); } db.Department.Add(dep1); db.SaveChanges(); } return(new JsonResult("Added Successfully!")); } catch (Exception) { return(new JsonResult("Failed to Add!")); } }
public JsonResult Delete(int id) { try { using (AngTestContext db = new AngTestContext()) { var emp1 = db.Employee.Find(id); db.Employee.Remove(emp1); db.SaveChanges(); } return(new JsonResult("Deleted successfully!")); } catch (Exception) { return(new JsonResult("Failed to Delete!")); } }
public JsonResult Delete(int id) { try { using (AngTestContext db = new AngTestContext()) { var dep1 = db.Department.Find(id); db.Department.Remove(dep1); db.SaveChanges(); } return(new JsonResult("Deleted Successfully!")); } catch (Exception) { return(new JsonResult("Failed to Delete !")); } }
public JsonResult Put(Department dep) { try { using (AngTestContext db = new AngTestContext()) { var id = dep.DepartmentId; var dep1 = db.Department.Find(id); dep1.DepartmentName = dep.DepartmentName; db.SaveChanges(); } return(new JsonResult("Updated Successfully!")); } catch (Exception) { return(new JsonResult("Failed to Update!")); } }
public JsonResult Put(Employee emp) { try { using (AngTestContext db = new AngTestContext()) { var id = emp.EmployeeId; var emp1 = db.Employee.Find(id); emp1.EmployeeName = emp.EmployeeName; emp1.Department = emp.Department; emp1.DateOfJoining = emp.DateOfJoining; emp1.PhotoFileName = emp.PhotoFileName; db.SaveChanges(); } return(new JsonResult("Updated successfully!")); } catch (Exception) { return(new JsonResult("Failed to Update!")); } }
public JsonResult Post(Employee emp) { try { using (AngTestContext db = new AngTestContext()) { DateTime thisDay = DateTime.Today; Employee emp1 = new Employee(); if (emp.EmployeeName != "") { emp1.EmployeeName = emp.EmployeeName; } else { return(new JsonResult("enter the name of the employee!")); } emp1.Department = emp.Department; if (emp.DateOfJoining != null & emp.DateOfJoining <= thisDay) { emp1.DateOfJoining = emp.DateOfJoining; } else { return(new JsonResult("enter date of joining correctly!")); } emp1.PhotoFileName = emp.PhotoFileName; db.Employee.Add(emp1); db.SaveChanges(); } return(new JsonResult("Added Successfully!")); } catch (Exception) { return(new JsonResult("Failed to Add!")); } }