コード例 #1
0
        public static async Task RenameSubjectAsync(SubjectRequest editSubjectRequest, SubjectsTable subjectsNames, string scheduleTableName, SubjectsTable subjectsNecessity, OperationResult operationResult)
        {
            var subjects = typeof(SubjectsTable).GetProperties().Where(x => string.Equals(x.GetValue(subjectsNames, null)?.ToString(), editSubjectRequest.subjectName));

            if (!subjects.Any())
            {
                operationResult.UpdateFailure(ErrorMessages.subjetNotFound);
            }
            else
            {
                subjects.First().SetValue(subjectsNames, editSubjectRequest.newSubjectName);
            }

            if (scheduleTableName != null)
            {
                var scheduleTable = CloudTableUtilities.OpenTable(scheduleTableName);
                var daysEntities  = CloudTableUtilities.getTableEntityAsync <ScheduleTable>(scheduleTable).Result;

                foreach (var dayEntity in daysEntities)
                {
                    var daySubjects = typeof(ScheduleTable).GetProperties().Where(x => x.Name.Contains(SubjectPropertyPrefix) && x.GetValue(dayEntity, null) != null).ToList();

                    foreach (var subjectProperty in daySubjects)
                    {
                        if (subjectProperty.GetValue(dayEntity, null).ToString() == editSubjectRequest.subjectName)
                        {
                            subjectProperty.SetValue(dayEntity, editSubjectRequest.newSubjectName);
                        }
                    }

                    await CloudTableUtilities.AddTableEntity(scheduleTable, dayEntity);
                }
            }
        }
コード例 #2
0
        public static async Task <string> SendScanOperation([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage request, ILogger log)
        {
            OperationResult operationResult = new OperationResult();
            SubjectRequest  subjectRequest  = await Utilities.ExtractContent <SubjectRequest>(request);

            var operation = JsonConvert.SerializeObject(new { command = ProjectConsts.scanOperaion });
            await IotDeviceFunctions.SendCloudToDeviceMessageAsync(operation, subjectRequest.userId);

            return(JsonConvert.SerializeObject(operationResult));
        }
コード例 #3
0
        public static async Task <string> GetAllSubjects(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage request, ILogger log)
        {
            {
                OperationResult operationResult = new OperationResult();
                SubjectRequest  subjectsRequest = await Utilities.ExtractContent <SubjectRequest>(request);

                var allSubjects = SubjectsTableUtilities.GetAllSubjects(subjectsRequest.tableName);
                operationResult.UpdateData(allSubjects);
                return(JsonConvert.SerializeObject(operationResult));
            }
        }
コード例 #4
0
        public static void AddNewSubject(SubjectRequest addSubjectRequest, SubjectsTable classSubjectsNamesEntity, SubjectsTable classSubjectsNecessityEntity, OperationResult operationResult)
        {
            var subjectsWithoutValues = typeof(SubjectsTable).GetProperties().Where(x => x.Name.Contains(SubjectPropertyPrefix) && x.GetValue(classSubjectsNamesEntity, null) == null);

            if (!subjectsWithoutValues.Any())
            {
                operationResult.UpdateFailure(ErrorMessages.noSubjectsAvailable);
            }
            else
            {
                var subject = subjectsWithoutValues.First();
                subject.SetValue(classSubjectsNamesEntity, addSubjectRequest.subjectName);
                subject.SetValue(classSubjectsNecessityEntity, NotNeededSubject);
            }
        }
コード例 #5
0
        public static async Task <string> UpdateSubjectNecessity(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage request, [SignalR(HubName = "Pack2SchoolSignalR1")] IAsyncCollector <SignalRMessage> signalRMessages,
            ILogger log)
        {
            var            operationResult = new OperationResult();
            SubjectRequest subjectRequest  = await Utilities.ExtractContent <SubjectRequest>(request);

            var subjectsTable          = CloudTableUtilities.OpenTable(subjectRequest.tableName);
            var classSubjectsNames     = CloudTableUtilities.getTableEntityAsync <SubjectsTable>(subjectsTable, SubjectsTableUtilities.ClassSubjects).Result.First();
            var classSubjectsNecessity = CloudTableUtilities.getTableEntityAsync <SubjectsTable>(subjectsTable, SubjectsTableUtilities.Necessity).Result.First();

            SubjectsTableUtilities.UpdateSubjectNecessity(classSubjectsNames, classSubjectsNecessity, subjectRequest.neededForTomorrow);
            await CloudTableUtilities.AddTableEntity(subjectsTable, classSubjectsNecessity);

            var neededSubjects = SubjectsTableUtilities.GetNeededSubject(subjectRequest.tableName);
            var studentsIds    = SubjectsTableUtilities.GetAllStudentsIds(subjectRequest.tableName);

            foreach (var studentId in studentsIds)
            {
                var missingSubjects = SubjectsTableUtilities.GetMissingSubejcts(subjectRequest.tableName, studentId);

                var dataBaseAndScanUpdates = new DataBaseAndScanUpdates(studentId, neededSubjects, missingSubjects);

                await signalRMessages.AddAsync(
                    new SignalRMessage
                {
                    UserId    = studentId,
                    Target    = ProjectConsts.SignalRTarget,
                    Arguments = new object[] { dataBaseAndScanUpdates }
                });
            }

            var classesTable    = CloudTableUtilities.OpenTable(ProjectConsts.classesTableName);
            var classesEntities = CloudTableUtilities.getTableEntityAsync <ClassesTable>(classesTable).Result;

            foreach (var classEntity in classesEntities)
            {
                if (classEntity.subjectsTableName == subjectRequest.tableName)
                {
                    classEntity.LastTeacherUpdate = DateTime.Now;
                    await CloudTableUtilities.AddTableEntity(classesTable, classEntity);
                }
            }

            return(JsonConvert.SerializeObject(operationResult));
        }
コード例 #6
0
        public static async Task <string> UpdateSubjectSticker([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage request,
                                                               ILogger log)
        {
            OperationResult operationResult = new OperationResult();
            SubjectRequest  subjectRequest  = await Utilities.ExtractContent <SubjectRequest>(request);

            var subjectsTable = CloudTableUtilities.OpenTable(subjectRequest.tableName);
            var userStickers  = CloudTableUtilities.getTableEntityAsync <SubjectsTable>(subjectsTable, subjectRequest.userId, SubjectsTableUtilities.Stickers).Result.First();
            var classSubjects = CloudTableUtilities.getTableEntityAsync <SubjectsTable>(subjectsTable, SubjectsTableUtilities.ClassSubjects).Result.First();

            var subjectsNamesDict = typeof(SubjectsTable).GetProperties().Where(x => x.Name.Contains(SubjectsTableUtilities.SubjectPropertyPrefix) && x.GetValue(classSubjects, null) != null).ToDictionary(prop => prop.GetValue(classSubjects, null).ToString(), prop => prop.Name);

            typeof(SubjectsTable).GetProperty(subjectsNamesDict.GetValueOrDefault(subjectRequest.subjectName)).SetValue(userStickers, subjectRequest.stickerId);
            await CloudTableUtilities.AddTableEntity(subjectsTable, userStickers);

            return(JsonConvert.SerializeObject(operationResult));
        }
コード例 #7
0
        public static async Task <string> EditSubject(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage request, [SignalR(HubName = "Pack2SchoolSignalR1")] IAsyncCollector <SignalRMessage> signalRMessages, ILogger log)
        {
            OperationResult operationResult    = new OperationResult();
            SubjectRequest  editSubjectRequest = await Utilities.ExtractContent <SubjectRequest>(request);

            var    subjectsTable          = CloudTableUtilities.OpenTable(editSubjectRequest.tableName);
            var    classSubjectsNames     = CloudTableUtilities.getTableEntityAsync <SubjectsTable>(subjectsTable, SubjectsTableUtilities.ClassSubjects).Result.First();
            var    classSubjectsNecessity = CloudTableUtilities.getTableEntityAsync <SubjectsTable>(subjectsTable, SubjectsTableUtilities.Necessity).Result.First();
            var    classesTable           = CloudTableUtilities.OpenTable(ProjectConsts.classesTableName);
            var    classesEntities        = CloudTableUtilities.getTableEntityAsync <ClassesTable>(classesTable).Result;
            string scheduleTableName      = null;

            foreach (var classEntity in classesEntities)
            {
                if (classEntity.subjectsTableName == editSubjectRequest.tableName)
                {
                    scheduleTableName = classEntity.ScheduleTableName;
                    break;
                }
            }

            if (editSubjectRequest.requestType == ProjectConsts.AddSubjectOperation)
            {
                SubjectsTableUtilities.AddNewSubject(editSubjectRequest, classSubjectsNames, classSubjectsNecessity, operationResult);
            }

            if (editSubjectRequest.requestType == ProjectConsts.RenameSubjectOperation)
            {
                await SubjectsTableUtilities.RenameSubjectAsync(editSubjectRequest, classSubjectsNames, scheduleTableName, classSubjectsNecessity, operationResult);
            }

            if (editSubjectRequest.requestType == ProjectConsts.DeleteSubjectOperation)
            {
                await SubjectsTableUtilities.DeleteSubjectAsync(editSubjectRequest, classSubjectsNames, scheduleTableName, classSubjectsNecessity, operationResult);
            }

            await CloudTableUtilities.AddTableEntity(subjectsTable, classSubjectsNames);

            await CloudTableUtilities.AddTableEntity(subjectsTable, classSubjectsNecessity);

            var neededSubjects = SubjectsTableUtilities.GetNeededSubject(editSubjectRequest.tableName);
            var allSubjects    = SubjectsTableUtilities.GetAllSubjects(editSubjectRequest.tableName);
            var studentsIds    = SubjectsTableUtilities.GetAllStudentsIds(editSubjectRequest.tableName);

            foreach (var studentId in studentsIds)
            {
                var missingSubjects = SubjectsTableUtilities.GetMissingSubejcts(editSubjectRequest.tableName, studentId);

                var dataBaseAndScanUpdates = new DataBaseAndScanUpdates(studentId, neededSubjects, missingSubjects, allSubjects);

                await signalRMessages.AddAsync(
                    new SignalRMessage
                {
                    UserId    = studentId,
                    Target    = ProjectConsts.SignalRTarget,
                    Arguments = new object[] { dataBaseAndScanUpdates }
                });
            }

            return(JsonConvert.SerializeObject(operationResult));
        }