/// <summary> /// This method deletes employee from DbSet and then saves changes to database. /// </summary> /// <param name="employeeID">ID of employee.</param> public void DeleteEmployee(int employeeID) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { List <tblReport> reports = context.tblReports.Where(x => x.EmployeeID == employeeID).ToList(); if (reports.Count() > 0) { foreach (var report in reports) { context.tblReports.Remove(report); context.SaveChanges(); } } tblEmployee employeeToDelete = context.tblEmployees.Where(x => x.EmployeeID == employeeID).FirstOrDefault(); context.tblEmployees.Remove(employeeToDelete); context.SaveChanges(); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// This method edits employee in DbSet and then saves changes to database. /// </summary> /// <param name="employee">Employee to edit.</param> /// <returns>Edited employee.</returns> public vwEmployee EditEmployee(vwEmployee employee) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblEmployee employeeToEdit = context.tblEmployees.Where(x => x.EmployeeID == employee.EmployeeID).FirstOrDefault(); employeeToEdit.Name = employee.Name; employeeToEdit.Surname = employee.Surname; employeeToEdit.JMBG = employee.JMBG; employeeToEdit.BankAccountNumber = employee.BankAccountNumber; employeeToEdit.Email = employee.Email; employeeToEdit.Salary = employee.Salary; employeeToEdit.Position = employee.Position; employeeToEdit.Username = employee.Username; employeeToEdit.Password = employee.Password; context.SaveChanges(); return(employee); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This method adds employee to DbSet and then save changes to database. /// </summary> /// <param name="employeeToAdd">Employee.</param> public void AddEmployee(vwEmployee employeeToAdd) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblEmployee employee = new tblEmployee { Name = employeeToAdd.Name, Surname = employeeToAdd.Surname, DateOfBirth = employeeToAdd.DateOfBirth, JMBG = employeeToAdd.JMBG, BankAccountNumber = employeeToAdd.BankAccountNumber, Email = employeeToAdd.Email, Salary = employeeToAdd.Salary, Position = employeeToAdd.Position, Username = employeeToAdd.Username, Password = employeeToAdd.Password }; context.tblEmployees.Add(employee); context.SaveChanges(); employeeToAdd.EmployeeID = employee.EmployeeID; } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// This method adds managers to DbSet and then save changes to database. /// </summary> /// <param name="managerToAdd">Employee.</param> public void AddManager(vwManager managerToAdd) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblEmployee employee = new tblEmployee { Name = managerToAdd.Name, Surname = managerToAdd.Surname, DateOfBirth = managerToAdd.DateOfBirth, JMBG = managerToAdd.JMBG, BankAccountNumber = managerToAdd.BankAccountNumber, Email = managerToAdd.Email, Salary = managerToAdd.Salary, Position = managerToAdd.Position, Username = managerToAdd.Username, Password = managerToAdd.Password, Sector = managerToAdd.Sector, AccessLevel = managerToAdd.AccessLevel }; context.tblEmployees.Add(employee); context.SaveChanges(); managerToAdd.EmployeeID = employee.EmployeeID; LogAction("Manager " + managerToAdd.Name + " " + managerToAdd.Surname + " created. Date of birth: " + managerToAdd.DateOfBirth + ", Position: " + managerToAdd.Position + ", Email: " + managerToAdd.Email + ", Sector: " + managerToAdd.Sector); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// This method deletes report from DbSet and saves changes to database. /// </summary> /// <param name="reportID"></param> public void DeleteReport(int reportID) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblReport reportToDelete = context.tblReports.Where(x => x.ReportID == reportID).FirstOrDefault(); context.tblReports.Remove(reportToDelete); context.SaveChanges(); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// This method edits reports in DbSet and then saves changes to database. /// </summary> /// <param name="report">Report to edit.</param> /// <returns>Edited report.</returns> public vwReport EditReport(vwReport report) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblReport reportToEdit = context.tblReports.Where(x => x.ReportID == report.ReportID).FirstOrDefault(); reportToEdit.Date = report.Date; reportToEdit.Project = report.Project; reportToEdit.Hours = report.Hours; context.SaveChanges(); return(report); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This method adds report to database. /// </summary> /// <param name="report">Report to add.</param> public void AddReport(vwReport report) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblReport reportToAdd = new tblReport { EmployeeID = report.EmployeeID, Date = report.Date, Project = report.Project, Hours = report.Hours }; context.tblReports.Add(reportToAdd); context.SaveChanges(); report.ReportID = reportToAdd.ReportID; } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }