public ActionResult Create([Bind(Include = "empid,empname,email,phoneno")] employee employee) { if (ModelState.IsValid) { db.employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
public bool DeleteEmployee(int id) { using (var context = new empdbEntities()) { var emp = new Employee() { Id = id }; context.Entry(emp).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); return(false); } }
public int AddEmployee(EmployeeModels model) { using (var context = new empdbEntities()) { Employee emp = new Employee() { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Code = model.Code }; context.Employee.Add(emp); context.SaveChanges(); return(emp.Id); } }
public ActionResult Create(FormCollection collection) { try { employee emp = new employee(); emp.empname = collection["empname"]; emp.email = collection["email"]; emp.phoneno = collection["phoneno"]; empdbEntities userRegistrationEntities = new empdbEntities(); userRegistrationEntities.employees.Add(emp); userRegistrationEntities.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public bool UpdateEmployee(int id, EmployeeModels models) { using (var context = new empdbEntities()) { var employee = new Employee(); if (employee != null) { employee.FirstName = models.FirstName; employee.LastName = models.LastName; employee.Email = models.Email; employee.Code = models.Code; employee.Addressid = models.Addressid; } context.Entry(employee).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(true); } }