Пример #1
0
        //update employee object
        public UpdateStatus Update(Employees updatedStudent)
        {
            UpdateStatus operationStatus = UpdateStatus.Failed;

            try
            {
                HelpdeskContext _db            = new HelpdeskContext();
                Employees       currentStudent = _db.Employees.FirstOrDefault(stu => stu.Id == updatedStudent.Id);
                _db.Entry(currentStudent).OriginalValues["Timer"] = updatedStudent.Timer;
                _db.Entry(currentStudent).CurrentValues.SetValues(updatedStudent);
                if (_db.SaveChanges() == 1)
                {
                    operationStatus = UpdateStatus.Ok;
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                operationStatus = UpdateStatus.Stale;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem in " + GetType().Name + " " +
                                  MethodBase.GetCurrentMethod().Name + " " + ex.Message);
                throw ex;
            }
            return(operationStatus);
        }
        public Employees GetByEmail(string email)
        {
            Employees selectedEmployee = null;

            try
            {
                HelpdeskContext _db = new HelpdeskContext();
                selectedEmployee = _db.Employees.FirstOrDefault(emp => emp.Email == email);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + " " + GetType().Name + " " +
                                MethodBase.GetCurrentMethod().Name + ex.Message);
            }
            return(selectedEmployee);
        }
        public int Add(Employees newempdent)
        {
            try
            {
                HelpdeskContext _db = new HelpdeskContext();
                _db.Employees.Add(newempdent);
                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + GetType().Name + " " +
                                MethodBase.GetCurrentMethod().Name + "" + ex.Message);
                throw ex;
            }

            return(newempdent.Id);
        }
        public List <Employees> GetAll()
        {
            List <Employees> allEmployees = new List <Employees>();

            try
            {
                HelpdeskContext _db = new HelpdeskContext();
                allEmployees = _db.Employees.ToList();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + GetType().Name + " " +
                                MethodBase.GetCurrentMethod().Name + "" + ex.Message);
                throw ex;
            }

            return(allEmployees);
        }
        public Employees GetById(int id)
        {
            Employees selectedempdent = null;

            try
            {
                HelpdeskContext _db = new HelpdeskContext();
                selectedempdent = _db.Employees.FirstOrDefault(emp => emp.Id == id);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in" + GetType().Name + " " +
                                MethodBase.GetCurrentMethod().Name + " " + ex.Message);
                throw ex;
            }

            return(selectedempdent);
        }
        public int Update(Employee updatedEmployee)
        {
            int employeesUpdated = -1;

            try
            {
                HelpdeskContext ctx            = new HelpdeskContext();
                Employee        currentStudent = ctx.Employees.FirstOrDefault(Employee => Employee.Id == updatedEmployee.Id);
                ctx.Entry(currentStudent).CurrentValues.SetValues(updatedEmployee);
                employeesUpdated = ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem in " + GetType().Name + " " +
                                  MethodBase.GetCurrentMethod().Name + " " + ex.Message);
                throw ex;
            }
            return(employeesUpdated);
        }
        public int Update(Employees updatedempdent)
        {
            int EmployeesUpdated = -1;

            try
            {
                HelpdeskContext _db            = new HelpdeskContext();
                Employees       currentempdent = _db.Employees.FirstOrDefault(emp => emp.Id == updatedempdent.Id);
                _db.Entry(currentempdent).CurrentValues.SetValues(updatedempdent);
                EmployeesUpdated = _db.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + GetType().Name + " " +
                                MethodBase.GetCurrentMethod().Name + " " + ex.Message);
            }

            return(EmployeesUpdated);
        }
        public int Delete(int id)
        {
            int empdentDeleted = -1;

            try
            {
                HelpdeskContext _db             = new HelpdeskContext();
                Employees       selectedempdent = _db.Employees.FirstOrDefault(emp => emp.Id == id);
                _db.Employees.Remove(selectedempdent);
                empdentDeleted = _db.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + GetType().Name + " " +
                                MethodBase.GetCurrentMethod().Name + "" + ex.Message);
                throw ex;
            }
            return(empdentDeleted);
        }
Пример #9
0
        // Returns the Id of added employee
        public int Add(Employees newEmployee)
        {
            try
            {
                // Declare HelpdeskContext object for function call
                HelpdeskContext _db = new HelpdeskContext();
                _db.Employees.Add(newEmployee);
                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem in " + GetType().Name + " " +
                                  MethodBase.GetCurrentMethod().Name + " " + ex.Message);
                throw ex;
            } // try/catch

            // Returns Id
            return(newEmployee.Id);
        }
Пример #10
0
        // Return lists of employees
        public List <Employees> GetAll()
        {
            // declare lists of employees
            List <Employees> allEmployees = new List <Employees>();

            try
            {
                // Declare HelpdeskContext object for function call
                HelpdeskContext _db = new HelpdeskContext();
                allEmployees = _db.Employees.ToList();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem in " + GetType().Name + " " +
                                  MethodBase.GetCurrentMethod().Name + " " + ex.Message);
                throw ex;
            } // try/catch

            // Return lists of employees
            return(allEmployees);
        }
Пример #11
0
        // Return employee with matching id
        public Employees GetById(int id)
        {
            // Decalre employee to store the result
            Employees selectedEmployee = null;

            try
            {
                // Declare HelpdeskContext object for query call
                HelpdeskContext _db = new HelpdeskContext();
                selectedEmployee = _db.Employees.FirstOrDefault(emp => emp.Id == id);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem in " + GetType().Name + " " +
                                  MethodBase.GetCurrentMethod().Name + " " + ex.Message);
                throw ex;
            } // try/catch

            // return the employee
            return(selectedEmployee);
        }
Пример #12
0
 public HelpdeskRepository(HelpdeskContext context = null)
 {
     _db = context != null ? context : new HelpdeskContext();
 }
Пример #13
0
 public HelpDeskRepository(HelpdeskContext context = null)
 {
     //Creates an instance of Helpdesk context to allow these methods to interact directly with the database
     dbContext = context != null ? context : new HelpdeskContext();
 }
Пример #14
0
 public SomeWorkRepository(HelpdeskContext context = null)
 {
     _db = context ?? new HelpdeskContext();
 }