public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here Employee_bak newEmp = new Employee_bak(); int newId = 1; if (empList.Count > 0) { newId = empList.Select(a => a.ID).Max() + 1; } newEmp.ID = newId; newEmp.Age = int.Parse(collection["Age"]); DateTime jDate; DateTime.TryParse(collection["JoiningDate"], out jDate); newEmp.JoiningDate = jDate; newEmp.Name = collection["Name"]; empList.Add(newEmp); return(RedirectToAction("Index")); } catch (Exception e) { Console.WriteLine(e.Message); return(View()); } }
// DELETE: Employee //[HttpDelete] public ActionResult Delete(int id) { Employee_bak currEmp = empList.Single(emp => emp.ID == id); empList.Remove(currEmp); return(RedirectToAction("Index")); }