Пример #1
0
        public ActionResult M_BookSave(BookModel bm)
        {
            //bbl.Book_Save(bm);
            //return RedirectToAction("Book");
            if (bm != null)
            {
                var mid = bbl.Check_Book(bm);

                if (mid == null || mid == "")
                {
                    HttpPostedFileBase pdf     = Request.Files["pdffile"];
                    string             pdfname = string.Empty;
                    pdfname = pdf.FileName;
                    //bm.PDF = pdfname;
                    if (!string.IsNullOrWhiteSpace(pdfname))
                    {
                        if (!Directory.Exists(BookFile))
                        {
                            Directory.CreateDirectory(BookFile);
                        }
                        string path = BookFile + bm.BookName + Path.GetExtension(pdfname);
                        pdf.SaveAs(path);
                        bm.PDF = bm.BookName + Path.GetExtension(pdfname);
                    }
                    else
                    {
                        bm.PDF = pdfname;
                    }
                    bbl.Book_Save(bm);
                }
                else
                {
                    HttpPostedFileBase pdf     = Request.Files["pdffile"];
                    string             pdfname = string.Empty;
                    pdfname = pdf.FileName;
                    //bm.PDF = pdfname;
                    if (!string.IsNullOrWhiteSpace(pdfname))
                    {
                        if (!Directory.Exists(BookFile))
                        {
                            Directory.CreateDirectory(BookFile);
                        }
                        string path = BookFile + bm.BookName + Path.GetExtension(pdfname);
                        pdf.SaveAs(path);
                        bm.PDF = bm.BookName + Path.GetExtension(pdfname);
                    }
                    else
                    {
                        DataTable dt = bbl.BookCheck(mid);
                        bm.PDF = dt.Rows[0]["PDF"].ToString();
                    }
                    bbl.Book_Update(bm);
                    //bbl.BookDelete(bm);
                }
            }
            return(RedirectToAction("Book"));
        }