Exemple #1
0
        public static List <string> GetSubjectsTableNamesForStudent(UsersTable userEntity)
        {
            var classesTable = CloudTableUtilities.OpenTable(ProjectConsts.classesTableName);
            var classEntity  = CloudTableUtilities.getTableEntityAsync <ClassesTable>(classesTable, userEntity.TeacherName, userEntity.ClassId).Result.First();

            return(new List <string>()
            {
                classEntity.subjectsTableName
            });
        }
Exemple #2
0
        public static List <string> GetSubjectsTableNamesForTeacher(UsersTable userEntity)
        {
            var subjectsTablesNames = new List <string>();

            if (userEntity.ClassId == null)
            {
                return(subjectsTablesNames);
            }

            var classesIds   = userEntity.ClassId.Split(ProjectConsts.delimiter).ToList();
            var classesTable = CloudTableUtilities.OpenTable(ProjectConsts.classesTableName);

            foreach (var classId in classesIds)
            {
                var classEntity = CloudTableUtilities.getTableEntityAsync <ClassesTable>(classesTable, userEntity.RowKey, classId).Result.First();
                subjectsTablesNames.Add(classEntity.subjectsTableName);
            }

            return(subjectsTablesNames);
        }
Exemple #3
0
        public static async Task <string> SignUp(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage request,
            [Table("UsersTable")] CloudTable usersTable)
        {
            OperationResult operationResult = new OperationResult();
            string          childrenIds     = null;

            UserRequest newUserRequest = await Utilities.ExtractContent <UserRequest>(request);

            TableQuery <UsersTable> query = new TableQuery <UsersTable>();

            TableQuerySegment <UsersTable> usersQueryResult = await usersTable.ExecuteQuerySegmentedAsync(query, null);

            if (!UsersTableUtilities.ValidateUserNotExist(usersQueryResult, newUserRequest, operationResult))
            {
                return(JsonConvert.SerializeObject(operationResult));
            }

            if (newUserRequest.userType == ProjectConsts.ParentType)
            {
                if (newUserRequest.childrenIds == null || newUserRequest.childrenIds.Count == 0)
                {
                    operationResult.UpdateFailure(ErrorMessages.NoChildIdProvided);
                    return(JsonConvert.SerializeObject(operationResult));
                }

                childrenIds = string.Join(ProjectConsts.delimiter, newUserRequest.childrenIds);

                if (!UsersTableUtilities.ValidateChildrenIdExist(usersQueryResult, newUserRequest, operationResult))
                {
                    return(JsonConvert.SerializeObject(operationResult));
                }
            }


            if (newUserRequest.userType == ProjectConsts.TeacherType)
            {
                newUserRequest.userName = UsersTableUtilities.GetUniqueName(newUserRequest.userName);
            }

            if (newUserRequest.userType == ProjectConsts.StudentType)
            {
                var tableExist = CloudTableUtilities.TableExist(newUserRequest.teacherUser + newUserRequest.classId);

                if (!tableExist)
                {
                    operationResult.UpdateFailure(string.Format(ErrorMessages.subjectTableNotExist));
                    return(JsonConvert.SerializeObject(operationResult));
                }
            }

            var newUserEntity = new UsersTable()
            {
                UserType     = newUserRequest.userType,
                UserEmail    = newUserRequest.userEmail,
                UserPassword = newUserRequest.userPassword,
                TeacherName  = newUserRequest.teacherUser,
                ClassId      = newUserRequest.classId,
                ChildrenIds  = childrenIds
            };

            await CloudTableUtilities.AddTableEntity(usersTable, newUserEntity, newUserRequest.userId, newUserRequest.userName);

            if (newUserRequest.userType == ProjectConsts.TeacherType)
            {
                operationResult.UpdateData(newUserEntity.RowKey);
            }


            if (newUserRequest.userType == ProjectConsts.StudentType)
            {
                var deviceConnectionString = await IotDeviceFunctions.AddDeviceAsync(newUserRequest.userId);

                var subjectsTablesNames = UsersTableUtilities.GetSubjectsTableNamesForStudent(newUserEntity);
                await SubjectsTableUtilities.AddStuentToClassTableAsync(subjectsTablesNames.First(), newUserRequest, operationResult);

                operationResult.UpdateData(new { deviceConnectionString, subjectsTablesNames });
            }

            return(JsonConvert.SerializeObject(operationResult));
        }