Пример #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;
            }
        }
Пример #2
0
        private async Task <bool> ProcessSignupAsync(Models.CourseStudent courseStudent)
        {
            try
            {
                if (courseStudent == null || courseStudent.CourseId == 0 || courseStudent.StudentId == 0)
                {
                    _logger.LogInformation(INVALID_INPUTS);
                    return(false);
                }
                var course = await _courseDbContext.FindAsync(courseStudent.CourseId);

                if (course == null)
                {
                    throw new KeyNotFoundException();
                }
                if (course.CourseStudents.Count() >= course.Capacity)
                {
                    throw new CourseCapacityFullException();
                }

                courseStudent.JoinDate = DateTime.UtcNow;

                _courseStudentDbContext.Add(courseStudent);

                var records = await _courseStudentDbContext.SaveChangesAsync();

                return(records > 0);
            }
            catch (Exception exp)
            {
                _logger.Log(LogLevel.Error, exp.Message, exp.Source);
                throw;
            }
        }
        private bool ProcessAssign(Models.CourseTeacher courseTeacher)
        {
            try
            {
                if (courseTeacher == null || courseTeacher.CourseId == 0 || courseTeacher.TeacherId == 0)
                {
                    _logger.LogInformation(INVALID_INPUTS);
                    return(false);
                }
                courseTeacher.JoinDate = DateTime.UtcNow;
                _courseTeacherDbContext.Add(courseTeacher);
                var records = _courseTeacherDbContext.SaveChanges();

                return(records > 0);
            }
            catch (Exception exp)
            {
                _logger.Log(LogLevel.Error, exp.Message, exp.Source);
                throw;
            }
        }