public void AddAdapters(List <IMqttAdapter> adapters) { using (var ctx = new SqliteContext()) { foreach (var adapter in adapters) { var controller = _modelFactory.CreateController(); controller.Identifier = adapter.Identifier; controller.Type = adapter.Type; controller.InitializationArguments = _jsonSerializerService.Serialize(adapter.GetInitializationArguments()); foreach (var state in adapter.GetPossibleStates()) { var stateModel = new ControllerStateInformation(); stateModel.State = state.State; stateModel.PowerConsumption = state.PowerConsumption; stateModel.Controller = controller; ctx.Add(stateModel); } ctx.Add(controller); } ctx.SaveChanges(); } }
public async Task <Profile> GetOrCreateProfileAsync(SqliteContext lite, DiscordMember user, ulong guildId) { var recordedUser = await lite.Profile .Where(x => x.guildId == guildId) .FirstOrDefaultAsync(x => x.MemberId == user.Id); if (recordedUser != null) { return(recordedUser); } recordedUser = new Profile { MemberId = user.Id, guildId = guildId, Username = user.Username, UserIconURL = user.AvatarUrl, DripScore = 100, GambleTickets = 5, DripInventory = "", }; lite.Add(recordedUser); await lite.SaveChangesAsync(); return(recordedUser); }
public Response UploadFile(string projName, int?version, string platform, IFormFile file) { var ret = new Response(); if (string.IsNullOrEmpty(projName) || version == null || file == null) { ret.Fail(0, "参数出错!"); return(ret); } //增加一条记录 using (var db = new SqliteContext()) { var ab = db.AssetBundleDatas.FirstOrDefault((ab) => ab.ProjName == projName && // ab.Platform == platform && // ab.Version == version); // if (ab == null) { ab = new AssetBundleData(); ab.ProjName = projName; ab.Platform = platform; ab.Version = (int)version; ab.Timer = DateTime.Now.ToShortTimeString(); db.Add(ab); db.SaveChanges(); } } try { //保存文件 abService.SaveFile(projName, platform, version.ToString(), file); ret.Success(msg: "成功!"); } catch (Exception e) { ret.Fail(msg: e.Message); } return(ret); }
public void Add(NavLink page) { _context.Add(page); _context.SaveChanges(); }
public void Add(RelatedPages page) { _context.Add(page); _context.SaveChanges(); }