Ejemplo n.º 1
0
        public async Task <ActionResult> CreateAsync(
            [FromBody] CreateChatroomRequest request)
        {
            try
            {
                var chatroom = await _chatroomManagerService.CreateChatroomAsync(new CreateChatroomModel
                {
                    ChatroomName = request.ChatroomName ?? string.Empty,
                    OwnerId      = request.OwnerId,
                    IsShared     = request.IsShared,
                });

                if (chatroom is null)
                {
                    return(BadRequest());
                }

                _notificationsService.EnqueueNotification(new ChatroomChangedNotification(
                                                              chatroomId: chatroom.Id,
                                                              chatroomName: chatroom.Name,
                                                              participants: new int[] { request.OwnerId, }));

                return(new JsonResult(new BasicChatroomResponse
                {
                    Id = chatroom.Id,
                    Name = chatroom.Name,
                    IsShared = chatroom.IsShared,
                }));
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, $"Could not create chatroom with name ({request.ChatroomName}).");
                return(BadRequest());
            }
        }
Ejemplo n.º 2
0
 private Location CreateLocationFromRequest(CreateChatroomRequest request)
 {
     return(new Location
     {
         Latitude = request.Location.Latitude,
         Longitude = request.Location.Longitude
     });
 }
Ejemplo n.º 3
0
        public async Task <Chatroom> CreateOrUpdate(CreateChatroomRequest request)
        {
            var chatroom = new Chatroom
            {
                Title       = request.Title,
                Description = request.Description,
                ImageUrl    = request.ImageUrl,
                Limit       = request.Limit,
                Location    = CreateLocationFromRequest(request)
            };

            return(await CreateOrUpdate(chatroom));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> CreateOrUpdateChatroom([FromUri] int id, [FromBody] CreateChatroomRequest request)
        {
            var createdOrUpdatedChatroom = await _chatroomFactory.CreateOrUpdate(request);

            return(Ok(createdOrUpdatedChatroom.ToResponse()));
        }