public dynamic Put(string id, ExtendedQueryModel model) { var query = this._queryRepository.GetById(id); if (query == null) { return NotFound(); } if (!this.CanEdit(query)) { return this.Unauthorized(); } if (this._queryRepository.All().FirstOrDefault(q => q.Alias == model.Alias && q.Id != id) != null) { return BadRequest("Query met dezelfde naam bestaat reeds."); } if (model.Id != id) { this._queryRepository.Delete(query); this.ClearCacheInQueryApi(query); } model.MapTo(query); this._queryRepository.Save(query); this.ClearCacheInQueryApi(query); return Ok(); }
public dynamic Post(ExtendedQueryModel model) { if (string.IsNullOrEmpty(model.Alias)) { return BadRequest("Query moet een naam hebben."); } var account = OperatingAccount.Current(_accountRepository); if (!account.IsEditor) { return this.Unauthorized(); } if (this._queryRepository.GetByAlias(model.Alias) != null) { return BadRequest("Query met dezelfde naam bestaat reeds."); } var query = new Query(); model.MapTo(query); query.Authorization = new List<AuthorizationSettings> { new AuthorizationSettings { AccountId = account.Id, Operation = AuthorizationOperations.Edit } }; this._queryRepository.Save(query); this.ClearCacheInQueryApi(query); return Ok(); }
public dynamic PreviewQuery(string id) { var query = this._queryRepository.GetByAlias(id); if (query == null) { return NotFound(); } var model = new ExtendedQueryModel(); model.MapFrom(query, this._accountRepository.All(), this._queryRepository.All().Select(q => q.Group).Distinct()); model.Link = ApiConfiguration.Current.QueryApiUrl + model.Link.Replace("$$apikey", OperatingAccount.Current(this._accountRepository).ApiKey.ToString()); var webclient = new WebClient(); var response = webclient.DownloadString(model.Link + "&debug=true&showQuery=true&format=json"); var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(response); return data; }
public dynamic Get(string id) { var query = (id == "new") ? new Query { ApiKeys = new List<string> { OperatingAccount.Current(_accountRepository).ApiKey } } : this._queryRepository.GetByAlias(id); var model = new ExtendedQueryModel(); model.MapFrom(query, this._accountRepository.All(), this._queryRepository.All().Select(q => q.Group).Distinct()); model.Link = ApiConfiguration.Current.QueryApiUrl + model.Link.Replace("$$apikey", OperatingAccount.Current(this._accountRepository).ApiKey.ToString()); return model; }