public void CreateEditBook(BookForm item) { Book book = BookFactory.Build(item.Id, item.Name, item.AuthorId, item.PublicationDate, item.Description); if (item.Id != Guid.Empty) // изменение { DbOfWork.Books.Update(book); if (item.GenreIds != null) { DbOfWork.BookGenres.UpdateGenre(book.Id, item.GenreIds.ToList()); } else { DbOfWork.BookGenres.UpdateGenre(book.Id, null); } } else // создание { DbOfWork.Books.Create(book); if (item.GenreIds != null) { DbOfWork.BookGenres.UpdateGenre(book.Id, item.GenreIds.ToList()); } else { DbOfWork.BookGenres.UpdateGenre(book.Id, null); } } DbOfWork.Save(); }
// Checking PublicationDate public async Task Test3() { string errorMessage = "PublicationDate is invalid: PublicationDate must be after 01/01/1900 and before the current date"; await CheckOnBadRequest(new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "Patrick Waterhouse", PublicationDate = DateTime.Parse("05/03/1888", new CultureInfo("en")) }, errorMessage); await CheckOnBadRequest(new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "Patrick Waterhouse", PublicationDate = DateTime.Now.AddDays(2) }, errorMessage); var book = new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "Patrick Waterhouse", PublicationDate = DateTime.Parse("05/03/2018", new CultureInfo("en")) }; var response3 = await Client.PostAsync($"/api/books", new StringContent(JsonConvert.SerializeObject(book), Encoding.UTF8, "application/json")); response3.StatusCode.Should().BeEquivalentTo(StatusCodes.Status200OK); }
public bool Validate(BookForm form) { bool result = true; if (!string.IsNullOrWhiteSpace(form.Name)) { if (form.Name.Length > 100) { result = false; Exceptions.Add(new ValidatonException("Длина имени превышает допустимое значение", "")); } } else { result = false; Exceptions.Add(new ValidatonException("Имя пустое или состоит из пробельных символов", "")); } if (!string.IsNullOrWhiteSpace(form.Description)) { if (form.Description.Length > 1000) { result = false; Exceptions.Add(new ValidatonException("Длина описания превышает допустимое значение", "")); } } else { result = false; Exceptions.Add(new ValidatonException("Описание пустое или состоит из пробельных символов", "")); } return(result); }
private async Task CheckOnBadRequest(BookForm book, string errorMessage) { var response0 = await Client.PostAsync($"/api/books", new StringContent(JsonConvert.SerializeObject(book), Encoding.UTF8, "application/json")); response0.StatusCode.Should().BeEquivalentTo(StatusCodes.Status400BadRequest); var responseMessage = await response0.Content.ReadAsStringAsync(); responseMessage.Contains(errorMessage).Should().BeTrue(); }
public IActionResult Book(BookForm form) { Customer c = new Customer(1, form.ClientName, form.ClientSurname); //repo.bookings.Add(new Booking(c, new Movie("ASD", "asd", new Cinema(1, "test")))); var cinema = repo.cinemas.Find(x => x.GetDescription().Equals(form.CinemaName)); repo.bookings.Add(new Booking(c, new Movie(form.MovieName, form.Date, cinema))); // repo.bookings.Add(); return(View(repo.bookings)); }
public object[] getBookSearchParm() { BookForm bookForm = Program.MainForm.BookForm; object[] arr = new object[11]; arr[0] = getValueOfTextBox(bookForm.searchBookID); arr[1] = getValueOfTextBox(bookForm.searchBookName); arr[2] = getValueOfComboBox(bookForm.searchBookStatus); arr[3] = getValueOfNum(bookForm.searchBookYear); arr[4] = getValueOfNum(bookForm.searchBookPrice); arr[5] = getValueOfComboBox(bookForm.searchBookType); arr[6] = getValueOfComboBox(bookForm.searchBookLocation); arr[7] = getValueOfComboBox(bookForm.searchBookNXB); arr[8] = getValueOfComboBox(bookForm.searchBookAuthor); arr[9] = getValueOfComboBox(bookForm.searchMuonTra); arr[10] = 100; return(arr); }
public async Task <IActionResult> UploadFile([FromForm] BookForm book) { if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { return(BadRequest($"Expected a multipart request, but got {Request.ContentType}")); } try { using (var stream = book.Image.OpenReadStream()) { var cloudBlock = await UploadToBlob(book.Image.FileName, null, stream); //// Retrieve the filename of the file you have uploaded //var filename = provider.FileData.FirstOrDefault()?.LocalFileName; if (string.IsNullOrEmpty(cloudBlock.StorageUri.ToString())) { return(BadRequest("An error has occured while uploading your file. Please try again.")); } //BookTag tagsList = new Book bookItem = new Book() { Created = DateTime.Now, Title = book.Title, CoverUrl = cloudBlock.SnapshotQualifiedUri.AbsoluteUri, Author = book.Author, ISBN = book.ISBN, YearPublished = book.YearPublished, BookRating = book.BookRating, BookReview = book.BookReview, BookTags = _bookService.ParseTags(book.tags) }; await _bookService.AddBookAsync(bookItem); return(Ok($"File: {book.Title} has successfully uploaded")); } } catch (Exception ex) { return(BadRequest($"An error has occured. Details: {ex.Message}")); } }
// Checking Author public async Task Test2() { string errorMessage = "Author is invalid: Author must contain a minimum of 3 characters and a maximum of 30, and the first letter should be in upper case"; await CheckOnBadRequest(new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "Pa", PublicationDate = DateTime.Parse("05/03/2018", new CultureInfo("en")) }, errorMessage); await CheckOnBadRequest(new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "", PublicationDate = DateTime.Parse("05/03/2018", new CultureInfo("en")) }, errorMessage); await CheckOnBadRequest(new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "Patrick Waterhouse with H. Macdonald SteelsPatrick Waterhouse with H. Macdonald SteelsPatrick Waterhouse with H. Macdonald SteelsPatrick Waterhouse with H. Macdonald SteelsPatrick Waterhouse", PublicationDate = DateTime.Parse("05/03/2018", new CultureInfo("en")) }, errorMessage); await CheckOnBadRequest(new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "patrick Waterhouse with H. Macdonald Steels", PublicationDate = DateTime.Parse("05/03/2018", new CultureInfo("en")) }, errorMessage); var book = new BookForm { Title = "Initial Professional Development for Civil Engineers, Second edition", Author = "Patrick Waterhouse", PublicationDate = DateTime.Parse("05/03/2018", new CultureInfo("en")) }; var response3 = await Client.PostAsync($"/api/books", new StringContent(JsonConvert.SerializeObject(book), Encoding.UTF8, "application/json")); response3.StatusCode.Should().BeEquivalentTo(StatusCodes.Status200OK); }
private void btn_Click(object sender, EventArgs e) { int holder = int.Parse(txtPINEntry.Text); if (Globals.BookStore.EmployeeList.verifyPin(holder)) { this.Hide(); BookForm BookForm = new BookForm(); BookForm.Show(); } else { tryCount++; txtPINEntry.Text = ""; txtPINEntry.Focus(); if (tryCount == Globals.BookStore.tryCountMax) { MessageBox.Show("Max attempts reached. Force exitting now...", "Intrusion Alert!"); this.Close(); } } }
public JsonResult HandleAddBook(EmployeeForm eform) { var success = false; var reason = "unknown"; Console.WriteLine(eform.Data); BookForm form = JsonSerializer.Deserialize <BookForm>(eform.Data); try { var absoluteImagePath = Path.GetFullPath(".") + "\\wwwroot\\images\\" + form.ImageName; var imageBase64 = form.Image.Replace("data:image/jpeg;base64,", ""); var handler = new ConnectionHandler(); using (MySqlConnection connection = handler.Connection) { string sql = "SELECT * FROM Books WHERE ISBN=@ISBN"; MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.Parameters.AddWithValue("@ISBN", form.ISBN); var hasBookAlready = false; using (MySqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { hasBookAlready = true; } } if (!hasBookAlready) { cmd.CommandText = "INSERT INTO Books(ISBN,title,genre,author,summary,imagePath) VALUES (@ISBN,@TITLE,@GENRE,@AUTHOR,@SUMMARY,@IMAGEPATH)"; cmd.Parameters.AddWithValue("@TITLE", form.Title); cmd.Parameters.AddWithValue("@GENRE", form.Genre); cmd.Parameters.AddWithValue("@AUTHOR", form.Author); cmd.Parameters.AddWithValue("@SUMMARY", form.Summary); cmd.Parameters.AddWithValue("@IMAGEPATH", form.ImageName); cmd.ExecuteNonQuery(); System.IO.File.WriteAllBytes(absoluteImagePath, Convert.FromBase64String(imageBase64)); success = true; } else { reason = "bookExists"; } } } catch (Exception ex) { success = false; Console.WriteLine(ex); } if (success) { reason = "none"; } return(new JsonResult($"{{\"success\":\"{success}\"," + $"\"reason\":\"{reason}\"}}", new System.Text.Json.JsonSerializerOptions())); }
internal void LaunchBookDialog(Books b) { BookForm bf = new BookForm(b); if (bf.ShowDialog() == DialogResult.OK) { //Update Patrons View RefreshPatrons(); } }
internal void LaunchBookCreateDialog() { BookForm bf = new BookForm(); if (bf.ShowDialog() == DialogResult.OK) { //Create Book Dialog RefreshAllBooksMedia(); } }
private void ShowBooksButton_Click(object sender, EventArgs e) { var Form = new BookForm(ChosenAuthor); Form.Show(); }
private void EditBookButton_Click(object sender, EventArgs e) { BookForm frm = new BookForm(this, selectedBook); frm.Show(); }
private void NewBookButton_Click(object sender, EventArgs e) { BookForm frm = new BookForm(this); frm.Show(); }