private async Task SendMessageBeforeVacations(VacationsContext context) { var date = DateTime.Today; var vacations = context.Vacations.ToList(); if (vacations.Count != 0) { foreach (var vacation in vacations) { if (vacation.DateOfBegin.AddDays(-14).ToString("ddMMyyyy").Equals(date.ToString("ddMMyyyy")) && IsApproved(context, vacation.VacationStatusTypeID)) { var employee = GetUserById(context, vacation.EmployeeID); var team = employee.EmployeesTeam.FirstOrDefault(); if (team != null) { var teamLeader = GetUserById(context, team.TeamLeadID); await SendAsync(teamLeader.WorkEmail, teamLeader.Name + " " + teamLeader.Surname, "Soon the vacation of your employee", employee.Name + " " + employee.Surname, employee.Name + " " + employee.Surname + " will go on vacation " + vacation.DateOfBegin.ToString("dd-MM-yyyy")); } } } } }
private async Task SendMessageForBirthdays(VacationsContext context) { var date = DateTime.Today; var employees = context.Employees.Where(x => !x.EmployeesTeam.Count.Equals(0)).ToList(); if (employees.Count != 0) { foreach (var employee in employees) { var yesterday = employee.BirthDate.AddDays(-1); if (yesterday.ToString("ddMM").Equals(date.ToString("ddMM"))) { var employeeTeam = employee.EmployeesTeam.FirstOrDefault(); if (employeeTeam != null) { var teamLeader = GetUserById(context, employeeTeam.TeamLeadID); await SendAsync(teamLeader.WorkEmail, teamLeader.Name + " " + teamLeader.Surname, "The birthday of your employee tomorrow", employee.Name + " " + employee.Surname, employee.Name + " " + employee.Surname + " has a birthday tomorrow"); } } } } }
public void UpdateBalance() { if (DateTime.Today.ToString("ddMM").Equals("0101")) { using (var context = new VacationsContext()) { var employees = context.Employees.Where(x => x.Status).ToList(); foreach (var employee in employees) { if (employee.VacationBalance < 0) { employee.VacationBalance += 28; } else { employee.VacationBalance = 28; } /*employee.Transactions.Add(new Transaction * { * BalanceChange = 28, * Discription = "New Year", * EmployeeID = employee.EmployeeID, * Employee = employee, * TransactionDate = DateTime.Today, * TransactionID = Guid.NewGuid().ToString(), * TransactionType = "", * });*/ } context.SaveChanges(); } } }
public void CreateVacation(Employee employee, Vacation vacation) { try { using (VacationsContext context = new VacationsContext()) { context.Employees.Attach(employee); employee.Vacations.Add(vacation); Int32 result = context.SaveChanges(); Console.WriteLine("Result: {0}", result); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var results = ex.EntityValidationErrors; foreach (var result in results) { Console.WriteLine("{0} {1}", result.Entry, result.IsValid); foreach (var error in result.ValidationErrors) { Console.WriteLine("{0} {1}", error.PropertyName, error.ErrorMessage); } } } catch (Exception ex) { Console.WriteLine(ex); } }
public async Task SendMessages() { using (var context = new VacationsContext()) { await SendMessageForBirthdays(context); await SendMessageBeforeVacations(context); } }
public void DeleteEmployee(Employee employee) { try { using (VacationsContext context = new VacationsContext()) { context.Employees.Attach(employee); context.Employees.Remove(employee); Int32 result = context.SaveChanges(); Console.WriteLine("Result: {0}", result); } } catch (Exception ex) { Console.WriteLine(ex); } }
public void DeleteVacation(Vacation vacation) { try { using (VacationsContext context = new VacationsContext()) { context.Vacations.Attach(vacation); context.Vacations.Remove(vacation); Int32 result = context.SaveChanges(); Console.WriteLine("Result: {0}", result); } } catch (Exception ex) { Console.WriteLine(ex); } }
/* * Check employee exists. */ public void CreateEmployee(String fullname) { try { using (VacationsContext context = new VacationsContext()) { Employee employee = new Employee(fullname); context.Employees.Add(employee); Int32 result = context.SaveChanges(); Console.WriteLine("Result: {0}", result); } } catch (Exception ex) { Console.WriteLine(ex); } }
public Vacation FindVacation(Int32 id) { Vacation vacation = null; try { using (VacationsContext context = new VacationsContext()) { vacation = context.Vacations.Where(p => p.VacationId == id).Single(); } } catch (Exception ex) { Console.WriteLine(ex); } return(vacation); }
public Employee FindEmployee(Int32 id) { Employee employee = null; try { using (VacationsContext context = new VacationsContext()) { employee = context.Employees.Where(p => p.EmployeeId == id).Single(); } } catch (Exception ex) { Console.WriteLine(ex); } return(employee); }
public IEnumerable <Employee> SelectAllEmployees() { var employees = new List <Employee>(); try { using (VacationsContext context = new VacationsContext()) { employees = context.Employees.Include("Vacations").ToList(); } } catch (Exception ex) { Console.WriteLine(ex); } return(employees); }
public IEnumerable <Employee> SelectAllEmployees() { var employees = new List <Employee>(); try { using (VacationsContext context = new VacationsContext()) { VacationsLib.Model.Attribute attribute = context.Attributes.Where(p => p.Description.Contains("Colour")).Single(); employees = context.Employees .Include("Vacations") .Include("EmpAttributes") //.Where(p=>p.EmpAttributes.Where(e=>e.AttributeId==attribute.AttributeId).Single()) .ToList(); } } catch (Exception ex) { Console.WriteLine(ex); } return(employees); }
public TransactionRepository(VacationsContext dbContext) { _context = dbContext; }
public EmployeeRepository(VacationsContext dbContext) { _context = dbContext; }
public RolesRepository(VacationsContext dbContext) { _context = dbContext; }
public TeamRepository(VacationsContext dbContext) { _context = dbContext; }
private Employee GetUserById(VacationsContext context, string id) { var obj = context.Employees.FirstOrDefault(x => x.EmployeeID == id); return(obj); }
private bool IsApproved(VacationsContext context, string id) { var obj = context.VacationStatusTypes.FirstOrDefault(x => x.VacationStatusTypeID == id); return(obj != null && obj.VacationStatusName == VacationStatusTypeEnum.Approved.ToString()); }
public EmployeeUnitOfWork() { _dbContext = new VacationsContext(); }
public JobTitleRepository(VacationsContext dbContext) { _context = dbContext; }
public UsersRepository(VacationsContext context) { _context = context; }
public VacationTypeRepository(VacationsContext dbContext) { _context = dbContext; }