public Response <Author> Create(AuthorRequest request) { try { var messages = request.Validate(); if (messages != null && messages.Count > 0) { return(ResponseBadRequest(messages.ToList())); } _repoAuthor.Add(new Author { Birthdate = request.Birthdate, LastName = request.Lastname, Name = request.Name }); return(ResponseSuccess(null)); } catch (Exception ex) { _logger.LogError(ex, $"Exception Method {nameof(AuthorBL)}.{nameof(Create)}"); return(ResponseFail()); } }
public Response <Author> Update(string id, AuthorRequest request) { try { var messages = request.Validate(); if (messages != null && messages.Count > 0) { return(ResponseBadRequest(messages.ToList())); } if (string.IsNullOrEmpty(id) || !int.TryParse(id, out int idAuthor)) { return(ResponseBadRequest(new List <string> { MessagesResponse.BadRequest })); } var author = _repoAuthor.Get(idAuthor); if (author == null) { return(ResponseFail(CodeResponse.NotFoundAuthor, new List <string> { MessagesResponse.NotFoundAuthor })); } _repoAuthor.Update(author, new Author { Birthdate = request.Birthdate, LastName = request.Lastname, Name = request.Name }); return(ResponseSuccess(null)); } catch (Exception ex) { _logger.LogError(ex, $"Exception Method {nameof(AuthorBL)}.{nameof(Update)}"); return(ResponseFail()); } }