Exemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] CreateRoomDTO data)
        {
            var roomCode = await new RoomCodeGenerator(_dbContext).Generate();

            var user = _dbContext.Users.Include(u => u.Account).ThenInclude(a => a.Rooms).FirstOrDefault(u => u.Email == HttpContext.User.FindFirst(ClaimTypes.Email).Value);

            var room = new Room
            {
                Owner       = user,
                Code        = roomCode,
                Name        = data.RoomName,
                Description = data.Description
            };

            user.Account.Rooms.Add(room);

            await _dbContext.UserRooms.AddAsync(new UserRoom
            {
                User = user,
                Room = room,
                Role = Role.host
            });

            await _dbContext.SaveChangesAsync();

            return(StatusCode(201, new { code = roomCode, roomId = room.Id }));
        }
Exemplo n.º 2
0
        public void CreateRoom(CreateRoomDTO roomDTO)
        {
            var roomDomain = _mapper.Map <CreateRoomDTO, Room>(roomDTO);

            _repository.Add(roomDomain);
            _repository.Save();
        }
Exemplo n.º 3
0
        public async Task <RoomDTO> Create(CreateRoomDTO dto, CancellationToken cancel)
        {
            var users = new List <User>();

            foreach (var userId in dto.UserIds)
            {
                var user = await _userRepository.Get(userId, cancel);

                if (user == null)
                {
                    throw new Exception("User not found!");
                }
                users.Add(user);
            }

            var model = new Room
            {
                RoomId = Guid.NewGuid(),
                Users  = users.ToList()
            };

            await _repository.Create(model, cancel);

            foreach (var userId in dto.UserIds)
            {
                await _hubContext.Clients.Group(userId.ToString()).
                SendAsync("RoomCreated", model.ToDTO(model.Users.Select(x => x.ToDTO(null)).ToList()));
            }

            return(model.ToDTO(model.Users.Select(x => x.ToDTO(new List <RoomDTO>())).ToList()));
        }
Exemplo n.º 4
0
 public async Task <IActionResult> CreateRoom(CreateRoomDTO room)
 {
     try
     {
         await _roomService.CreateRoom(room);
     }
     catch (Exception)
     {
         return(BadRequest("An error occurred during the creating process. Please try again !"));
     }
     return(Ok("The process is success"));
 }
Exemplo n.º 5
0
        public async Task CreateRoom_HappyPath()
        {
            var dto = new CreateRoomDTO
            {
                UserIds = new System.Guid[] { StaticData.TestUserId }
            };
            var room = await _handler.Create(dto, CancellationToken.None);

            var dataFromDb = await Context.Rooms.ToListAsync();

            Assert.AreEqual(2, dataFromDb.Count);

            await DeleteDatabase();
        }
Exemplo n.º 6
0
        public async Task CreateRoom(CreateRoomDTO input)
        {
            var room = _mapper.Map <Room>(input);

            if (input.FloorId != Guid.Empty)
            {
                room.Floor = await _floorRepository.GetById(input.FloorId);
            }

            if (input.BeaconId != Guid.Empty)
            {
                room.Beacon = await _beaconRepository.GetById(input.BeaconId);
            }
            await _roomRepository.Create(room);
        }
Exemplo n.º 7
0
 public ActionResult Post([FromBody] CreateRoomDTO createRoomDTO)
 {
     try
     {
         _service.Save(createRoomDTO);
         return(Ok());
     }
     catch (Exception e)
     {
         string errors = e.Message;
         return(ValidationProblem(new ValidationProblemDetails()
         {
             Type = "Model Validation Error",
             Detail = errors
         }));
     }
 }
        public async Task <CreateOperationResult> CreateRoom(CreateRoomDTO dto)
        {
            using (var dbContext = new GrowFlowContext())
            {
                using (var service = ComplianceService.Create(dbContext, account))
                {
                    Site facility = dbContext.Set <Site>().AsNoTracking()
                                    .SingleOrDefault(s => s.AccountId == account.Id && s.Type == SiteType.Facility);

                    if (facility == null)
                    {
                        return(new CreateOperationResult()
                        {
                            Success = false,
                            Exception = "Unable to create room.  No facility location exists for this account."
                        });
                    }

                    try
                    {
                        var result = await service.CreateRoomAsync(
                            account,
                            facility,
                            dto.Name,
                            dto.Type,
                            dto.Notes);

                        return(new CreateOperationResult()
                        {
                            Success = true,
                            Data = result
                        });
                    }
                    catch (Exception e)
                    {
                        return(new CreateOperationResult()
                        {
                            Success = false,
                            Exception = e.Message
                        });
                    }
                }
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create([FromBody] CreateRoomDTO dto)
        {
            var message = await _handler.Create(dto, HttpContext.RequestAborted);

            return(Ok(message));
        }
Exemplo n.º 10
0
        public void Save(CreateRoomDTO model)
        {
            var room = _mapper.Map <CreateRoomCommand>(model);

            _bus.SendCommand(room);
        }