Exemple #1
0
        public async Task <IActionResult> AddResourceItem([FromBody] GroupResourceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ErrorResponse.Create(ModelState.GetErrorMessage())));
            }

            if (!model.Name.IsValidPartitionOrRowKey())
            {
                return(BadRequest(ErrorResponse.Create($"Invalid {nameof(model.Name)} value")));
            }

            if (string.IsNullOrWhiteSpace(model.Value.Id))
            {
                return(BadRequest(ErrorResponse.Create("Id can't be empty")));
            }

            if (string.IsNullOrWhiteSpace(model.Value.Value))
            {
                return(BadRequest(ErrorResponse.Create("Value can't be empty")));
            }

            await _groupResourcesService.AddOrUpdateItemAsync(model.Name, model.Value);

            return(Ok());
        }
Exemple #2
0
        public IActionResult GetGroupResourceSection(string name)
        {
            if (!name.IsValidPartitionOrRowKey())
            {
                return(BadRequest(ErrorResponse.Create($"Invalid {nameof(name)} value")));
            }

            var resources = _groupResourcesService.GetGroup(name).ToList();

            if (resources.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(resources));
        }
Exemple #3
0
        public IActionResult GetResource(string name)
        {
            if (!name.IsValidPartitionOrRowKey())
            {
                return(BadRequest(ErrorResponse.Create($"Invalid {nameof(name)} value")));
            }

            var resource = _groupResourcesService.Get(name);

            if (resource == null)
            {
                return(NotFound());
            }

            return(Ok(resource));
        }
Exemple #4
0
        public async Task <IActionResult> AddResources([FromBody] GroupResourcesModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ErrorResponse.Create(ModelState.GetErrorMessage())));
            }

            if (!model.Name.IsValidPartitionOrRowKey())
            {
                return(BadRequest(ErrorResponse.Create($"Invalid {nameof(model.Name)} value")));
            }

            var group = _groupResourcesService.Get(model.Name);

            if (group != null)
            {
                return(BadRequest(ErrorResponse.Create($"'{model.Name}' group is already exists")));
            }

            if (model.Values.Length == 0)
            {
                return(BadRequest(ErrorResponse.Create($"{nameof(model.Values)} is empty")));
            }

            if (model.Values.Any(item => string.IsNullOrWhiteSpace(item.Id)))
            {
                return(BadRequest(ErrorResponse.Create("Id can't be empty")));
            }

            if (model.Values.Any(item => string.IsNullOrWhiteSpace(item.Value)))
            {
                return(BadRequest(ErrorResponse.Create("Value can't be empty")));
            }

            var ids = model.Values.Select(item => item.Id).Distinct().ToArray();

            if (ids.Length != model.Values.Length)
            {
                return(BadRequest(ErrorResponse.Create("Id must be unique")));
            }

            await _groupResourcesService.AddAsync(model.Name, model.Values);

            return(Ok());
        }
Exemple #5
0
        public async Task <IActionResult> DeleteResourceItem([FromBody] DeleteGroupResourceItemModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ErrorResponse.Create(ModelState.GetErrorMessage())));
            }

            if (!model.Name.IsValidPartitionOrRowKey())
            {
                return(BadRequest(ErrorResponse.Create($"Invalid {nameof(model.Name)} value")));
            }

            var res = _groupResourcesService.Get(model.Name);

            if (res == null)
            {
                return(BadRequest($"Group resource with name '{model.Name}' not found"));
            }

            await _groupResourcesService.DeleteItemAsync(model.Name, model.Id);

            return(Ok());
        }