public async Task <IActionResult> Edit(int id, [Bind("Id,BookId,AuthorId")] Wrote wrote) { if (id != wrote.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(wrote); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WroteExists(wrote.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var book = await _context.Books.FindAsync(wrote.BookId); ViewData["AuthorId"] = new SelectList(_context.Authors, "Id", "Name", wrote.AuthorId); ViewData["BookId"] = new SelectList(_context.Books, "Id", "Name", wrote.BookId); return(RedirectToAction("Index", "Wrotes", new { id = book.Id, name = book.Name })); }
public string WriteOutput(string input) { Console.WriteLine(input); Wrote?.Invoke(this, new ConsoleEventArgs { Message = input }); return(input); }
public static void Write() { var bytes = MessagePackSerializer.Serialize(MainWindow.MainViewModel); if (!Directory.Exists(PATH)) { Directory.CreateDirectory(PATH); } File.WriteAllBytes(FILEPATH, bytes); Wrote?.Invoke(bytes); }
public async Task <IActionResult> Create(int?BookId, [Bind("Id,BookId,AuthorId")] Wrote wrote) { ViewBag.BookId = BookId; wrote.BookId = ViewBag.BookId; var Book = await _context.Books.FindAsync(BookId); if (ModelState.IsValid) { _context.Add(wrote); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Wrotes", new { id = Book.Id, name = Book.Name })); } ViewData["AuthorId"] = new SelectList(_context.Authors, "Id", "Name", wrote.AuthorId); ViewData["BookId"] = new SelectList(_context.Books, "Id", "Name", wrote.BookId); return(RedirectToAction("Index", "Wrotes", new { id = Book.Id, name = Book.Name })); }
/// <summary> /// Writes the settings. /// </summary> public void Write() { try { // valide settings values Validate(); // write settings values using (var stream = new FileStream(Target, FileMode.Create, FileAccess.Write)) { var serializer = new DataContractJsonSerializer(typeof(UserSettings)); serializer.WriteObject(stream, this); } Wrote?.Invoke(this, EventArgs.Empty); } catch (Exception exception) { throw new InvalidOperationException("failed to save settings", exception); } }
private void AddBook(IXLRow row, IXLWorksheet worksheet, Genre newcat) { Book book = new Book(); book.Name = row.Cell(1).Value.ToString(); book.Genre = newcat; book.YearWritten = Convert.ToInt32(row.Cell(6).Value.ToString()); book.Isbn = Convert.ToInt32(row.Cell(7).Value.ToString()); _context.Books.Add(book); if (!BookExists(book.Name)) { for (int i = 2; i <= 5; i++) { if (row.Cell(i).Value.ToString().Length > 0) { Wrote wr = new Wrote(); wr.Book = book; wr.Author = AddAuthor(row, i); _context.Wrotes.Add(wr); } } for (int i = 8; i <= 10; i++) { if (row.Cell(i).Value.ToString().Length > 0) { Description ds = new Description(); ds.Book = book; ds.Tag = AddTag(row, i); _context.Descriptions.Add(ds); } } } else { throw new InvalidOperationException("Input file contains existing books."); } }