Example #1
0
        public ActionResult SaveUpdateBook(SACH sach, List <THE_LOAI> tl, List <TAC_GIA> tg, NHA_XUAT_BAN nxb, string TACGIA, string THELOAI)
        {
            if ("" != THELOAI)
            {
                if (tl == null)
                {
                    tl = new List <THE_LOAI>();
                }
                THE_LOAI cate = new THE_LOAI();
                cate.MA_THE_LOAI = THELOAI;
                tl.Add(cate);
            }

            if ("" != TACGIA)
            {
                if (tg == null)
                {
                    tg = new List <TAC_GIA>();
                }
                TAC_GIA author = new TAC_GIA();
                author.TEN_TAC_GIA = TACGIA;
                tg.Add(author);
            }
            try
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];
                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/img/Books"), fileName);
                        file.SaveAs(path);
                        sach.ANH = "/img/Books/" + fileName;
                    }
                }
                BookDetails book = new BookDetails(sach, tg, tl, nxb);
                BookContext.UpdateBook(book);
            }
            catch (Exception ex)
            {
                return(Content("<script>alert(" + ex.Message + ");</script>"));
            }
            return(RedirectToAction("Index"));
        }