public ActionResult AddBook(String id, String name, String author, int year, double price, int stock) { int num; if (!(Int32.TryParse(id, out num))) { return(Content("<script>alert('Please input a ID only with numbers');window.location='/Book/ShowAll';</script>")); } else if (year.GetType() != typeof(int) || year > 2017) { return(Content("<script>alert('Please input a valid year');window.location='/Book/ShowAll';</script>")); } else if (price.GetType() != typeof(double) || price < 0) { return(Content("<script>alert('Please input a valid price');window.location='/Book/ShowAll';</script>")); } else if (stock.GetType() != typeof(int) || stock < 0) { return(Content("<script>alert('Please input a valid stock');window.location='/Book/ShowAll';</script>")); } else { ServiceReference1.Book book = new ServiceReference1.Book { ID = id, name = name, author = author, year = year, price = price, stock = stock }; //write to txt file ServiceReference1.Service1Client pro = new ServiceReference1.Service1Client(); List <ServiceReference1.Book> books = pro.ReadBooks(file); books.Insert(0, book); pro.WriteBooks(books, file); return(Content("<script>alert('New book added');window.location='/Book/ShowAll';</script>")); } }
public string Edit(Book newBook) { var book = new ServiceReference1.Book() { BookId = newBook.BookId, ISBN = newBook.ISBN, Title = newBook.Title }; return(client.UpdateBook(book, book.BookId)); }
public string AddBook(Book newBook) { var book = new ServiceReference1.Book() { BookId = newBook.BookId, ISBN = newBook.ISBN, Title = newBook.Title }; return(client.AddBook(book));; }