public async Task <IActionResult> CreateAsync([FromBody] NoticeCreateDto noticeCreate) { var notice = _mapper.Map <Notice>(noticeCreate); var autenticated = await _identityService.GetAutenticatedPersonAsync(HttpContext.RequestAborted); notice .AddPostedBy(autenticated); _noticeRepository.Add(notice); await _noticeRepository.UnitOfWork.CommitAsync(HttpContext.RequestAborted); if (noticeCreate.SendNotification) { var data = new Dictionary <string, string>(); data.Add("Notice", notice.Id.ToString()); var image = $"https://guadalupestorage.blob.core.windows.net/assets/" + notice.Image; await _notificationService.SendByTopicAsync(notice.Title, notice.Message, image, "notices", data, HttpContext.RequestAborted) .ConfigureAwait(false); } return(Created($"api/notice/{notice.Id}", notice.Id)); }
public ActionResult <NoticeReadDto> CreateNotice(NoticeCreateDto noticeCreateDto) { var noticeModel = _mapper.Map <Notice>(noticeCreateDto); _repository.CreateNotice(noticeModel); _repository.SaveChanges(); var noticeReadDto = _mapper.Map <NoticeReadDto>(noticeModel); return(CreatedAtRoute(nameof(GetNoticeById), new { Id = noticeReadDto.Id }, noticeReadDto)); //return Ok(noticeReadDto); }
public async Task <Guid> AdicionarAsync(NoticeCreateDto notice, CancellationToken cancellationToken) { var token = await _userService.AuthenticationAsync(Startup.authentication, cancellationToken) .ConfigureAwait(false); var url = $"{Controller}"; var httpContent = new StringContent(JsonSerializer.Serialize(notice)); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var client = _clientFactory.CreateClient("guadalupe-conexao-api"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); var result = await client.PostAsync(url, httpContent, cancellationToken) .ConfigureAwait(false); return(await result.GetResultAsync <Guid>() .ConfigureAwait(false)); }
public ActionResult <NoticeReadDto> CreateNotice(NoticeCreateDto noticeCreateDto) { var noticeModel = _mapper.Map <Notice>(noticeCreateDto); _repository.CreateNotice(noticeModel); _repository.SaveChanges(); var noticeReadDto = _mapper.Map <NoticeReadDto>(noticeModel); CreatedAtRoute(nameof(GetNoticeById), new { Id = noticeReadDto.Id }, noticeReadDto); var message = MessageResource.Create( body: "Hey, Welcome to our new SMS platform. From KIBET", from: new Twilio.Types.PhoneNumber("+18506008350"), to: new Twilio.Types.PhoneNumber("+254719453783") ); return(Ok(noticeReadDto)); }