public UserListDTO GetListUserByID(int listId) { UserType userType = db.UserTypes.First(f => f.UserID == listId); UserList list = db.UserLists.Find(listId); UserListDTO userListDTO = new UserListDTO(); userListDTO.ID = list.ID; userListDTO.Name = list.Name; userListDTO.Surname = list.Surname; userListDTO.Email = list.Email; userListDTO.Avatar = list.Avatar; userListDTO.UserType = userType.RoleID; userListDTO.UP = false; userListDTO.AP = false; userListDTO.HP = false; List <PermissionList> permissionList = db.PermissionLists.Where(f => f.UserID == listId).ToList(); foreach (var permission in permissionList) { if (permission.PermissionID == 1) { userListDTO.UP = true; } if (permission.PermissionID == 2) { userListDTO.AP = true; } if (permission.PermissionID == 2) { userListDTO.HP = true; } } return(userListDTO); }
public UserListDTO GetEditUser(int editedId, string editedName, string editedSurname, string editedEmail, string editedAvatar, string editedUserType) { UserList list = db.UserLists.First(f => f.ID == editedId); list.Name = editedName; list.Surname = editedSurname; list.Email = editedEmail; list.Avatar = editedAvatar; db.SaveChanges(); UserListDTO userListDTO = new UserListDTO(); userListDTO.Name = list.Name; userListDTO.Surname = list.Surname; userListDTO.Email = list.Email; userListDTO.Avatar = list.Avatar; return(userListDTO); }
public List <UserListDTO> GetListUsers() { List <UserList> list = db.UserLists.ToList(); List <UserListDTO> DTOList = new List <UserListDTO>(); foreach (var item in list) { UserType userType = db.UserTypes.First(f => f.UserID == item.ID); UserListDTO userListDTO = new UserListDTO(); userListDTO.ID = item.ID; userListDTO.Name = item.Name; userListDTO.Surname = item.Surname; userListDTO.Email = item.Email; userListDTO.Avatar = item.Avatar; userListDTO.UserType = userType.RoleID; userListDTO.UP = false; userListDTO.AP = false; userListDTO.HP = false; List <PermissionList> permissionList = db.PermissionLists.Where(f => f.UserID == item.ID).ToList(); foreach (var permission in permissionList) { if (permission.PermissionID == 1) { userListDTO.UP = true; } if (permission.PermissionID == 2) { userListDTO.AP = true; } if (permission.PermissionID == 3) { userListDTO.HP = true; } } DTOList.Add(userListDTO); } return(DTOList); }
public UserListDTO GetAddNewUser(string newName, string newSurname, string newEmail, string newAvatar, bool UP, bool AP, bool HP) { UserListDTO userListDTO = new UserListDTO(); UserList userList = new UserList(); //USERLIST userListDTO.Name = newName; userListDTO.Surname = newSurname; userListDTO.Email = newEmail; userListDTO.Avatar = newAvatar; userList.Name = userListDTO.Name; userList.Surname = userListDTO.Surname; userList.Email = userListDTO.Email; userList.Avatar = userListDTO.Avatar; db.UserLists.Add(userList); db.SaveChanges(); //USERTYPE UserType userType = new UserType(); userType.UserID = userList.ID; if (AP) { Role role = db.Roles.Find(2); userType.RoleID = role.RoleID; } else { Role role = db.Roles.Find(1); userType.RoleID = role.RoleID; } db.UserTypes.Add(userType); //PERMISSIONLIST if (UP) { PermissionList permissionList = new PermissionList(); permissionList.UserID = userList.ID; Permission permission = db.Permissions.Find(1); permissionList.PermissionID = permission.PermissionID; db.PermissionLists.Add(permissionList); } if (AP) { PermissionList permissionList = new PermissionList(); permissionList.UserID = userList.ID; Permission permission = db.Permissions.Find(2); permissionList.PermissionID = permission.PermissionID; db.PermissionLists.Add(permissionList); } if (HP) { PermissionList permissionList = new PermissionList(); permissionList.UserID = userList.ID; Permission permission = db.Permissions.Find(3); permissionList.PermissionID = permission.PermissionID; db.PermissionLists.Add(permissionList); } db.SaveChanges(); return(userListDTO); }