public async Task<JsonResult> GetSet(string resource) { ServiceResponse response = default(ServiceResponse); using (Session session = ApplicationModel.Current.CreateSession(new SecurityToken(this.HttpContext.Request.Url.Host, this.HttpContext.User.Identity.Name))) { try { IDictionary<string, string> parameters = this.GetParameters(); IRestPortal<DataTransferObject> portal = DependencyInjection.Get<IRestPortal<DataTransferObject>>(InjectionParameter.Create("resource", resource)); IEnumerable<DataTransferObject> set = portal.Get(parameters); ResponseStatus status = ResponseStatus.OK; response = new ServiceDataResponse(RestVersion0100Controller.API_VERSION, status, set); } catch (Exception ex) { response = new ServiceErrorResponse(RestVersion0100Controller.API_VERSION, ResponseStatus.ERROR, new ServiceError(ex)); } } return this.Json(response, JsonRequestBehavior.AllowGet); }
public async Task<JsonResult> Get(string resource, Guid identifier) { ServiceResponse response = default(ServiceResponse); using (Session session = ApplicationModel.Current.CreateSession(new SecurityToken(this.HttpContext.Request.Url.Host, this.HttpContext.User.Identity.Name))) { try { IRestPortal<DataTransferObject> portal = DependencyInjection.Get<IRestPortal<DataTransferObject>>(InjectionParameter.Create("resource", resource)); DataTransferObject value = portal.Get(identifier); if (default(DataTransferObject) == value) HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; ResponseStatus status = default(DataTransferObject) != value ? ResponseStatus.OK : ResponseStatus.NO_DATA; response = new ServiceDataResponse(RestVersion0100Controller.API_VERSION, status, value); } catch (Exception ex) { response = new ServiceErrorResponse(RestVersion0100Controller.API_VERSION, ResponseStatus.ERROR, new ServiceError(ex)); } } return this.Json(response, JsonRequestBehavior.AllowGet); }