Beispiel #1
0
        public ApiResponse <CreateCategoryRequest, Categories> Post([FromBody] CreateCategoryRequest request)
        {
            var validate = _createValidations.Validate(request);

            if (!validate.IsValid)
            {
                Log.Error(validate.ToString(""));

                return(new ApiResponse <CreateCategoryRequest, Categories>()
                {
                    status = false,
                    error_code = "validations_error",
                    error_message = validate.ToString("~"),
                    request = request
                });
            }

            var response = _repository.Create(request);

            Log.Information("Category added...");

            _queueRepository.Add(request);

            Log.Information("Category queue added...");

            _queueRepository.Read();

            return(new ApiResponse <CreateCategoryRequest, Categories>()
            {
                status = true,
                request = request,
                response = response
            });
        }
Beispiel #2
0
        public async Task <IActionResult> Add(string name)
        {
            {
                short?queueId = await queueRepository.Find(name);

                if (queueId.HasValue)
                {
                    return(Redirect("/list/{queueId}"));
                }
            }
            {
                short queueId = await queueRepository.Add(new Queue(name));

                return(Created($"/list/{queueId}", queueId));
            }
        }
Beispiel #3
0
        protected override void HandleCommand(QueueRequestCommand command)
        {
            OnCommandExecuting($"Initiating new queue");

            logger.LogInformation("Initiating new queue");
            var queue = new Queue
            {
                Processed       = false,
                TransactionId   = long.Parse(DateTime.Now.ToString("yyMMddHHmmssfff")),
                Request         = JsonConvert.SerializeObject(command.Request),
                TypeDefinition  = command.Request.GetType().AssemblyQualifiedName,
                HubId           = command.HubId,
                CreatedDateTime = DateTime.Now
            };

            logger.LogInformation($"Queue has initiated by transaction identity value ({queue.TransactionId})");

            repository.Add(queue);
            UnitOfWork.SaveChanges();
            logger.LogInformation($"Queue has persisted into database with id ({queue.Id})");

            OnCommandExecuting($"Queue has persisted into database with id ({queue.Id})");
        }
Beispiel #4
0
        public GeneralResponse GetQueuesFromAsterisk()
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                var    monitoring = new MonitoringControllerService();
                string Token      = monitoring.login("saman", "102030");

                List <QueueWSDL> queues      = monitoring.getQueue(Token).ToList <QueueWSDL>();
                List <Queue>     savedQueues = _queueRepository.FindAll().ToList <Queue>();

                foreach (var item in queues)
                {
                    foreach (var _item in savedQueues)
                    {
                        if (item.id == _item.AsteriskID)
                        {
                            _item.QueueName = item.name;
                            _queueRepository.Save(_item);
                        }
                    }
                }

                if (queues.Count() > savedQueues.Count())
                {
                    var result = queues.Where(x => savedQueues.All(s => s.AsteriskID != x.id));

                    foreach (var item in result)
                    {
                        var queue = new Queue();
                        queue.AsteriskID = item.id;
                        queue.ID         = Guid.NewGuid();
                        queue.QueueName  = item.name;

                        _queueRepository.Add(queue);
                    }
                }

                if (queues.Count() < savedQueues.Count())
                {
                    IEnumerable <QueueLocalPhoneStore> queueLocalPhone = _queueLocalPhoneRepository.FindAll();

                    var result1 = queueLocalPhone.Where(x => queues.All(s => s.id != x.Queue.AsteriskID));

                    foreach (var item in result1)
                    {
                        _queueLocalPhoneRepository.Remove(item);
                    }
                }

                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }