示例#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 }));
            }
        }
示例#2
0
        public async Task <IActionResult> AddStolenAlert([FromForm] StolenAlertRequest request, [FromForm] IFormFile policeAlertFile, [FromForm] IFormFile affidavitFile)
        {
            try {
                var user = await _customerUserRepository.GetCustomerUserByDni(request.UserDni);

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

                StolenAlert stolenAlert = new StolenAlert {
                    UserCip       = user.CustomerId,
                    OtrsServiceId = _ticketSettings.StolenAlertServiceID,
                    Asset         = await _assetRepository.GetAssetById(request.AssetId),
                    PoliceReport  = _mapper.Map <PoliceReport>(_convertFileExtensions.ConvertFileToBase64(policeAlertFile)),
                    Affidavit     = _mapper.Map <Affidavit>(_convertFileExtensions.ConvertFileToBase64(affidavitFile))
                };
                var result = _stolenAlertrepository.AddStolenAlert(
                    _mapper.Map <TicketCredencials>(_otrsCredencialsService.GetOtrsCredencials()),
                    stolenAlert);

                if (result.TicketID != null)
                {
                    await _assetRepository.UpdateAssetByStolen(request.AssetId);

                    var sendMail = await _smtpService.SendEmailCreateTicket(user, result.TicketNumber);

                    return(StatusCode(StatusCodes.Status201Created, new { Result = result, EmailSend = false, Status = 1 }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new { Result = result, EmailSend = false, Status = 0 }));
                }
            } catch (Exception e) {
                _logger.LogError(e, "Stolen Alert Controller Error");
                return(StatusCode(StatusCodes.Status500InternalServerError, new { StatusName = e.Message, Message = "Ocurrió un problema al guardar la información.", EmailSend = false, Status = 0 }));
            }
        }