public IHttpActionResult CreatePlace([FromBody] PlaceBuildInfo buildInfo) { if (buildInfo == null) { return(this.BadRequest()); } string sessionId = ""; CookieHeaderValue cookie = Request.Headers.GetCookies("SessionId").FirstOrDefault(); if (cookie != null) { sessionId = cookie["SessionId"].Value; } if (!authenticator.TryGetSession(sessionId, out var sessionState)) { return(this.Unauthorized()); } var creationInfo = PlaceBuildInfoConverter.Convert(sessionState.UserId, buildInfo); var modelPlaceInfo = repository.Create(creationInfo); var clientPlaceInfo = PlaceInfoConverter.Convert(modelPlaceInfo); var routeParams = new Dictionary <string, object> { { "placeId", clientPlaceInfo.Id } }; return(this.CreatedAtRoute("GetPlaceRoute", routeParams, clientPlaceInfo)); }
public IHttpActionResult CreatePlace([FromBody] PlaceBuildInfo buildInfo) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } if (buildInfo == null) { return(this.BadRequest("Body must be not null")); } string sessionId = buildInfo.SessionId; if (!authenticator.TryGetSession(sessionId, out var sessionState)) { return(this.Unauthorized()); } var creationInfo = PlaceBuildInfoConverter.Convert(sessionState.UserId, buildInfo); var modelPlaceInfo = repository.Create(creationInfo); var clientPlaceInfo = PlaceInfoConverter.Convert(modelPlaceInfo); var routeParams = new Dictionary <string, object> { { "placeId", clientPlaceInfo.Id } }; return(this.CreatedAtRoute("GetPlaceRoute", routeParams, clientPlaceInfo)); }