public async Task <ActionResult> Post(string authorization, [FromBody] TicketCreateParameters parameter)
        {
            var ticket = await _ticketService.Create(parameter);

            if (ticket == null)
            {
                return(Ok(new TicketCreateResult()));
            }

            if (parameter.Files != null)
            {
                ticket.Files = new List <StorageViewResult>();
                foreach (var item in parameter.Files)
                {
                    item.TicketId = ticket.Id;
                    var file = await _storageService.Create(item);

                    var path = _pathGenerator.Generate(file.Id);
                    await _fileStorage.Save(path, item.Bytes);

                    ticket.Files.Add(file);
                }
            }
            return(Ok(ticket));
        }
Exemple #2
0
        public async Task <TicketCreateResult> Create(TicketCreateParameters parameters)
        {
            var product = await _dbContext.Products.FirstOrDefaultAsync(p => p.Id == parameters.ProductId);

            var client = await _dbContext.Clients.FirstOrDefaultAsync(c => c.Id == parameters.ClientId);

            if (product == null || client == null)
            {
                return(null);
            }

            var result = await _dbContext.Tickets.AddAsync(new Ticket()
            {
                Subject        = parameters.Subject,
                Summary        = parameters.Summary,
                Status         = TicketStatus.Open,
                Priority       = product.TicketPriority,
                CreateDateTime = DateTime.Now,
                Product        = product,
                Client         = client,
            });

            await _dbContext.SaveChangesAsync();

            return(new TicketCreateResult()
            {
                Id = result.Entity.Id,
                Subject = result.Entity.Subject,
                Summary = result.Entity.Summary,
                Status = result.Entity.Status,
                ProductName = product.Name,
                ClientName = client.Name,
                Priority = result.Entity.Priority,
                CreateDateTime = result.Entity.CreateDateTime,
            });
        }