Пример #1
0
 public User GetirRolesByUserName(string username)
 {
     using (var dbcontext = new WebChatContext())
     {
         return(dbcontext.Users.Where(x => x.UserName == username).FirstOrDefault());
     }
 }
Пример #2
0
        public bool UpdateUser(User user, out string error)
        {
            error = string.Empty;
            try
            {
                using (var dbcontext = new WebChatContext())
                {
                    var userToUpdate = dbcontext.Users.SingleOrDefault(s => s.UserId == user.UserId);
                    if (userToUpdate == null)
                    {
                        error = "Employee Bulunamadı";
                        return(false);
                    }
                    userToUpdate.UserName = user.UserName;
                    userToUpdate.Password = user.Password;
                    userToUpdate.Email    = user.Email;
                    dbcontext.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Пример #3
0
 public User CheckLogin(string username, string password)
 {
     using (var dbcontext = new WebChatContext())
     {
         return(dbcontext.Users.SingleOrDefault(x => x.UserName == username && x.Password == password));
     }
 }
Пример #4
0
        public bool UpdateEmployee(Employee employee, out string error)
        {
            error = string.Empty;
            try
            {
                using (var dbcontext = new WebChatContext())
                {
                    var employeeToUpdate = dbcontext.Employees.SingleOrDefault(s => s.Id == employee.Id);
                    if (employeeToUpdate == null)
                    {
                        error = "Employee Bulunamadı";
                        return(false);
                    }
                    employeeToUpdate.Name    = employee.Name;
                    employeeToUpdate.Surname = employee.Surname;
                    employeeToUpdate.Job     = employee.Job;
                    dbcontext.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Пример #5
0
 public Employee GetByID(int id)
 {
     using (var dbcontext = new WebChatContext())
     {
         return(dbcontext.Employees.Where(x => x.Id == id).FirstOrDefault());
     }
 }
Пример #6
0
 public List <Employee> GetEmployees()
 {
     using (var dbcontext = new WebChatContext())
     {
         return(dbcontext.Employees.ToList());
     }
 }
Пример #7
0
 public bool CreateUser(User user, out string error)
 {
     error = string.Empty;
     try
     {
         using (var dbcontext = new WebChatContext())
         {
             dbcontext.Users.Add(user);
             dbcontext.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         error = ex.Message;
         return(false);
     }
 }
Пример #8
0
 public bool CreateEmployee(Employee employee, out string error)
 {
     error = string.Empty;
     try
     {
         using (var dbcontext = new WebChatContext())
         {
             dbcontext.Employees.Add(employee);
             dbcontext.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         error = ex.Message;
         return(false);
     }
 }
Пример #9
0
        public bool DeleteEmployee(int empID)
        {
            string error;

            try
            {
                using (var dbcontext = new WebChatContext())
                {
                    var silinecekEmployee = dbcontext.Employees.Where(x => x.Id == empID).FirstOrDefault();
                    int id = silinecekEmployee.Id;
                    dbcontext.Employees.Remove(silinecekEmployee);
                    dbcontext.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }