private dynamic GetPlacesId(dynamic parameters) { try { var placeId = (int)parameters.id; var db = new MainContext(); var place = ServicePlace.GetPlaceById(placeId, db); return(place == null ? Response.AsJson("There is no such place.", HttpStatusCode.NotFound) : Response.AsJson(place.GetView())); } catch (InDataError) { return(Response.AsJson("Internal server error", HttpStatusCode.InternalServerError)); } }
private dynamic PostPhoto(dynamic parameters) { try { var userName = (string)Request.Session[ControllerUser.SessionUserNameKey]; if (string.IsNullOrEmpty(userName)) { return(Response.AsJson("Noone logged in.", HttpStatusCode.Unauthorized)); } var db = new MainContext(); var user = ServiceUser.GetLoggedUser(userName, db); if (user == null) { return(Response.AsJson("Logged user with bad userName", HttpStatusCode.InternalServerError)); } var body = this.Bind <PostPhotoBody>(); if (string.IsNullOrEmpty(body.Url)) { return(Response.AsJson("Body not completed.", HttpStatusCode.BadRequest)); } var placeId = parameters.id; var place = ServicePlace.GetPlaceById(placeId, db); if (place == null) { return(Response.AsJson("Place with this id not found.", HttpStatusCode.NotFound)); } ModelPhoto photo = ServicePlace.AddPhoto(place, user, body.Url, db); return(Response.AsJson(photo.GetView())); } catch (InDataError) { return(HttpStatusCode.InternalServerError); } catch (ModelBindingException) { return(Response.AsJson("Body not completed.", HttpStatusCode.BadRequest)); } catch (UnauthorizedAccessException) { return(Response.AsJson("You are not author of this place.", HttpStatusCode.Unauthorized)); } }