public JsonResult UpdateChapter(UpdateChapterViewModel model) { if (!ModelState.IsValid) { return(Json(false)); } BookChapter chapter; if (model.Id == 0) { chapter = new BookChapter { Name = model.Name, IsLock = false, BookId = model.BookId }; if (model.ParentId != 0) { chapter.ParentId = model.ParentId; } _bookChapterService.InsertBookChapter(chapter); } else { chapter = _bookChapterService.GetBookChapterById(model.Id); chapter.Name = model.Name; chapter.BookId = model.BookId; _bookChapterService.UpdateBookChapter(chapter); } return(Json(true)); }
public JsonResult ChapterUpload(int chapterId) { var file = Request.Files[0]; var chapter = _bookChapterService.GetBookChapterById(chapterId); if (null == chapter || file == null || file.ContentLength == 0) { return(Json(false)); } var extens = Path.GetExtension(file.FileName); var filename = Guid.NewGuid() + extens; var relatepath = $"/Content/Upload/World/{filename}"; var phyPath = _webHelper.MapPath("~" + relatepath); file.SaveAs(phyPath); var entity = new AF.Domain.Domain.Media.File() { OriginallName = file.FileName, CreateTime = DateTime.Now, Name = filename, RelatePath = relatepath }; chapter.UploadFile = entity; _bookChapterService.UpdateBookChapter(chapter); return(Json(true)); }
public ActionResult Chapter(ChapterParamModel param) { if (!ModelState.IsValid) { param.BookChapterList = _bookChapterService.GetBookChapters(param.BookId); return(View(param)); } var chapterIdArr = param.BookChapterIds.Split(','); //获取题目数量 var bookChapterList = chapterIdArr.Select(t => _bookChapterService.GetBookChapterById(int.Parse(t))).ToList(); //生成任务名 string taskName = DateTime.Now.ToString("yyyyMMdd-1"); var works = _bookWorkTaskService.GetBookWorkList(new BookWorkRequest() { Begin = DateTime.Now, End = DateTime.Now, PageSize = 1 }); var work = works.FirstOrDefault(); if (!string.IsNullOrEmpty(work?.Name)) { int num = Convert.ToInt32(work.Name.ToCharArray().Last().ToString()) + 1; taskName = DateTime.Now.ToString("yyyyMMdd-" + num); } var model = new BookWorkTask() { Name = taskName, BookId = param.BookId, CheckCustomerId = param.CheckCustomerId, //标定 录入人 MarkCustomerId = param.EntryCustomerId, EntryCustomerId = param.EntryCustomerId, Status = TaskStatus.Entry, CreateTime = DateTime.Now }; _bookWorkTaskService.InsertBookWorkTask(model); var taskItemList = chapterIdArr.Select(t => new BookWorkTaskItem() { TaskId = model.Id, ChapterId = int.Parse(t), Status = 0 }).ToList(); _bookWorkTaskItemService.InsertBookWorkTaskItems(taskItemList); //修改章节表的TaskItemId taskItemList.ForEach(t => { var bookChapter = bookChapterList.First(h => h.Id == t.ChapterId); bookChapter.TaskItemId = t.Id; _bookChapterService.UpdateBookChapter(bookChapter); }); return(RedirectToAction("Index")); }