public void AddingNovel() { NovelModel nv = new NovelModel(); nv.Name = "new novel"; nv.Image_link = "#"; nv.Author = "Tony"; nv.Chap_number = 1; DBModel db = new DBModel(); bool novel = db.AddNewNovel(nv); Assert.IsTrue(novel); //check that add new novel is success or not }
public IActionResult Upload(NovelModel novel) { if (novel.Name != null && novel.Author != null && novel.Link != null) { novel.upload_date = DateTime.Now; novel.Owner = Request.Cookies["userID"].ToString(); string image_sourceFile = @"C:\Users\lythe\Desktop\" + novel.Image_link; string image_destinationFile = @"~/database/Image/" + novel.Image_link; string sourceFile = @"C:\Users\lythe\Desktop\" + novel.Link; string destinationFile = "~/database/novel_book/" + novel.Link; System.IO.File.Copy(image_sourceFile, image_destinationFile, true); System.IO.File.Copy(sourceFile, destinationFile, true); DBModel db = new DBModel(); int chap = 1; //get maximum chapter using (StreamReader sr = new StreamReader("~/database/novel_book/" + novel.Link)) { string line = sr.ReadLine(); //first is a chapter while (line != null) { if (line.ToLower() == ("chapter " + chap)) { chap += 1; } line = sr.ReadLine(); } } novel.Chap_number = chap - 1; db.AddNewNovel(novel); return(Redirect("/Home/Index/")); } else { return(Redirect("/Novel/Upload/")); } }