Example #1
0
        public async Task <IActionResult> AddIncidence([FromForm] IncidenceCreateRequest request, [FromForm] List <IFormFile> attachments)
        {
            try {
                var user = await _customerUserRepository.GetCustomerUserByDni(request.UserDni);

                if (user == null)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest));
                }

                TicketIncidenceCreate ticket = new TicketIncidenceCreate {
                    UserCip       = user.CustomerId,
                    OtrsServiceId = request.OtrsServiceID,
                    Description   = request.Description,
                    Asset         = await _assetRepository.GetAssetById(request.AssetId),
                    Attachments   = _mapper.Map <List <TicketAttachments> >(_convertFileExtensions.ListConvertFileToBase64(attachments))
                };
                var result = _ticketRepository.AddTicketIncidenceOtrs(
                    _mapper.Map <TicketCredencials>(_otrsCredencialsService.GetOtrsCredencials()),
                    ticket);

                if (result.TicketID != null)
                {
                    var sendMail = await _smtpService.SendEmailCreateTicket(user, result.TicketNumber);

                    return(StatusCode(StatusCodes.Status201Created, new { Result = result, EmailSend = sendMail, Status = 1 }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new { Result = result, EmailSend = false, Status = 0 }));
                }
            } catch (Exception e) {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { StatusName = e.Message, Message = "OcurriĆ³ un problema al guardar la informaciĆ³n.", EmailSend = false, Status = 0 }));
            }
        }