Example #1
0
        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));
        }
        public IHttpActionResult Patch(string userId, [FromBody] UserPatchInfo patchInfo)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }
            if (patchInfo == null)
            {
                return(this.BadRequest("Body must be not null"));
            }

            if (!Guid.TryParse(userId, out var userIdGuid))
            {
                return(BadRequest());
            }

            string sessionId = patchInfo.SessionId;

            if (!authenticator.TryGetSession(sessionId, out var sessionState))
            {
                return(Unauthorized());
            }

            var userPatchInfo = UserPatchInfoConverter.Convert(userIdGuid, patchInfo);

            Model.User modelUser = null;

            try
            {
                modelUser = userRepository.Patch(userPatchInfo);
            }
            catch (Model.UserNotFoundException)
            {
                return(NotFound());
            }

            return(Ok(UserConverter.Convert(modelUser)));
        }