Exemple #1
0
 public T Add(T entity)
 {
     //Add the parameter object to the database
     dbContext.Set <T>().Add(entity);
     //Save changes to finalize the add
     dbContext.SaveChanges();
     //Return the newly added entity
     return(entity);
 }
Exemple #2
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 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 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);
        }
Exemple #7
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);
        }
Exemple #8
0
 public T Add(T entity)
 {
     _db.Set <T>().Add(entity);
     _db.SaveChanges();
     return(entity);
 }
Exemple #9
0
 public T Add(T entity)
 {
     ctx.Set <T>().Add(entity);
     ctx.SaveChanges();
     return(entity);
 }