public async Task <string> CreateSession(CreateSessionDto createSessionDto) { var session = await _openTok.CreateSession(createSessionDto.Location, createSessionDto.MediaMode, createSessionDto.ArchiveMode); return(session.Id); }
public void Create(CreateSessionDto dto) { var session = _mapper.Map <SessionDbEntity>(dto); _DB.Sessions.Add(session); _DB.SaveChanges(); }
public IActionResult Create(CreateSessionDto dto) { if (ModelState.IsValid) { _service.Create(dto); return(RedirectToAction("Index")); } return(View(dto)); }
public IActionResult CreateSession([FromBody] CreateSessionDto session) { var newSession = new SessionDto() { Id = Guid.NewGuid() }; return(StatusCode(200, newSession)); }
public static async Task <HttpResponseData> RunAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "sessions")] HttpRequestData req, CreateSessionDto data ) { // Create response var response = req.CreateResponse(); // Get user id var userId = Utils.GetUserId(req.Headers); // Validate params var valid = Validate(userId, data); if (valid.Item1) { try { // Get container var sessionContainer = await CosmosDb.GetContainerAsync(CosmosDb.SESSION_CONTAINER_ID); // Create new instance var session = new Session() { UserId = userId, SessionName = data.SessionName }; Task.WaitAll( // Save to database CosmosDb.CreateItemAsync <Session>(sessionContainer, session, session.UserId.ToString()), // Write id to response response.WriteAsJsonAsync(session.Id).AsTask() ); } catch (CosmosException ex) { // Response error message await response.WriteAsJsonAsync(ex.Message); // Set http status code response.StatusCode = (HttpStatusCode)ex.Status; } } else { // Response invalid await response.WriteAsJsonAsync(valid.Item2); // Set http status code response.StatusCode = HttpStatusCode.BadRequest; } return(response); }
private async Task <string> CreateSession(uint mapId, Difficulty difficulty) { var client = _httpClientFactory.CreateClient(); var newSession = new CreateSessionDto { Difficulty = (int)difficulty, MapId = (int)mapId }; var response = await client.PostAsync($"{_mapConfiguration.ApiUrl}/sessions/", newSession, new JsonMediaTypeFormatter()); var createdSession = await response.Content.ReadAsAsync <SessionDto>(); return(createdSession.Id); }
private static (bool, string) Validate(Guid userId, CreateSessionDto data) { var valid = true; var message = new List <string>(); // Validate user id if (userId == Guid.Empty) { valid = false; message.Add("User ID is invalid."); } // Validate data if (string.IsNullOrWhiteSpace(data.SessionName)) { valid = false; message.Add("Session name is missing."); } return(valid, string.Join("\n", message)); }
public IActionResult Create([FromBody] CreateSessionDto dto) { _service.Create(dto); return(Ok(GetResponse())); }