Exemplo n.º 1
0
 /// <summary>
 /// This method edits employee in DbSet and then saves changes to database.
 /// </summary>
 /// <param name="employee"></param>
 /// <returns>True if edited, false if not.</returns>
 public bool EditEmployee(vwEmployee employee)
 {
     try
     {
         using (Employee_DataEntities context = new Employee_DataEntities())
         {
             tblEmployee employeeToEdit = context.tblEmployees.Where(x => x.EmployeeId == employee.EmployeeId).FirstOrDefault();
             employeeToEdit.NameAndSurname       = employee.NameAndSurname;
             employeeToEdit.DateOfBirth          = CalculateDateOfBirth.Calculate(employee.JMBG);
             employeeToEdit.JMBG                 = employee.JMBG;
             employeeToEdit.NumberOfIdentityCard = employee.NumberOfIdentityCard;
             employeeToEdit.Gender               = employee.Gender;
             employeeToEdit.PhoneNumber          = employee.PhoneNumber;
             employeeToEdit.Sector               = employee.Sector;
             employeeToEdit.LocationId           = employee.LocationId;
             employeeToEdit.Manager              = employee.Manager;
             context.SaveChanges();
             logger.LogAction("Employee with JMBG " + employeeToEdit.JMBG + " updated.");
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// This method adds employee to DbSet and then save changes to database.
 /// </summary>
 /// <param name="employeeToAdd">Employee to be added.</param>
 /// <returns>True if added, false if not.</returns>
 public bool AddEmployee(vwEmployee employeeToAdd)
 {
     try
     {
         using (Employee_DataEntities context = new Employee_DataEntities())
         {
             tblEmployee employee = new tblEmployee
             {
                 NameAndSurname       = employeeToAdd.NameAndSurname,
                 DateOfBirth          = CalculateDateOfBirth.Calculate(employeeToAdd.JMBG),
                 NumberOfIdentityCard = employeeToAdd.NumberOfIdentityCard,
                 JMBG        = employeeToAdd.JMBG,
                 Gender      = employeeToAdd.Gender,
                 PhoneNumber = employeeToAdd.PhoneNumber,
                 Sector      = employeeToAdd.Sector,
                 LocationId  = employeeToAdd.LocationId,
                 Manager     = employeeToAdd.Manager
             };
             context.tblEmployees.Add(employee);
             context.SaveChanges();
             employeeToAdd.EmployeeId = employee.EmployeeId;
             logger.LogAction("Employee " + employeeToAdd.NameAndSurname + " created. ID: " + employeeToAdd.EmployeeId + " JMBG: " + employeeToAdd.JMBG);
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }