Exemplo n.º 1
0
        public Response <Category> Create(CategoryRequest request)
        {
            try
            {
                var messages = request.Validate();

                if (messages != null && messages.Count > 0)
                {
                    return(ResponseBadRequest(messages.ToList()));
                }

                _repoCategory.Add(new Category
                {
                    Description = request.Description,
                    Name        = request.Name
                });

                return(ResponseSuccess(null));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Exception Method {nameof(CategoryBL)}.{nameof(Create)}");
                return(ResponseFail());
            }
        }
Exemplo n.º 2
0
        public Response <Category> Update(string id, CategoryRequest request)
        {
            try
            {
                if (string.IsNullOrEmpty(id) || !int.TryParse(id, out int idCategory))
                {
                    return(ResponseBadRequest(new List <string> {
                        MessagesResponse.BadRequest
                    }));
                }

                var messages = request.Validate();

                if (messages != null && messages.Count > 0)
                {
                    return(ResponseBadRequest(messages.ToList()));
                }

                var category = _repoCategory.Get(idCategory);

                if (category == null)
                {
                    return(ResponseFail(CodeResponse.NotFoundCategory, new List <string> {
                        MessagesResponse.NotFoundCategory
                    }));
                }

                _repoCategory.Update(category, new Category {
                    Description = request.Description, Name = request.Name
                });

                return(ResponseSuccess(null));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Exception Method {nameof(CategoryBL)}.{nameof(Update)}");
                return(ResponseFail());
            }
        }