Exemplo n.º 1
0
        public async Task UpdateQueueType(int queueTypeId, QueueTypeModel model)
        {
            var queueType = (await context.QueueTypes.FirstOrDefaultAsync(u => u.Id == queueTypeId))
                            ?? throw new KeyNotFoundException($"Queue type not found with an id of {queueTypeId}");

            if (userAccessor.CompanyId == null)
            {
                throw new InvalidOperationException("Only an assigned administrator can make changes");
            }

            new QueueTypeValidator().ValidateAndThrow(model);

            if (queueType.CompanyId != userAccessor.CompanyId)
            {
                throw new InvalidOperationException("Queue type is not part of the company");
            }

            if (await context.QueueTypes.AnyAsync(c => c.Name == model.Name && c.Id != queueTypeId))
            {
                throw new InvalidOperationException($"Queue type with name \"{model.Name}\" already exists.");
            }

            queueType.Name = model.Name;

            await context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task <QueueTypeDto> CreateQueueType(QueueTypeModel model)
        {
            new QueueTypeValidator().ValidateAndThrow(model);

            if (await context.QueueTypes.AnyAsync(c => c.Name == model.Name))
            {
                throw new ArgumentException($"Queue type already exists with name: \"{model.Name}\"");
            }

            var queueType = new Domain.Entities.QueueType
            {
                Name      = model.Name,
                CompanyId = (int)userAccessor.CompanyId,
                IsEnabled = true
            };

            context.QueueTypes.Add(queueType);
            await context.SaveChangesAsync();

            return(mapper.Map <QueueTypeDto>(queueType));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> UpdateQueueType(int queueTypeId, QueueTypeModel model)
        {
            await queueTypeService.UpdateQueueType(queueTypeId, model);

            return(Ok());
        }
Exemplo n.º 4
0
 public async Task <ActionResult <QueueTypeDto> > CreateQueueType([FromBody] QueueTypeModel model)
 {
     return(Ok(await queueTypeService.CreateQueueType(model)));
 }