/// <summary> /// Method for adding or editing reports into database by Employee /// </summary> /// <param name="report"></param> /// <returns></returns> public string AddReport(vwReport report) { try { using (EmployeeManagementEntities context = new EmployeeManagementEntities()) { if (report.ReportId == 0) { int noOfreports = (from x in context.tblReports where x.EmployeeId == report.EmployeeId && x.ReportDate == report.ReportDate select x).Count(); if (noOfreports < 2) { int hours = 0; if (noOfreports == 1) { hours = (from x in context.tblReports where x.EmployeeId == report.EmployeeId && x.ReportDate == report.ReportDate select x.WorkHours).FirstOrDefault(); } if (hours + report.WorkHours <= 12) { tblReport newReport = new tblReport(); newReport.EmployeeId = report.EmployeeId; newReport.ReportDate = report.ReportDate; newReport.Project = report.Project; newReport.WorkHours = report.WorkHours; context.tblReports.Add(newReport); context.SaveChanges(); return(null); } } } else { tblReport reportToEdit = (from x in context.tblReports where x.ReportId == report.ReportId select x).FirstOrDefault(); reportToEdit.ReportDate = report.ReportDate; reportToEdit.Project = report.Project; reportToEdit.WorkHours = report.WorkHours; int rep = (from x in context.tblReports where x.EmployeeId == report.EmployeeId && x.ReportDate == report.ReportDate && x.ReportId != report.ReportId select x.WorkHours).FirstOrDefault(); if (rep == 0 && reportToEdit.WorkHours <= 12) { context.SaveChanges(); return(null); } else if (rep + reportToEdit.WorkHours <= 12) { context.SaveChanges(); } else { return("Cannot have more than 12 work hours."); } } } return("Cannot have more than 12 work hours."); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public DepartmentController() { empDb = new EmployeeManagementEntities(); _departmentService = new DepartmentService(); }
public CommonEntityService() { empDb = new EmployeeManagementEntities(); }
public EmployeeController() { empDb = new EmployeeManagementEntities(); _empService = new EmployeeServices(); }
public DepartmentService() { empDb = new EmployeeManagementEntities(); }
public EmployeeService() { employeeManagementEntities = new EmployeeManagementEntities(); }
public EmployeeRepository() { employeeManagementEntitiesObj = new EmployeeManagementEntities(); }