Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }