// GET: Manga public ActionResult Index(int id) { var dao = new MangaDao(); var mangaId = id.ToString(); if (String.IsNullOrEmpty((string)Session[mangaId])) { dao.AddView(id); Session[mangaId] = "Đã xem"; } var manga = db.Mangas.Where(i => i.mId == id).FirstOrDefault(); var item = new MangaDetail(); item.mId = manga.mId; var chapter = db.Chapters.OrderByDescending(i => i.cId) .Where(i => i.mId == manga.mId).FirstOrDefault(); item.displayName = chapter == null ? manga.mName : chapter.cName; item.createdBy = db.Users.Where(i => i.uId == manga.CreatedBy).FirstOrDefault().displayName; item.updatedAt = manga.updatedAt; item.chapters = manga.mChapter; item.totalComment = manga.totalComment; item.image = manga.image; item.description = manga.mDescription; item.author = manga.mAuthor; item.totalView = manga.totalView; var categories = db.Categories.Where(i => i.mId == item.mId).Join(db.CategoryDetails, d => d.categoryId, f => f.categoryId, (d, f) => new { Category = d, CategoryDetail = f }); item.listCategories = categories.Select(i => new CategoryModel { id = i.Category.categoryId, displayName = i.CategoryDetail.categoryName }).ToList(); return(View(item)); }
public void AddCategory(int mId, IEnumerable <int> list) { var dao = new MangaDao(); var oldCategories = db.Categories.Where(i => i.mId == mId); db.Categories.RemoveRange(oldCategories); foreach (var i in list) { var category = new Category(); category.mId = mId; category.categoryId = i; dao.AddCategory(category); } }
public ActionResult UnPublished(int id) { var user = (UserLogin)Session[Constants.USER_SESSION]; var manga = db.Mangas.Where(i => i.mId == id).FirstOrDefault(); MangaDao dao = new MangaDao(); if (user.UserName == "admin" || user.UserId == manga.CreatedBy) { dao.UnPublishedManga(id); } else { return(RedirectToAction("Error")); } return(RedirectToAction("Index", "Manage")); }
public ActionResult AddChapter(ChapterDetail chapter) { var dao = new MangaDao(); var path = ""; var fileName = ""; var imgList = new List <ImageViewModel>(); var user = (UserLogin)Session[Constants.USER_SESSION]; if (chapter.imgFile.Any()) { var c = new Chapter(); c.cName = chapter.displayName; c.cPostOn = DateTime.Now; c.mId = chapter.mId; var cId = dao.AddChapter(c); var currentDir = Path.Combine(HttpRuntime.AppDomainAppPath, "Image", chapter.mId.ToString(), cId.ToString()); if (!Directory.Exists(currentDir)) { Directory.CreateDirectory(currentDir); } foreach (var file in chapter.imgFile) { fileName = file.FileName; if (file.ContentLength > 0) { if (Path.GetExtension(fileName).ToLower() == ".jpg" || Path.GetExtension(fileName).ToLower() == ".png" || Path.GetExtension(fileName).ToLower() == ".gif" || Path.GetExtension(fileName).ToLower() == ".jpeg") { file.SaveAs(Path.Combine(currentDir, fileName)); var image = new ImageViewModel(); image.src = "/Image/" + c.mId.ToString() + "/" + c.cId.ToString() + "/" + fileName; imgList.Add(image); } } } foreach (var img in imgList) { var i = new Image(); i.cId = cId; i.source = img.src; dao.AddImage(i); } } return(RedirectToAction("UploadedManga")); }
public ActionResult DeleteChapter(int id) { MangaDao dao = new MangaDao(); var chapter = db.Chapters.Where(i => i.cId == id).FirstOrDefault(); var manga = db.Mangas.Where(i => i.mId == chapter.mId).FirstOrDefault(); var user = (UserLogin)Session[Constants.USER_SESSION]; if (user.UserName == "admin" || user.UserId == manga.CreatedBy) { dao.RemoveChapter(chapter); } else { return(RedirectToAction("Error")); } return(RedirectToAction("Index", "Manage")); }
public ActionResult Create(MangaDetail item) { var path = ""; var fileName = ""; var user = (UserLogin)Session[Constants.USER_SESSION]; if (item.imgFile != null) { fileName = item.imgFile.FileName; if (item.imgFile.ContentLength > 0) { var manga = new Manga(); manga.mName = item.displayName; manga.publishedAt = DateTime.Now; manga.updatedAt = DateTime.Now; manga.mAuthor = item.author; manga.CreatedBy = user.UserId; manga.mDescription = item.description; MangaDao dao = new MangaDao(); int id = dao.AddManga(manga); AddCategory(id, item.categories); if (Path.GetExtension(fileName).ToLower() == ".jpg" || Path.GetExtension(fileName).ToLower() == ".png" || Path.GetExtension(fileName).ToLower() == ".gif" || Path.GetExtension(fileName).ToLower() == ".jpeg") { string currentDir = Path.Combine(HttpRuntime.AppDomainAppPath, "Image"); if (!Directory.Exists(Path.Combine(currentDir, id.ToString()))) { Directory.CreateDirectory(Path.Combine(currentDir, id.ToString())); } string dir = Path.Combine(currentDir, id.ToString()); path = Path.Combine(dir, fileName); item.imgFile.SaveAs(path); var _manga = db.Mangas.Where(i => i.mId == id).FirstOrDefault(); _manga.image = "/Image/" + manga.mId.ToString() + "/" + item.imgFile.FileName; db.SaveChanges(); } } } return(RedirectToAction("Index", "Manage")); }
public void InserirNovoManga(MangaEntidades manga) { _mangaDao = new MangaDao(); var linhasAfetadas = _mangaDao.InserirManga(manga); }