コード例 #1
0
        public ActionResult GeneralBooks(GeneralBookViewModel gbvm, HttpPostedFileBase inputFile) {
            if (!string.IsNullOrEmpty(gbvm.GeneralBook.Title)) {
                if (!string.IsNullOrEmpty(gbvm.GeneralBook.Subject)) {
                    if (!string.IsNullOrEmpty(gbvm.GeneralBook.Year)) {
                        if (inputFile != null && inputFile.ContentLength > 0) {
                            if (inputFile.ContentType == "application/pdf") {
                                Guid FileName = Guid.NewGuid();
                                gbvm.GeneralBook.FilePath = "/Uploads/GeneralBooks/" + FileName + ".pdf";
                                string tPath = Path.Combine(Server.MapPath("~/Uploads/GeneralBooks/"), FileName + ".pdf");
                                inputFile.SaveAs(tPath);

                                gbvm.GeneralBook.CreatedBy = Request.Cookies["INDMS"]["UserID"];
                                gbvm.GeneralBook.CreatedDate = null;

                                db.GeneralBooks.Add(gbvm.GeneralBook);
                                db.SaveChanges();

                                TempData["RowId"] = gbvm.GeneralBook.ID;
                                TempData["MSG"] = "Save Successfully";

                                return RedirectToAction("GeneralBooks");
                            }
                            else {
                                TempData["Error"] = "Please Select PDF Files Only.";
                            }
                        }
                        else {
                            TempData["Error"] = "Please Select File";
                        }
                    }
                    else {
                        TempData["Error"] = "Please Enter Year";
                    }
                }
                else {
                    TempData["Error"] = "Please Enter Title";
                }
            }
            else {
                TempData["Error"] = "Please Enter Title";
            }

            gbvm.GeneralBooks = db.GeneralBooks.OrderByDescending(x => x.ID);
            return View();
        }
コード例 #2
0
 public ActionResult GeneralBooks() {
     GeneralBookViewModel gbvm = new GeneralBookViewModel();
     gbvm.GeneralBooks = db.GeneralBooks.OrderByDescending(x => x.ID);
     return View(gbvm);
 }