public Employee GetById(Guid id) { using (var context = new AutomaxContext()) { return(context.Employees.FirstOrDefault(e => e.Id == id)); } }
public IEnumerable <Employee> GetAll() { using (var context = new AutomaxContext()) { return(context.Employees.ToList()); } }
public bool LoginEmployee(string loginName, string password) { using (var context = new AutomaxContext()) { var hasher = new PasswordHasher(); var employee = context.Employees .FirstOrDefault(e => e.LoginName == loginName && e.Active == true); if (employee != null) { if (!hasher.VerifyPassword(password, employee.HashedPassword)) { return(false); } LogoutCurrentEmployee(); _currentLoggedEmployee = employee; _employeeLogged = true; return(true); } return(false); } }
public void Save(Employee employee) { using (var context = new AutomaxContext()) { context.Employees.AddOrUpdate(employee); context.SaveChanges(); } }
public int NextNumber() { using (var context = new AutomaxContext()) { int?maxNumber = context.Invoices.Max(i => (int?)i.Number); return((maxNumber == null) ? 1 : maxNumber.Value + 1); } }
public void Save(Invoice invoice) { using (var context = new AutomaxContext()) { context.Employees.Attach(invoice.Employee); context.Invoices.AddOrUpdate(invoice); context.SaveChanges(); } }
public Invoice GetByNumber(int number) { using (var context = new AutomaxContext()) { return(context.Invoices .Include(i => i.Employee) .Include(i => i.ServicesToProvide) .FirstOrDefault(i => i.Number == number)); } }
public IEnumerable <Employee> GetByAllRegularsAndManagers() { using (var context = new AutomaxContext()) { return(context.Employees .Where(e => e.EmployeeRole == EmployeeRole.Regular || e.EmployeeRole == EmployeeRole.Manager) .ToList()); } }
public IEnumerable <Invoice> GetRecents(int maxNumberToRetrieve) { using (var context = new AutomaxContext()) { return(context.Invoices .OrderByDescending(i => i.InvoiceDate) .Take(maxNumberToRetrieve) .Include(i => i.Customer) .Include(i => i.ServicesToProvide) .Include(i => i.Employee) .Include(i => i.VehicleToRepair) .ToList()); } }
public Invoice GetLastIssued() { using (var context = new AutomaxContext()) { var invoices = context.Invoices; return(invoices .Include(i => i.Customer) .Include(i => i.ServicesToProvide) .Include(i => i.Employee) .Include(i => i.VehicleToRepair) .FirstOrDefault(i => i.Number == invoices.Max(invoice => invoice.Number))); } }
public IList <Invoice> GetByEmployeeBetweenDates(Guid employeeId, DateTime startDate, DateTime endDate) { if (startDate >= endDate) { throw new ArgumentException( $"{nameof(startDate)} can't be equal or greater than {nameof(endDate)}", nameof(startDate)); } using (var context = new AutomaxContext()) { return(context.Invoices .Where(i => i.Employee.Id == employeeId) .Where(i => i.InvoiceDate >= startDate && i.InvoiceDate <= endDate) .Include(i => i.Customer) .Include(i => i.ServicesToProvide) .Include(i => i.Employee) .Include(i => i.VehicleToRepair) .ToList()); } }