// GET: Employee/Create public ActionResult Create() { EmployeeCustomModel emptable = new EmployeeCustomModel(); emptable.DepertmentSelectList = employeeService.GetDepartmentSelectListItems(); return(View(emptable)); }
// GET: Employee public ActionResult Index() { var emp = db.Employee.ToList(); List <EmployeeCustomModel> employees = new List <EmployeeCustomModel>(); if (emp != null && emp.Count > 0) { foreach (var item in emp) { EmployeeCustomModel newmodel = new EmployeeCustomModel(); newmodel.ID = item.ID; newmodel.Department = item.Department; newmodel.Name = item.Name; newmodel.DOB = item.DOB; newmodel.Age = employeeService.CalculateYourAge(item.DOB); employees.Add(newmodel); } } return(View(employees)); }
public ActionResult Create(EmployeeCustomModel emptable) { try { // TODO: Add insert logic here //emptable.Department = "IT"; //emptable.DOB = DateTime.Now; //emptable.Name = "chk emp"; Employee insertdata = new Employee(); insertdata.ID = emptable.ID; insertdata.Department = emptable.Department; insertdata.DOB = emptable.DOB; insertdata.Name = emptable.Name; db.Employee.Add(insertdata); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
public ActionResult Index(FilterSalary collection) { List <Employee> data = db.Employee.Where(m => m.DOB.Year > collection.StartDate.Year && m.DOB.Year < collection.EndDate.Year).ToList(); List <EmployeeCustomModel> employees = new List <EmployeeCustomModel>(); if (data != null && data.Count > 0) { foreach (var item in data) { EmployeeCustomModel newmodel = new EmployeeCustomModel(); newmodel.ID = item.ID; newmodel.Department = item.Department; newmodel.Name = item.Name; newmodel.DOB = item.DOB; newmodel.Age = employeeService.CalculateYourAge(item.DOB); employees.Add(newmodel); } } string averageSalary = ""; collection.employees = employees; List <int> idListint = new List <int>(); if (data != null && data.Count > 0) { foreach (var item in data) { if (item != null) { var Id = item.ID; idListint.Add(Id); } } } List <int> DistinctIds = new List <int>(); if (idListint != null && idListint.Count > 0) { DistinctIds = idListint.Distinct().ToList(); } if (DistinctIds != null && DistinctIds.Count > 0) { int i = 0; foreach (var item in DistinctIds) { i = i + 1; var dataselect = db.EmployeeSalary.Where(m => m.EmpId == item).ToList(); decimal count = 0; if (dataselect != null && dataselect.Count > 0) { foreach (var inneritem in dataselect) { count = count + Convert.ToDecimal(inneritem.Salary); } } var name = db.Employee.Where(m => m.ID == item).Select(m => m.Name).FirstOrDefault(); if (count == 0) { averageSalary = averageSalary + " " + name + ":-No salary "; } else if (count > 0) { count = count / i; averageSalary = averageSalary + " " + name + ":-" + count; } } } collection.averageSalary = averageSalary; return(View(collection)); }