public IActionResult CreateLibrary([FromBody] LibraryValue libValue) { var libName = libValue.LibraryName; if (String.IsNullOrEmpty(libName)) { return(BadRequest()); } // check if library exists already Library lib = Context.FindLibrary(libName); if (lib != null) { return(BadRequest()); } lib = new Library() { Account = (Account)HttpContext.Items["Account"], LibraryName = libName, AssetCollection = $"assets_{Path.GetFileNameWithoutExtension(Path.GetRandomFileName())}" }; Context.Libraries.InsertOne(lib); return(Ok(LibraryValue.FromModel(lib))); }
public ActionResult Edit([Bind(Include = "Id,MaxBorrows,MaxBorrowTime,TimeToCollectBook,MaxBooksToCollect")] LibraryValue libraryValue) { if (ModelState.IsValid) { db.Entry(libraryValue).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "WorkerPanel")); } return(View(libraryValue)); }
// GET: LibraryValues/Edit/5 public ActionResult Edit() { LibraryValue libraryValue = db.LibraryValues.Find(1); if (libraryValue == null) { return(HttpNotFound()); } return(View(libraryValue)); }
public IActionResult GetLibrary(string id) { Library lib = Context.FindObjectById <Library>(id); if (lib != null) { return(Ok(LibraryValue.FromModel(lib))); } else { return(NotFound()); } }
private Book SafeRead(string[] data, LibraryValue returnValue) { try { if (returnValue == LibraryValue.Book) { return(new Book(data)); } else { return(new ScienceBook(data)); } } #region FewArgument catch (ArgumentException ae) when(ae.Message.Contains("few")) { DialogResult dr = MessageBox.Show("File contain bad line with too FEW argument", "Warning", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning); if (dr == DialogResult.Abort) { MessageBox.Show("Stop File Reading", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Stop); throw new Exception("break"); } else if (dr == DialogResult.Retry) { MessageBox.Show("Data will be wrong", "Retry", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (returnValue == LibraryValue.Book) { return(new Book() { Name = data.Length > 1 ? data[0] : "Name", AmountOfPages = data.Length > 2 ? int.Parse(data[2]) : 100 }); } else { return(new ScienceBook() { Name = data.Length > 1 ? data[0] : "Name", AmountOfPages = data.Length > 2 ? int.Parse(data[2]) : 100, Author = data.Length > 3 ? data[2] : "Author", }); } } else { MessageBox.Show("Ignore this line", "Ignore", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(null); } } #endregion #region Many Argument catch (ArgumentException ae) when(ae.Message.Contains("many")) { DialogResult dr = MessageBox.Show("File contain bad line with too MANY argument", "Warning", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning); if (dr == DialogResult.Abort) { MessageBox.Show("Stop File Reading", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Stop); throw new Exception("break"); } else if (dr == DialogResult.Retry) { MessageBox.Show("Data will be lost", "Retry", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (returnValue == LibraryValue.Book) { return(new Book() { Name = data[0], AmountOfPages = int.Parse(data[2]) }); } else { return(new ScienceBook() { Name = data[0], AmountOfPages = int.Parse(data[2]), Author = data[2] }); } } else { MessageBox.Show("Ignore this line", "Ignore", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(null); } } #endregion #region Format Exeption catch (FormatException fe) { DialogResult dr = MessageBox.Show("File contain bad line with too BAD NUMBER", "Warning", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning); if (dr == DialogResult.Abort) { MessageBox.Show("Stop File Reading", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Stop); throw new Exception("break"); } else if (dr == DialogResult.Retry) { MessageBox.Show("Data will be wrong", "Retry", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (returnValue == LibraryValue.Book) { return(new Book() { Name = data.Length > 1 ? data[0] : "Name", AmountOfPages = 100 }); } else { return(new ScienceBook() { Name = data.Length > 1 ? data[0] : "Name", AmountOfPages = 100, Author = data.Length > 3 ? data[2] : "Author", }); } } else { MessageBox.Show("Ignore this line", "Ignore", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(null); } } #endregion }
public IActionResult GetLibrariesForAccount() { Account acct = (Account)HttpContext.Items["Account"]; return(Ok(LibraryValue.FromModel(acct.Libraries))); }