public ActionResult CreateChapter(ChapterVM chapterVM) { if (!string.IsNullOrEmpty(chapterVM.Name)) { _chapterService.AddChapter(chapterVM); } return(RedirectToAction("Chapter", new { id = chapterVM.SubjectId })); }
public IHttpActionResult GetChapter(int id) { Chapter chapter = db.Chapters.Find(id); if (chapter == null) { return(NotFound()); } ChapterVM chapterVM = new ChapterVM(chapter); return(Ok(chapterVM)); }
// GET: api/Chapters public IQueryable <ChapterVM> GetChapters() { List <ChapterVM> chapterVMs = new List <ChapterVM>(); ChapterVM chapterVM; foreach (var chapter in db.Chapters) { chapterVM = new ChapterVM(chapter); chapterVMs.Add(chapterVM); } return(chapterVMs.AsQueryable()); }
public IQueryable <ChapterVM> GetChaptersByStory(string slug) { IQueryable <Chapter> chapters = from c in db.Chapters where c.Story.Slug.Equals(slug) select c; List <ChapterVM> chapterVMs = new List <ChapterVM>(); ChapterVM chapterVM; foreach (var chapter in chapters) { chapterVM = new ChapterVM(chapter); chapterVMs.Add(chapterVM); } return(chapterVMs.AsQueryable()); }
public IQueryable <ChapterVM> GetChapterByNumber(string story, int number) { IQueryable <Chapter> chapters = db.Chapters.Where(c => c.Story.Slug.Equals(story) && c.ChapterNumber == number); List <ChapterVM> chapterVMs = new List <ChapterVM>(); ChapterVM chapterVM; foreach (var chapter in chapters) { chapterVM = new ChapterVM(chapter); chapterVMs.Add(chapterVM); } return(chapterVMs.AsQueryable()); }
public MainPageVM(IDataAccess dataAccess, ChapterVM chapterVm) { OpenFileCommand = new RelayCommand(ExecuteOpenFile); OpenFolderCommand = new RelayCommand(ExecuteOpenFolder); OpenLinkCommand = new RelayCommand(ExecuteOpenLinkCommand); OpenRecentCommand = new RelayCommand(ExecuteOpenRecentCommand); ClearHistoryCommand = new RelayCommand(ExecuteClearHistory); View = new ReadingView(); _chapterVm = chapterVm; _dataAccess = dataAccess; RecentList = new ObservableCollection <LinkInfo>(_dataAccess.GetAll()); }
/// <summary> /// 列表 /// </summary> /// <param name="_ChapterVM"></param> /// <param name="pn"></param> /// <returns></returns> public ActionResult List(ChapterVM _ChapterVM, int pn = 1) { int totalCount, pageIndex = pn, pageSize = PagingConfig.PAGE_SIZE; var list = _ChapterService.GetManagerList(_ChapterVM.QueryName, pageIndex, pageSize, out totalCount); var paging = new Paging <Chapter>() { Items = list, Size = PagingConfig.PAGE_SIZE, Total = totalCount, Index = pn, }; _ChapterVM.Paging = paging; return(View(_ChapterVM)); }
public IHttpActionResult DeleteChapter(int id) { Chapter chapter = db.Chapters.Find(id); if (chapter == null) { return(NotFound()); } //db.Chapters.Remove(chapter); chapter.ChapterStatus = -1; db.Entry(chapter).State = EntityState.Modified; db.SaveChanges(); ChapterVM chapterVM = new ChapterVM(chapter); return(Ok(chapterVM)); }
public IHttpActionResult PostChapter(ChapterVM chapterVM) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Chapter chapter = new Chapter(); ConvertChapterVM(ref chapter, chapterVM); db.Chapters.Add(chapter); db.SaveChanges(); chapterVM.Update(chapter); return(CreatedAtRoute("DefaultApi", new { id = chapterVM.ChapterId }, chapterVM)); }
public IActionResult Create(int ID, int CourseId) { var vm = new ChapterVM(); if (ID != 0) { var model = _chapterService.GetById(ID); if (model == null) { return(NotFound()); } vm = _mapper.Map <ChapterVM>(model); } else { var numChapter = _chapterService.CountCondition(m => m.CourseId == CourseId); vm.OrderChapter = ++numChapter; vm.CourseId = CourseId; } return(View(vm)); }
private void ConvertChapterVM(ref Chapter chapter, ChapterVM chapterVM) { chapterVM.Slug = SlugUtil.GenerateSlug(chapterVM.ChapterTitle); chapter.StoryId = chapterVM.StoryId; chapter.ChapterNumber = chapterVM.ChapterNumber; chapter.ChapterTitle = chapterVM.ChapterTitle; chapter.ChapterContent = chapterVM.ChapterContent; chapter.ChapterStatus = chapterVM.ChapterStatus; chapter.UploadedDate = chapterVM.UploadedDate; chapter.LastEditedDate = chapterVM.LastEditedDate; chapter.UserId = chapterVM.UserId; chapter.Slug = chapterVM.Slug; var slugCount = db.Chapters.Count(c => c.Slug.StartsWith(chapterVM.Slug)); if (slugCount > 0) { chapter.Slug += slugCount; } }
public IHttpActionResult PutChapter(int id, ChapterVM chapterVM) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != chapterVM.ChapterId) { return(BadRequest()); } Chapter chapter = db.Chapters.Find(id); ConvertChapterVM(ref chapter, chapterVM); db.Entry(chapter).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ChapterExists(id)) { return(NotFound()); } else { throw; } } chapterVM.Update(chapter); return(StatusCode(HttpStatusCode.OK)); }
public ActionResult Article(string id, string chapterId) { var article = DataRepo.AllArticles.FirstOrDefault(x => x.Uid == id); if (article == null) { throw new HttpException(404, "Article not found"); } if (string.IsNullOrWhiteSpace(chapterId)) { chapterId = article.Chapters.FirstOrDefault(x => string.IsNullOrWhiteSpace(x.Separator))?.Uid; } var chapter = article.Chapters.FirstOrDefault(x => x.Uid == chapterId); if (chapter == null) { throw new HttpException(404, "Chapter not found"); } var chaptersWithoutSeparators = article.Chapters.Where(x => string.IsNullOrWhiteSpace(x.Separator)).ToList(); var index = chaptersWithoutSeparators.ToList().IndexOf(chapter); var vm = new ChapterVM() { Uid = chapter.Uid, ArticleUid = article.Uid, Display = chapter.Display, ContentHtml = Db.Chapter.GetHtmlContent(HttpContext, chapter), PreviousUid = index > 0 ? chaptersWithoutSeparators[index - 1].Uid : string.Empty, NextUid = index < chaptersWithoutSeparators.Count - 1 ? chaptersWithoutSeparators[index + 1].Uid : string.Empty }; return(View(vm)); }
public IHttpActionResult GetProblemAndRecord([FromUri] SelctProblemVM SelctProblemVM) { if (SelctProblemVM != null) { int count = 0; var problemCollectList = problemCollectService.GetProblemCollectList(SelctProblemVM.UserInfoId, 1, 10000, out count); //ProblemVM var problemList = problemService.GetProblemList(SelctProblemVM.belongId, SelctProblemVM.ChapterId, SelctProblemVM.SubjectInfoId); List <ProblemVM> problemVMlist = new List <ProblemVM>(); foreach (var result in problemList) { int IsCollect = 0; if (problemCollectList != null && problemCollectList.Count > 0) { var problemCollect = (from a in problemCollectList where a.ProblemId == result.ProblemId select a).FirstOrDefault(); if (problemCollect != null) { IsCollect = 1; } } ProblemVM problem = new ProblemVM(); problem.ProblemId = result.ProblemId; problem.Title = result.Title; problem.ProblemCategoryId = result.ProblemCategoryId; problem.ProblemCategory = result.ProblemCategory; problem.Analysis = result.Analysis; ChapterVM chapterVM = new ChapterVM(); if (result.Chapter != null) { chapterVM.ChapterId = result.Chapter.ChapterId; chapterVM.Title = result.Chapter.Title; chapterVM.Sort = result.Chapter.Sort; } problem.Chapter = chapterVM; problem.IsCollect = IsCollect; List <AnswerVM> childList = new List <AnswerVM>(); if (result.AnswerList != null) { foreach (var item in result.AnswerList) { childList.Add(new AnswerVM { AnswerId = item.AnswerId, ProblemId = item.ProblemId, IsCorrect = item.IsCorrect, Title = item.Title }); } } problem.AnswerList = childList; problemVMlist.Add(problem); } //获取用户此分类的答题记录 var answerRecordModel = userInfoAnswerRecordService.GetUserLastRecord(SelctProblemVM.ChapterId, SelctProblemVM.UserInfoId); LastAnswerRecordVM lar = new LastAnswerRecordVM(); //获取答题记录详细 if (answerRecordModel != null) { var uifa = new UserInfoAnswerVM(); uifa.ChapterId = answerRecordModel.ChapterId; uifa.UserInfoAnswerRecordId = answerRecordModel.UserInfoAnswerRecordId; uifa.UserInfoId = answerRecordModel.UserInfoId; uifa.CTime = answerRecordModel.CTime; uifa.UTime = answerRecordModel.UTime; //通过编号获取详细 var problemRecordList = problemRecordService.GetForUserInfoRecordId(answerRecordModel.UserInfoAnswerRecordId); var prList = new List <ProblemRecordVM>(); foreach (ProblemRecord item in problemRecordList) { prList.Add(new ProblemRecordVM() { ProblemId = item.ProblemId, ProblemRecordId = item.ProblemRecordId, CorrectAnswer = item.CorrectAnswer, ErrorAnswer = item.ErrorAnswer, YesOrNo = item.YesOrNo, }); } lar.problemsRecord = prList; lar.userInfoAnswerRecord = uifa; } ProblemAndRecord par = new ProblemAndRecord(); par.problemsvm = problemVMlist; par.lastAnswervm = lar; return(Json(new { Success = true, Msg = "OK", Data = par })); } else { return(Json(new { Success = false, Msg = "参数不对", Data = "" })); } }
public IHttpActionResult GetProblemList([FromUri] SelctProblemVM SelctProblemVM) { if (SelctProblemVM != null) { int count = 0; var problemCollectList = problemCollectService.GetProblemCollectList(SelctProblemVM.UserInfoId, 1, 10000, out count); //ProblemVM var problemList = problemService.GetProblemList(SelctProblemVM.belongId, SelctProblemVM.ChapterId, SelctProblemVM.SubjectInfoId); List <ProblemVM> problemVMlist = new List <ProblemVM>(); foreach (var result in problemList) { int IsCollect = 0; if (problemCollectList != null && problemCollectList.Count > 0) { var problemCollect = (from a in problemCollectList where a.ProblemId == result.ProblemId select a).FirstOrDefault(); if (problemCollect != null) { IsCollect = 1; } } ProblemVM problem = new ProblemVM(); problem.ProblemId = result.ProblemId; problem.Title = result.Title; problem.ProblemCategoryId = result.ProblemCategoryId; problem.ProblemCategory = result.ProblemCategory; problem.Analysis = result.Analysis; ChapterVM chapterVM = new ChapterVM(); if (result.Chapter != null) { chapterVM.ChapterId = result.Chapter.ChapterId; chapterVM.Title = result.Chapter.Title; chapterVM.Sort = result.Chapter.Sort; } problem.Chapter = chapterVM; problem.IsCollect = IsCollect; List <AnswerVM> childList = new List <AnswerVM>(); if (result.AnswerList != null) { foreach (var item in result.AnswerList) { childList.Add(new AnswerVM { AnswerId = item.AnswerId, ProblemId = item.ProblemId, IsCorrect = item.IsCorrect, Title = item.Title }); } } problem.AnswerList = childList; problemVMlist.Add(problem); } return(Json(new { Success = true, Msg = "OK", Data = problemVMlist })); } else { return(Json(new { Success = false, Msg = "参数不对", Data = "" })); } }
public ActionResult EditChapter(ChapterVM model, HttpPostedFileBase file) { return(RedirectToAction("Edit")); }
public ActionResult AddChapter(ChapterVM model, HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View(model)); } using (Db db = new Db()) { if (db.Chapters .Any(x => x.Name == model.Name)) { ModelState .AddModelError("", "The chapter already exists!"); return(View(model)); } } int id = 0; using (Db db = new Db()) { ChapterDTO chapter = new ChapterDTO(); chapter.Name = model.Name; chapter.Description = model.Description; db.Chapters.Add(chapter); db.SaveChanges(); id = chapter.Id; } #region Create Chapter DirectoryInfo originalDirectory = new DirectoryInfo(string.Format("{0}Courses\\", Server.MapPath("~/"))); CourseDTO course; using (Db db = new Db()) { ChaptersForCoursesDTO dto = new ChaptersForCoursesDTO() { CourseId = ShopController.getCourseId(id), ChapterId = id }; course = db.Courses .Find(ShopController.getCourseId(id)); db.ChaptersForCourses.Add(dto); db.SaveChanges(); } string pathString = Path .Combine(originalDirectory.ToString() + "\\" + course.Name); string pathString2 = Path .Combine(pathString + "\\" + "Chapters"); int chaptersCount = 0; using (Db db = new Db()) { chaptersCount = db .ChaptersForCourses .Where(x => x.CourseId == ShopController.getCourseId(id)) .Count(); } string pathString3 = Path .Combine(pathString2 + "\\" + string.Format( "Chapter " + chaptersCount.ToString() + " - " + model.Name)); if (Directory.Exists(pathString3)) { Directory.CreateDirectory(pathString3); } #endregion TempData["SM"] = "You have added a new chapter!"; return(RedirectToAction("AddChapter")); }
/// <summary> /// 编辑 /// </summary> /// <param name="_ChapterVM"></param> /// <returns></returns> public ActionResult Edit(ChapterVM _ChapterVM) { _ChapterVM.Chapter = _ChapterService.GetById(_ChapterVM.Id) ?? new Chapter(); return(View(_ChapterVM)); }