Example #1
0
        /// <summary>
        /// Sends checking signal to Customer's vehicle and enqueue the result using RabbitMQ.
        /// </summary>
        /// <param name="cid">Customer Id</param>
        public List <VehicleTransModel> PingVehiclesInQueue(int cid)
        {
            try
            {
                var vehicleTransList = new List <VehicleTransModel>();

                // 1- ping vehicles of this customer/all and get signal statuses back.
                var vehiclesSignalStatuses =
                    cid != 0
                        ? _vehicleContextRepo.GetAll().Where(v => v.CustomerId != null && v.CustomerId == cid)
                        : _vehicleContextRepo.GetAll().Where(v => v.CustomerId != null);

                // 2- post to DB.
                foreach (var v in vehiclesSignalStatuses)
                {
                    var vse = _genericsConnectionStatusRepo.GenerateSignal();
                    _genericsVehicleTransDbContextRepo.Add(new VehicleStatusTrans
                    {
                        PingTime  = DateTime.Now,
                        Status    = vse.ToString(),
                        VehicleId = v.Id
                    });
                    _genericsVehicleTransDbContextRepo.SaveChanges();
                    vehicleTransList.Add(new VehicleTransModel
                    {
                        VehicleId   = v.Id,
                        VehicleCode = v.Code,
                        VehicleRegistrationNumber = v.RegNumber,
                        CustomerId   = v.CustomerId,
                        CustomerName = _genericsCustomerDbContextRepo.Find(v.CustomerId).Name,
                        Status       = vse.ToString()
                    });
                }

                // Publish list to EventBus queue.
                _serviceBusQueue.Publish("Customer_VehicleStatusTrans", vehicleTransList);

                return(vehicleTransList);
            }
            catch (NullReferenceException nullExp)
            {
                _logger.Log(LogLevel.Error, nullExp.Message, nullExp.Source);
                throw;
            }
            catch (ObjectDisposedException objectDisponseExp)
            {
                _logger.Log(LogLevel.Error, objectDisponseExp.Message, objectDisponseExp.Source);
                throw;
            }
            catch (NotSupportedException notSuppExp)
            {
                _logger.Log(LogLevel.Error, notSuppExp.Message, notSuppExp.Source);
                throw;
            }
            catch (Exception exp)
            {
                _logger.Log(LogLevel.Error, exp.Message, exp.Source);
                throw;
            }
        }
        public IEnumerable <GetCourseStudentTeacherModel> GetDetails()
        {
            var courses = _courseDbContext.GetAll();

            if (courses == null || courses.Any() == false)
            {
                return(null);
            }
            var result = new List <GetCourseStudentTeacherModel>();

            foreach (var c in courses)
            {
                var currentResult = new GetCourseStudentTeacherModel()
                {
                    Course   = GetCourses(c),
                    Students = GetStudents(c),
                    Teachers = GetTeachers(c)
                };
                if (currentResult != null)
                {
                    result.Add(currentResult);
                }
            }
            return(result);
        }
Example #3
0
        public IEnumerable <GetCourseStudentSummaryModel> GetList()
        {
            var courses = _courseDbContext.GetAll();

            if (courses == null || courses.Any() == false)
            {
                return(null);
            }
            var result = (from c in courses
                          select new GetCourseStudentSummaryModel()
            {
                CourseID = c.Id,
                CourseName = c.Name,
                AssignedStudentsCount = c.CourseStudents != null ? c.CourseStudents.Count() : 0,
                StudentMaxAge = c.CourseStudents != null && c.CourseStudents.Any() ? c.CourseStudents.Select(s => s.Student.Age).Max() : 0,
                StudentMinAge = c.CourseStudents != null && c.CourseStudents.Any() ? c.CourseStudents.Select(s => s.Student.Age).Min() : 0,
                TotalCapacity = c.Capacity
            }).ToList();

            return(result);
        }