/// <summary> /// 修改 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <Result <SecondLevel> > updateSecondLevelDir(SecondLevel model) { Result <SecondLevel> result = new Result <SecondLevel>(); try { using (DirDbContext context = new DirDbContext()) { var data = context.secondLevels.Where(x => x.activityFlag == 1 && x.id == model.id).FirstOrDefault(); if (data != null) { data.orderId = model.orderId; data.title = model.title; data.open = model.open; data.url = model.url; data.firstLevelId = model.firstLevelId; data.lastUpdatedBy = model.lastUpdatedBy; data.lastUpdatedDate = model.lastUpdatedDate; } var count = await context.SaveChangesAsync(); } } catch (Exception err) { result.addError(err.Message); } return(result); }
/// <summary> /// 增加 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <Result <SecondLevel> > addSecondLevelDir(SecondLevel model) { Result <SecondLevel> result = new Result <SecondLevel>(); using (DirDbContext context = new DirDbContext()) { try { var data = context.secondLevels.FirstOrDefault(x => x.title == model.title); if (data != null) { result.addError($"目录名{model.title}已经存在"); } else { result.data = context.secondLevels.Add(model); await context.SaveChangesAsync(); } } catch (Exception err) { result.addError(err.Message); } } return(result); }
public static async Task Main(string[] args) { using (var db = new DirDbContext("temp1.db", null)) { db.Database.Migrate(); var folder = new EncryptedFolder { Name = "First folder", Created = DateTime.Now, EncryptedName = "First folder encrypted", Files = new List <EncryptedFile> { new EncryptedFile { Name = "First file" }, new EncryptedFile { Name = "Second file" } } }; db.Folders.Add(folder); await db.SaveChangesAsync(); } Console.WriteLine("End"); Console.ReadKey(); }