public async Task CreateCategory(CommonDbContext dbCtx, string Name) { var cateModel = await dbCtx.Categories.FirstOrDefaultAsync(x => x.Name == Name); if (cateModel == null) { await dbCtx.Categories.AddAsync(new Content.Model.Categories { Id = Guid.NewGuid(), Name = Name, CreateTime = DateTime.Now, Tags = new List <Tags> { new Tags { Name = "日漫" }, //new Tags { Name = "偶像" }, //new Tags{ Name ="兄妹"}, //new Tags{ Name ="日常"}, //new Tags{ Name ="恋爱"} } }); await dbCtx.SaveChangesAsync(); } }
private static async Task prepareImage(CommonDbContext dbContext, ContentEntry chapterContent, Stream imgStream, string imgName) { var mediaImg = chapterContent.MediaResource?.FirstOrDefault(x => x.Name == imgName); if (mediaImg == null) { if (chapterContent.MediaResource == null) { chapterContent.MediaResource = new List <FileEntry>(); } //图片判重 if (chapterContent.MediaResource.Any(x => x.Name == imgName)) { return; } imgStream.Position = 0; QiniuTool.UploadImage(imgStream, imgName).Wait(); chapterContent.MediaResource.Add(new FileEntry { ActualPath = "https://mioto.milbit.com/" + imgName, Name = imgName, CreateTime = DateTime.Now, Id = Guid.NewGuid() }); await dbContext.SaveChangesAsync(); } }
public async Task <bool> AddQuestionToMyLib(string ques_id) { var qa = await _context.User.FirstAsync(x => x.UserName == User.Identity.Name); ques_id = ques_id.Substring(1); if (string.IsNullOrEmpty(qa.QuestionSet)) { qa.QuestionSet = ""; } if (qa.QuestionSet.Contains(ques_id)) { return(false); } else { qa.QuestionSet = string.IsNullOrEmpty(qa.QuestionSet) ? ques_id + ";" : qa.QuestionSet + ques_id + ";"; _context.Update(qa); await _context.SaveChangesAsync(); return(true); } }
private static async Task InsertPosInfoToDB(CommonDbContext dbContext, JObject posInfoObj) { var posInfoList = posInfoObj["pois"]; foreach (var posItem in posInfoList) { var idcode = posItem["id"].ToString(); var hasAny = await dbContext.StoreMapInfos.AnyAsync(x => x.IdCode == idcode); if (!hasAny) { var storeInfoModel = MappingStoreInfoModel(posItem, dbContext); await dbContext.AddAsync(storeInfoModel); } } await dbContext.SaveChangesAsync(); }
public async Task CreateChapter(CommonDbContext dbCtx, string cateName, string Name, int order) { var category = await dbCtx.Categories.FirstOrDefaultAsync(x => x.Name == cateName); var hasContent = await dbCtx.ContentEntry.AnyAsync(x => x.Category.Name == cateName && x.Title == Name); if (!hasContent) { await dbCtx.ContentEntry.AddAsync(new ContentEntry { Id = Guid.NewGuid(), Category = category, Title = Name, Order = order, CreateTime = DateTime.Now }); await dbCtx.SaveChangesAsync(); } }
private static async Task <ContentEntry> prepareChapter(CommonDbContext dbContext, Categories category, string chapterName, int chapterIndex) { var chapter = category.ContentList.FirstOrDefault(x => x.Title == chapterName); if (chapter == null) { chapter = new ContentEntry { Id = Guid.NewGuid(), CreateTime = DateTime.Now, Category = category, Title = chapterName, Order = chapterIndex }; dbContext.ContentEntry.Add(chapter); await dbContext.SaveChangesAsync(); dbContext.Entry(chapter); } return(chapter); }
public async Task SvaeChapterDetail(CommonDbContext dbCtx, string cateName, string contentName, string fileName, int order) { try { var content = await dbCtx.ContentEntry.Include(x => x.MediaResource).FirstOrDefaultAsync(x => x.Category.Name == cateName && x.Title == contentName); var category = await dbCtx.Categories.FirstOrDefaultAsync(x => x.Name == cateName); if (content.MediaResource == null) { content.MediaResource = new List <FileEntry> { }; } var name = $"{cateName}/{contentName}/{order}img.jpg"; if (!content.MediaResource.Any(x => x.Name == name)) { await QiniuTool.UploadImage(fileName, name); content.MediaResource.Add(new FileEntry { Name = name, ActualPath = "https://mioto.milbit.com/" + name, CreateTime = DateTime.Now, Order = order, Tag = cateName }); } await dbCtx.SaveChangesAsync(); } catch (Exception exc) { Console.WriteLine(exc.Message); } }
public async Task Commit() { await context.SaveChangesAsync(); }
public async Task <int> Commit() { return(await _context.SaveChangesAsync()); }
public async Task <IActionResult> QCreate(ClassForQuestionCreatingModel ob) { if (ModelState.IsValid) { var tags = ob.tags.Where(x => x.IsSelected).Select(x => x.Id); /* Пока разрешим создание без тегов * if (tags.Count() == 0) * ModelState.AddModelError(string.Empty, "вы должны указать как минимум один тег"); */ Question obj = new Question(); var StringTags = string.Join(";", tags); var qa = await _context.User.FirstAsync(x => x.UserName == User.Identity.Name); obj.CreationDate = DateTime.Now; obj.UpdateDate = DateTime.Now; obj.Author = User.Identity.Name; obj.TagIds = StringTags; obj.IsPrivate = true; obj.Definition = ob.Definition; obj.Proof = ob.Proof; obj.Title = ob.Title; _context.Add(obj); await _context.SaveChangesAsync(); qa.QuestionSet = string.IsNullOrEmpty(qa.QuestionSet) ? obj.Id + ";" : qa.QuestionSet + obj.Id + ";"; _context.Update(qa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ob)); }