Exemplo n.º 1
0
        public ActionResult AddBookSubmit()
        {
            HttpPostedFileBase file = Request.Files["picture"];

            // Initiate a class instance
            Books book = new Books();
            Authors author = new Authors();

            // Save the book added
            string title = Request.Form["title"];
            string auteur = Request.Form["author"];
            auteur = author.GetIdByName(auteur);
            string synopsis = Request.Form["synopsis"];

            string picture = "";
            if (file != null && file.ContentLength > 0)
            {
                string fname = System.IO.Path.GetFileName(file.FileName);
                file.SaveAs(Server.MapPath(System.IO.Path.Combine("~/Content/img", fname)));
                picture = "../Content/img/" + fname;

                book.AddBooks(title, auteur, picture, synopsis);
            }
            else
            {
                book.AddBooks(title, auteur, synopsis);
            }

            return RedirectToAction("Books");
        }
Exemplo n.º 2
0
        public ActionResult AddAuthorSubmit()
        {
            HttpPostedFileBase file = Request.Files["picture"];

            // Initiate a class instance
            Authors author = new Authors();

            // Save the author added
            string name = Request.Form["name"];
            string picture = "";
            if(file != null && file.ContentLength > 0)
            {
                string fname = System.IO.Path.GetFileName(file.FileName);
                file.SaveAs(Server.MapPath(System.IO.Path.Combine("~/Content/img", fname)));
                picture = "../Content/img/" + fname;

                author.AddAuthors(name, picture);
            }
            else
            {
                author.AddAuthors(name);
            }

            return RedirectToAction("Authors");
        }
        private void AddAuthor(object sender, EventArgs e)
        {
            if (saveBtn.Text == "Save")
            {
                Regex letters      = new Regex(@"^[A-Za-z ]+$");
                Match nameMatch    = letters.Match(nameBox.Text);
                Match surnameMatch = letters.Match(surnameBox.Text);

                if (nameMatch.Success && surnameMatch.Success)
                {
                    Models.Authors a1 = new Models.Authors();
                    a1.Id      = ab.AuthorId;
                    a1.Name    = nameBox.Text;
                    a1.Surname = surnameBox.Text;


                    using (LibraryEntities db = new LibraryEntities())
                    {
                        db.Authors.Add(a1);
                        db.SaveChanges();
                    }

                    FillAuthors();
                    nameBox.Clear();
                    surnameBox.Clear();
                }
                else
                {
                    MessageBox.Show("Surname and name contain only letters");
                }
            }
            else
            {
                using (LibraryEntities db = new LibraryEntities())
                {
                    int authorId = Convert.ToInt32(authorTable.SelectedRows[0].Cells[0].Value);

                    Models.Authors newAuthor = db.Authors.Where(a => a.Id == authorFound.Id).FirstOrDefault();

                    newAuthor.Id = authorId;
                    Regex letters      = new Regex(@"^[A-Za-z ]+$");
                    Match nameMatch    = letters.Match(nameBox.Text);
                    Match surnameMatch = letters.Match(surnameBox.Text);

                    if (nameMatch.Success && surnameMatch.Success)
                    {
                        newAuthor.Name    = nameBox.Text;
                        newAuthor.Surname = surnameBox.Text;
                    }
                    else
                    {
                        MessageBox.Show("Surname and name contain only letters");
                    }
                    db.SaveChanges();
                    FillAuthors();
                }
            }
        }
Exemplo n.º 4
0
        public ActionResult AddBook()
        {
            Authors authors = new Authors();

            var authorsName = authors.GetNameAuthors();

            ViewBag.AuthorsName = authorsName;

            return View();
        }
 private void DeleteAuthor(object sender, EventArgs e)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         int            authorId = Convert.ToInt32(authorTable.SelectedRows[0].Cells[0].Value);
         Models.Authors a1       = db.Authors.Where(a => a.Id == authorId).FirstOrDefault();
         db.Authors.Remove(a1);
         db.SaveChanges();
     }
     FillAuthors();
     Reset();
 }
Exemplo n.º 6
0
        // GET: Authors
        public ActionResult Authors()
        {
            // Initiate a class instance
            Authors author = new Authors();

            // Get all the authors from the database
            var authors = new List<Tuple<string, string, string>>();
            authors = author.GetAllAuthors();

            ViewBag.Authors = authors;

            return View();
        }
        private void AuthorTable_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int authorId = Convert.ToInt32(authorTable.Rows[e.RowIndex].Cells[0].Value);

            using (LibraryEntities db = new LibraryEntities())
            {
                authorFound = db.Authors.Where(a => a.Id == authorId).FirstOrDefault();
                if (authorFound != null)
                {
                    nameBox.Text    = authorFound.Name;
                    surnameBox.Text = authorFound.Surname;
                }

                saveBtn.Text      = "Update";
                deleteBtn.Enabled = true;
            }
        }
Exemplo n.º 8
0
        public ActionResult AuthorBooks(string id)
        {
            // Initiate a class instance
            Authors author = new Authors();

            // Get author's books
            var authorBooks = new List<Tuple<string, string, string, string>>();
            authorBooks = author.GetAuthorBooks(id);

            Books book = new Books();
            string authorName;
            authorName = book.GetNameAuthor(id);

            ViewBag.AuthorBooks = authorBooks;
            ViewBag.AuthorName = authorName;

            return View();
        }