/// <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 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 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());
     }
 }
예제 #4
0
 /// <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 checks if exist employee with forwarded username and password.
 /// </summary>
 /// <param name="username">Employee username.</param>
 /// <param name="password">Employee password.</param>
 /// <returns>True if exist, false if not.</returns>
 public bool AuthenticateEmployee(string username, string password)
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             tblEmployee employeeToFind = context.tblEmployees.Where(x => x.Username == username).FirstOrDefault();
             if (employeeToFind != null)
             {
                 if (employeeToFind.Password == password)
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This methods finds employee based on forwarded username and password.
 /// </summary>
 /// <param name="username">Employee username.</param>
 /// <param name="password">Employee password.</param>
 /// <returns>Employee.</returns>
 public vwEmployee FindEmployee(string username, string password)
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             return(context.vwEmployees.Where(x => x.Username == username && x.Password == password).FirstOrDefault());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
 /// <summary>
 /// This method finds employee from DbSet based on forwarded username.
 /// </summary>
 /// <param name="username">Employee username.</param>
 /// <returns>Employee.</returns>
 public List <vwEmployee> FindEmployee(string username)
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             return(context.vwEmployees.Where(x => x.Username == username).ToList());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
예제 #8
0
 /// <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 creates a list of data from view of employees.
 /// </summary>
 /// <returns>List of employees.</returns>
 public List <vwEmployee> GetEmployees()
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             List <vwEmployee> employees = new List <vwEmployee>();
             employees = (from x in context.vwEmployees select x).ToList();
             return(employees);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
예제 #10
0
 /// <summary>
 /// This method creates a list of report of employee.
 /// </summary>
 /// <param name="employeeID">Employee ID.</param>
 /// <returns>List of employee's reports.</returns>
 public List <vwReport> GetAllEmployeeReports(int employeeID)
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             List <vwReport> reports = new List <vwReport>();
             reports = context.vwReports.Where(x => x.EmployeeID == employeeID).ToList();
             return(reports);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
예제 #11
0
 /// <summary>
 /// This methods creates a list of data from view of reports.
 /// </summary>
 /// <returns></returns>
 public List <vwReport> GetReports()
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             List <vwReport> reports = new List <vwReport>();
             reports = (from x in context.vwReports select x).ToList();
             return(reports);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
예제 #12
0
 /// <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 checks if employee exists.
 /// </summary>
 /// <param name="username">Employee username.</param>
 /// <returns>True if employee exist, false if not.</returns>
 public bool IsEmployeeExists(string username)
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             vwEmployee sector = context.vwEmployees.Where(x => x.Username == username).FirstOrDefault();
             if (sector != null)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
예제 #14
0
 /// <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());
     }
 }