[HttpPost("new")] // just for testing public async Task <ActionResult <NotificationCreateDto> > AddNewNotification(NotificationCreateDto requestDto) { if (requestDto.UserId == null) { requestDto.UserId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.SerialNumber)?.Value; } var notif = await _notification.CreateAsync(requestDto); return(notif); }
public async Task <IActionResult> CreateNotification(NotificationCreateDto notificationCreateDto) { var notification = _mapper.Map <Notification>(notificationCreateDto); await _repository.CreateObjectAsync(notification); var notificationReadDto = _mapper.Map <NotificationReadDto>(notification); // https://docs.microsoft.com/en-us/dotnet/api/system.web.http.apicontroller.createdatroute?view=aspnetcore-2.2 return(CreatedAtRoute(nameof(GetNotificationByDeviceId), new { Id = notificationReadDto.Id }, notificationReadDto)); }
public async Task <NotificationCreateDto> CreateAsync(NotificationCreateDto dto) { var notification = new Notification { UserId = dto.UserId, Title = dto.Title, Text = dto.Text, Seen = false }; UnitOfWork.Notifications.Add(notification); await UnitOfWork.SaveChangesAsync(); return(_mapper.Map <NotificationCreateDto>(dto)); }
public async Task <IActionResult> UpdateNotificationByObjectId(string id, NotificationCreateDto notificationCreateDto) { var notificationModel = this._mapper.Map <Notification>(notificationCreateDto); var notification = await this._repository.GetObjectByIdAsync(id); if (notification != null) { notificationModel.UpdatedAt = DateTime.UtcNow; notificationModel.Id = new ObjectId(id); await this._repository.UpdateObjectAsync(id, notificationModel); return(Ok(this._mapper.Map <Notification>(notificationModel))); } return(NotFound()); }
public async Task <IActionResult> CreateNotification(NotificationCreateDto notificationCreateDto) { var notification = this._mapper.Map <Notification>(notificationCreateDto); if (notification != null) { notification.Id = ObjectId.GenerateNewId(); notification.CreatedAt = notification.UpdatedAt = DateTime.UtcNow; await this._repository.CreateObjectAsync(notification); // SignalR event // await this._hub.Clients.All.SendAsync("GetNewNotificationsAsync", notification); return(Ok(this._mapper.Map <NotificationReadDto>(notification))); } return(NotFound()); }