public ActionResult Add(Employee toAdd) { using (collabcontext db = new collabcontext()) { //getting a new employee model -dummy EmployeeModel vm = new EmployeeModel() { Result = new List <Employee>() }; if (toAdd != null) { bool isAlready = db.Employees .Where(x => x.Id == toAdd.Id) .Count() != 0; if (!isAlready) { if (!String.IsNullOrEmpty(toAdd.Email) && !String.IsNullOrEmpty(toAdd.Alias)) { db.Employees.Add(toAdd); try { db.SaveChanges(); vm.Result = db.Employees.ToList <Employee>(); return(View("Index", vm)); } catch (Exception x) { return(View()); } } } return(View("Index", vm)); } return(View("Index", vm)); } }
public ActionResult Search(int SearchPhrase) { using (collabcontext db = new collabcontext()) { var result = db.Employees.Where(x => x.Id == SearchPhrase).Select(x => x); EmployeeModel vm = new EmployeeModel() { Result = result.ToList <Employee>() }; return(View("Index", vm)); } }
public ActionResult Index() { using (collabcontext db = new collabcontext()) { var employees = db.Employees.Select(x => x); EmployeeModel vm = new EmployeeModel() { Result = employees.ToList <Employee>() }; return(View("Index", vm)); } }