Exemplo n.º 1
0
        public static Subject ToSubjectAggregate(this SubjectDataModel dataModel)
        {
            if (dataModel == null)
            {
                return(null);
            }

            var lectures = dataModel.Lectures.Select(l =>
            {
                var theatreLink      = l.LectureTheatreLink;
                var lectureSchedules = new LectureSchedule(
                    new TheatreReference(
                        theatreLink.TheatreId,
                        theatreLink.Theatre.Name,
                        theatreLink.Theatre.Capacity),
                    theatreLink.DayOfWeek,
                    theatreLink.StartHour,
                    theatreLink.EndHour);

                return(new Lecture(l.Id, l.Name, lectureSchedules));
            }).ToList();

            var studentEnrolments =
                dataModel.StudentLinks.Select(x => new StudentEnrolment(x.Student.Id, x.Student.Name)).ToList();

            var subject = new Subject(dataModel.Id, dataModel.Name, lectures, studentEnrolments);

            return(subject);
        }
Exemplo n.º 2
0
        public Task <GetScanSubjectAccessResponse> Run(GetScanSubjectAccessRequest Request)
        {
            try
            {
                var scans = m_scanCollection
                            .AsQueryable()
                            .Where(S => S.DeviceId == Request.DeviceId)
                            .ToList();

                int wifiDeviceCount      = scans.Sum(S => S.WifiDevices.Count());
                int bluetoothDeviceCount = scans.Sum(S => S.BluetoothDevices.Count());
                int scanCount            = scans.Count();

                var dataModel = new SubjectDataModel()
                {
                    Data = new Dictionary <string, string>()
                    {
                        { nameof(wifiDeviceCount), wifiDeviceCount.ToString() },
                        { nameof(bluetoothDeviceCount), bluetoothDeviceCount.ToString() },
                        { nameof(scanCount), scanCount.ToString() }
                    },
                    Categories       = s_scanSubjectCategories,
                    Name             = "Scan Data",
                    DateOfCollection = DateTime.Now.Date - TimeSpan.FromDays(12),
                    DateOfDeletion   = DateTime.Now.Date + TimeSpan.FromDays(12)
                };

                var response = new GetScanSubjectAccessResponse(dataModel, true);

                return(Task.FromResult(response));
            }
            catch (Exception _)
            {
                return(Task.FromResult(new GetScanSubjectAccessResponse(default, false)));
Exemplo n.º 3
0
        public override async Task <string> Save(Subject subject)
        {
            SubjectDataModel subjectDataModel = null;

            if (!string.IsNullOrWhiteSpace(subject.Id))
            {
                subjectDataModel = await GetBaseQuery().SingleOrDefaultAsync(x => x.Id == subject.Id);
            }

            if (subjectDataModel == null)
            {
                subjectDataModel = new SubjectDataModel()
                {
                    Name = subject.Name
                };
            }

            var lecturesDataModelById = subjectDataModel.Lectures?.ToDictionary(x => x.Id) ??
                                        new Dictionary <string, LectureDataModel>();

            var lectures = GetLectureDataModels(subject, lecturesDataModelById);

            subjectDataModel.Lectures = lectures;

            _dbContext.Update(subjectDataModel);
            await _dbContext.SaveChangesAsync();

            await DispatchEvents(subject);

            return(subjectDataModel.Id);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetSubjectlData(Guid deviceId)
        {
            var response = await m_processor.Run(new GetDeviceSARequest(deviceId));

            if (response.Success)
            {
                var device = response.DeviceModel;

                SubjectDataModel dataModel = new SubjectDataModel()
                {
                    Name = "Device Data",
                    Data = new Dictionary <string, string>()
                    {
                        { nameof(device.BluetoothName), device.BluetoothName },
                        { nameof(device.MacAddress), device.MacAddress },
                        { nameof(device.Manufacturer), device.Manufacturer },
                        { nameof(device.Model), device.Model }
                    },
                    DateOfCollection = response.DeviceModel.DateOfCreation,
                    DateOfDeletion   = response.DeviceModel.DateOfCreation + TimeSpan.FromDays(30.0),
                    Categories       = s_devicePersonalDataCategories
                };

                return(Ok(dataModel));
            }

            return(NotFound());
        }
 public GetScanSubjectAccessResponse(SubjectDataModel dataModel, bool Success) : base(Success)
 {
     DataModel = dataModel;
 }