public ActionResult Chapter(String namechapter, HttpPostedFileBase[] files, String comicId) { if (CheckStatusUser()) { return(RedirectToAction("Login")); } if (!CheckViewer()) { chapter chapter = new chapter(); chapter.NameChapter = namechapter; chapter.ComicId = Convert.ToInt32(comicId); int userId = _user.UserId; ChapterDAO chapterDao = new ChapterDAO(); var c = chapterDao.Add(chapter, userId); Messenger mss = new Messenger(); if (c != null) { String path = String.Format("~{0}", c.FolderImage); path = Server.MapPath(path); int s = 0; int f = 0; for (int i = 0; i < files.Length; i++) { Messenger messenger = UploadFile.Upload(files[i], path, String.Format("{0}.jpg", i)); if (messenger.Code == 1) { s++; } else { f++; } } mss.Mss = String.Format("Tải lên thành công {0}, thất bại {1}", s, f); mss.Code = 1; } else { mss.Code = 0; } var chapters = chapterDao.ListChapterComic(Convert.ToInt32(comicId)); ViewBag.Mss = mss; ViewBag.Chapters = chapters; return(View()); } return(View()); }
public int Delete(chapter ct, int userId) { var chapter = WcDbContext.chapters.Single(c => c.ChapterId == ct.ChapterId && c.comic.UserId == userId); var sql = WcDbContext.chapters.Remove(chapter); var n = WcDbContext.SaveChanges(); return(n); }
// Use this for initialization void Awake() { //If this is a duplicate of the original persistant LevelManager then destroy this GO if (FindObjectsOfType(GetType()).Length > 1) { Destroy(gameObject); } DontDestroyOnLoad(gameObject);//Don't destroy this gameobject between scenes, it will be used between scenes for loading levels //Get data path to chapters, can just add "[number].json" to end of this stub to get a chapter chapterFilePathStub = Application.persistentDataPath + "/chapter"; currentChapter = null;//Current chapter is null by default until one is loaded }
public chapter Add(chapter chapter) { var c = WcDbContext.chapters.Add(chapter); WcDbContext.SaveChanges(); c.FolderImage = String.Format("/Upload/truyen/{0}/{1}", c.ComicId, c.ChapterId); var comic = WcDbContext.comics.Single(comic1 => comic1.ComicId == c.ComicId); comic.UpdateAt = DateTime.Now; WcDbContext.SaveChanges(); return(c); }
public chapter Add(chapter chapter, int userId) { var comic = WcDbContext.comics.Single(c => c.UserId == userId && c.user.RoleId < 3 && c.StatusComicId < 4 && c.ComicId == chapter.ComicId); if (comic != null) { var checkeName = WcDbContext.chapters.Where(chapter1 => chapter1.NameChapter.Equals(chapter.NameChapter) && chapter1.ComicId == chapter.ComicId) .Count(); if (checkeName == 0) { var num = WcDbContext.chapters.Where(chapter1 => chapter1.ComicId == chapter.ComicId) .Max(chapter1 => chapter1.NumChapter); if (num != null) { chapter.NumChapter = num + 1; } //thêm chapter var ct = WcDbContext.chapters.Add(chapter); //Cập nhật time comic.UpdateAt = DateTime.Now; ct.FolderImage = String.Format("/Upload/truyen/{0}/{1}_{2}", ct.ComicId, ct.NameChapter.Replace(" ", "_"), DateTime.Now.ToString("ddMMyy_hhmm")); WcDbContext.SaveChanges(); return(ct); } } return(null); }
//xóa chapter public Boolean DeleteChapter() { if (CheckStatusUser()) { return(false); } if (!CheckViewer()) { chapter chapter = new chapter(); chapter.ChapterId = Convert.ToInt32(Request["id"]); int userId = _user.UserId; ChapterDAO chapterDao = new ChapterDAO(); var n = chapterDao.Delete(chapter, userId); return(n == 1); } return(false); }
//Loads given chapter from file for future level loading public void loadChapter(int chapter) { chapterNumber = chapter; //Store current chapter number for future use string chapterFilePath = chapterFilePathStub + chapter + ".json"; //Get full file path to this chapter Debug.Log("Loaded: " + chapterFilePath); //ALL THIS FILE CHECKING STUFF SHOULD GO FOR FINAL RELEASE, ABSOLUTELY NOT NECESSARY BUT KINDA MAKES ANY TWEAKS DURING DEV EASIER //If chapter save file doesn't exist at persistent path, load the default from Resources and store its file at correct path if (!File.Exists(chapterFilePath)) { File.WriteAllText(chapterFilePath, Resources.Load <TextAsset>("chapter" + chapter).text); currentChapter = JsonUtility.FromJson <chapter>(File.ReadAllText(chapterFilePath)); //Use Unity's json parser to parse in text from file //Convert into serializable levelCollection class and get the resulting array of levels //Get saves from file and store them in a list } else//Check if level file is consistent with how levels are supposed to be, will make updates easier but maintain save info { currentChapter = JsonUtility.FromJson <chapter>(File.ReadAllText(chapterFilePath)); //Load in save file level[] levelsCheck = JsonUtility.FromJson <chapter>(Resources.Load <TextAsset>("chapter" + chapter).text).levels; //Load in official default file to check against bool changeFound = false; //Whether a change has been found between save file and default for (int i = 0; i < currentChapter.levels.Length; i++) { //If a disparity is found, set stored level to match default official one if (levelsCheck[i].tiles.Length != currentChapter.levels[i].tiles.Length || levelsCheck[i].par != currentChapter.levels[i].par) { currentChapter.levels[i] = levelsCheck[i]; changeFound = true; } else { for (int j = 0; j < levelsCheck[i].tiles.Length; j++) { //Debug.Log(JsonUtility.ToJson(currentChapter.levels[i].tiles[j])); if (JsonUtility.ToJson(currentChapter.levels[i].tiles[j]) != JsonUtility.ToJson(levelsCheck[i].tiles[j])) { currentChapter.levels[i] = levelsCheck[i]; break; } if (j >= levelsCheck[i].tiles.Length) { levelsCheck[i].best = currentChapter.levels[i].best; } } } } //If there's less levels in file than should be, reset to newer levels (this will retain high scores) if (currentChapter.levels.Length != levelsCheck.Length) { currentChapter.levels = levelsCheck; changeFound = true; } //If change was found, overwrite old save file with updated one if (changeFound) { File.WriteAllText(chapterFilePathStub + chapterNumber + ".json", JsonUtility.ToJson(currentChapter)); } } setupLevelButtons(); //Set up level buttons for chapter now that it's loaded Camera.main.GetComponent <sceneTransition>().slideToLevelSelect(); //Make slide transition to level select buttons }