Esempio n. 1
0
 void LoadData()
 {
     try
     {
         jailData = Interface.GetMod().DataFileSystem.ReadObject <JailDataStorage>("jail_data");
         foreach (var entry in jailData.prisons)
         {
             prisonIDs.Add(entry.Value.zoneID);
         }
     }
     catch
     {
         jailData = new JailDataStorage();
     }
 }
        public async Task <Result <Unit> > Store(ulong guildId, RoleUpdateModel updateModel)
        {
            var storage = new JailDataStorage(guildId.MapUlongToLong(), updateModel.User.MapUlongToLong(),
                                              updateModel.RolesChanged.ToStorage());
            var entity =
                await(_context.JailDatas as IQueryable <JailDataStorage>)
                .FirstOrDefaultAsync(x =>
                                     x.GuildId == storage.GuildId && x.UserId == storage.UserId);

            if (entity is null)
            {
                _context.JailDatas.Add(storage);
            }
            else
            {
                _context.Entry(entity).CurrentValues.SetValues(storage);
            }

            await _context.SaveChangesAsync();

            return(new Unit());
        }