public async Task CreateRoom(CreateRoomChatView model, string userId) { var user = await _userManager.FindByIdAsync(userId); if (user == null) { throw new Exception("User is not found"); } Room room = new Room { Name = model.Name, }; if (model.Photo != null) { room.Photo = _imageProvider.ResizeAndSave(model.Photo, Constants.FilePaths.RoomAvatarImages, $"{room.Id}.png", Constants.DefaultIconSizes.MaxWidthOriginalImage, Constants.DefaultIconSizes.MaxHeightOriginalImage); } user.CurrentRoomId = room.Id; UserInRoom userInRoom = new UserInRoom() { RoomId = room.Id, UserId = userId }; await _roomRepository.Create(room); await _userInRoomRepository.Create(userInRoom); await _userManager.UpdateAsync(user); }
public async Task <IActionResult> CreateRoom(CreateRoomChatView model) { await _chatService.CreateRoom(model, UserId); return(Redirect("Index")); }