internal static void Validate(this UpdateBookDetailsRequest request) { if (request == null) { throw BookstoreException.InvalidJsonData; } if (!Guid.TryParse(request.BookId, out Guid bookIdAsGuid)) { throw BookstoreException.InvalidBookId; } if (string.IsNullOrEmpty(request.Name)) { throw BookstoreException.NameNotNull; } if (string.IsNullOrEmpty(request.Description)) { throw BookstoreException.DescriptionNotNull; } if (string.IsNullOrEmpty(request.Summary)) { throw BookstoreException.SummaryNotNull; } if (request.Name.Length > 100) { throw BookstoreException.InvalidName; } if (request.Description.Length > 1000) { throw BookstoreException.InvalidDescription; } if (request.Summary.Length > 250) { throw BookstoreException.InvalidSummary; } }
internal static Book UpdateBook(this IDbConnection con, UpdateBookDetailsRequest request) { var newUpdate = con.Execute("UPDATE [dbo].[Book] SET [Title] = @Title, [Summary] = @Summary, [Description] = @Description WHERE Id = @Id", new { Id = request.BookId, Title = request.Name, Summary = request.Summary, Description = request.Description }); if (newUpdate > 0) { Guid updatedBookId = Guid.Parse(request.BookId); return(con.Select <Book>(new { Id = updatedBookId }).SingleOrDefault());; } else { throw BookstoreException.NotBookUpdated; } }
public UpdateBookDetailsResponse UpdateBook(UpdateBookDetailsRequest request) { request.Validate(); using (var connection = _DbConnectionProvider.SafelyInvoke(_logger)) { var book = connection.UpdateBook(request); if (book == null) { throw BookstoreException.BookNotFound; } var booksDetails = book.ToDetailsModel(); return(new UpdateBookDetailsResponse { BookDetails = booksDetails }); } }