/// <summary> /// Updates an existing book in the system /// </summary> /// <param name="book">The book record (with its id populated)</param> public void Book_Update(DataObjects.Book book) { if (IsAuthenticated) { try { Book bookRef = DataFactory.GetBooks(SessionId).FirstOrDefault(b => b.Id == book.Id); if (bookRef == null) { throw CreateFault("NotFound", String.Format("Book with id={0} not found", book.Id)); } bookRef.AuthorId = book.AuthorId; bookRef.GenreId = book.GenreId; bookRef.Name = book.Name; } catch (Exception ex) { throw ConvertExceptions(ex); } } else { throw CreateFault("Unauthorized", "Unauthorized, call Connection_Authenticate first"); } }
/// <summary> /// Updates an existing book in the system /// </summary> /// <param name="id">The id of the book to update</param> /// <param name="session_id">The unique session id</param> /// <param name="book">The book record</param> public void Book_Update(string id, string session_id, DataObjects.Book book) { //Make sure a session id is specified if (String.IsNullOrWhiteSpace(session_id)) { throw new WebFaultException <string>("You need to pass a session_id with this request", System.Net.HttpStatusCode.BadRequest); } if (IsAuthenticated) { try { Book bookRef = DataFactory.GetBooks(session_id).FirstOrDefault(b => b.Id == book.Id); if (bookRef == null) { throw new WebFaultException <string>(String.Format("Book with id={0} not found", book.Id), System.Net.HttpStatusCode.NotFound); } bookRef.AuthorId = book.AuthorId; bookRef.GenreId = book.GenreId; bookRef.Name = book.Name; } catch (Exception ex) { throw ConvertExceptions(ex); } } else { throw new WebFaultException <string>("Unauthorized, please pass through the authentication information with the request", System.Net.HttpStatusCode.Unauthorized); } }
/// <summary> /// Adds a new book to the system /// </summary> /// <param name="book">The book data</param> /// <param name="session_id">The unique session id</param> /// <returns>The book with its id populated</returns> public DataObjects.Book Book_Insert(string session_id, DataObjects.Book book) { //Make sure a session id is specified if (String.IsNullOrWhiteSpace(session_id)) { throw new WebFaultException <string>("You need to pass a session_id with this request", System.Net.HttpStatusCode.BadRequest); } if (IsAuthenticated) { try { //Need to find the book with the maximum ID currently and increment List <Book> books = DataFactory.GetBooks(session_id); int maxIdBook = books.OrderByDescending(b => b.Id).First().Id + 1; book.Id = maxIdBook; books.Add(book); return(book); } catch (Exception ex) { throw ConvertExceptions(ex); } } else { throw new WebFaultException <string>("Unauthorized, please pass through the authentication information with the request", System.Net.HttpStatusCode.Unauthorized); } }
/// <summary> /// Adds a new book to the system /// </summary> /// <param name="book">The book data</param> /// <returns>The book with its id populated</returns> public DataObjects.Book Book_Insert(DataObjects.Book book) { if (IsAuthenticated) { try { //Need to find the book with the maximum ID currently and increment List <Book> books = DataFactory.GetBooks(SessionId); int maxIdBook = books.OrderByDescending(b => b.Id).First().Id + 1; book.Id = maxIdBook; books.Add(book); return(book); } catch (Exception ex) { throw ConvertExceptions(ex); } } else { throw CreateFault("Unauthorized", "Unauthorized, call Connection_Authenticate first"); } }