Пример #1
0
        public async Task UpdateNmStoreRecordAsync(NmStoreModel newModel)
        {
            using (var dbContext = new GmailBotDbContext())
            {
                var existModel = await dbContext.NmStore
                                 .Where(nmStore => nmStore.Id == newModel.Id)
                                 .Include(nmStore => nmStore.To)
                                 .Include(nmStore => nmStore.Cc)
                                 .Include(nmStore => nmStore.Bcc)
                                 .Include(nmStore => nmStore.File)
                                 .SingleOrDefaultAsync();

                if (existModel == null)
                {
                    return;
                }
                // Update
                dbContext.Entry(existModel).CurrentValues.SetValues(newModel);
                // Delete
                dbContext.To.RemoveRange(existModel.To.Except(newModel.To, new IdEqualityComparer <ToModel>()));
                dbContext.Cc.RemoveRange(existModel.Cc.Except(newModel.Cc, new IdEqualityComparer <CcModel>()));
                dbContext.Bcc.RemoveRange(existModel.Bcc.Except(newModel.Bcc, new IdEqualityComparer <BccModel>()));
                dbContext.File.RemoveRange(existModel.File.Except(newModel.File, new IdEqualityComparer <FileModel>()));

                UpdateAdress(dbContext, newModel.To, existModel.To);
                UpdateAdress(dbContext, newModel.Cc, existModel.Cc);
                UpdateAdress(dbContext, newModel.Bcc, existModel.Bcc);
                UpdateFile(dbContext, newModel.File, existModel.File);
                await dbContext.SaveChangesAsync();
            }
        }
Пример #2
0
        public async Task UpdateUserSettingsRecordAsync(UserSettingsModel newModel)
        {
            using (var db = new GmailBotDbContext())
            {
                var existModel = await db.UserSettings
                                 .Where(userSettings => userSettings.Id == newModel.Id)
                                 .Include(userSettings => userSettings.IgnoreList)
                                 .Include(userSettings => userSettings.Blacklist)
                                 .Include(userSettings => userSettings.Whitelist)
                                 .SingleOrDefaultAsync();

                if (existModel == null)
                {
                    return;
                }
                // Update
                db.Entry(existModel).CurrentValues.SetValues(newModel);
                //Delete
                db.Ignore.RemoveRange(existModel.IgnoreList.Except(newModel.IgnoreList, new IdEqualityComparer <IgnoreModel>()));
                db.Blacklist.RemoveRange(existModel.Blacklist.Except(newModel.Blacklist, new IdEqualityComparer <BlacklistModel>()));
                db.Whitelist.RemoveRange(existModel.Whitelist.Except(newModel.Whitelist, new IdEqualityComparer <WhitelistModel>()));

                UpdateIgnoreList(db, newModel.IgnoreList, existModel.IgnoreList);
                UpdateLabelsList(db, newModel.Blacklist, existModel.Blacklist);
                UpdateLabelsList(db, newModel.Whitelist, existModel.Whitelist);
                await db.SaveChangesAsync();
            }
        }
 public async Task UpdateTempDataRecordAsync(TempDataModel tempDataModel)
 {
     using (var db = new GmailBotDbContext())
     {
         db.TempData.Attach(tempDataModel);
         db.Entry(tempDataModel).State = EntityState.Modified;
         await db.SaveChangesAsync();
     }
 }
Пример #4
0
 public async Task UpdateUserRecordAsync(UserModel userModel)
 {
     using (var db = new GmailBotDbContext())
     {
         db.Users.Attach(userModel);
         db.Entry(userModel).State = EntityState.Modified;
         await db.SaveChangesAsync();
     }
 }
        public async Task <TempDataModel> AddNewTempDataAsync(TempDataModel tempData)
        {
            tempData.NullInspect(nameof(tempData));

            using (var db = new GmailBotDbContext())
            {
                var newModel = db.TempData.Add(tempData);
                await db.SaveChangesAsync();

                return(newModel);
            }
        }
Пример #6
0
        public async Task <NmStoreModel> AddNewNmStoreAsync(int userId)
        {
            using (var db = new GmailBotDbContext())
            {
                var newModel = db.NmStore.Add(new NmStoreModel {
                    UserId = userId
                });
                await db.SaveChangesAsync();

                return(newModel);
            }
        }
Пример #7
0
        public async Task <UserSettingsModel> AddNewUserSettingsAsync(int userId)
        {
            using (var db = new GmailBotDbContext())
            {
                var userSettings = db.UserSettings.Add(new UserSettingsModel {
                    UserId = userId
                });
                await db.SaveChangesAsync();

                return(userSettings);
            }
        }
Пример #8
0
        public async Task <UserModel> AddNewUserAsync(User user)
        {
            user.NullInspect(nameof(user));

            using (var db = new GmailBotDbContext())
            {
                var newModel = db.Users.Add(new UserModel(user));
                await db.SaveChangesAsync();

                return(newModel);
            }
        }
Пример #9
0
        public async Task <PendingUserModel> UpdateRecordJoinTimeAsync(int id, DateTime time)
        {
            using (var db = new GmailBotDbContext())
            {
                var query = await db.PendingUser.FindAsync(id);

                if (query != null)
                {
                    query.JoinTimeUtc = time;
                    await db.SaveChangesAsync();
                }
                return(query);
            }
        }
Пример #10
0
        public async Task <PendingUserModel> QueueAsync(int userId)
        {
            using (var db = new GmailBotDbContext())
            {
                var newModel = db.PendingUser.Add(new PendingUserModel
                {
                    UserId      = userId,
                    JoinTimeUtc = DateTime.Now
                });
                await db.SaveChangesAsync();

                return(newModel);
            }
        }
        public async Task RemoveTempDataAsync(TempDataModel model)
        {
            model.NullInspect(nameof(model));

            using (var db = new GmailBotDbContext())
            {
                var entry = db.Entry(model);
                if (entry.State == EntityState.Detached)
                {
                    db.TempData.Attach(model);
                }
                db.TempData.Remove(model);
                await db.SaveChangesAsync();
            }
        }
Пример #12
0
        public async Task RemoveFromQueueAsync(PendingUserModel model)
        {
            model.NullInspect(nameof(model));

            using (var db = new GmailBotDbContext())
            {
                var entry = db.Entry(model);
                if (entry.State == EntityState.Detached)
                {
                    db.PendingUser.Attach(model);
                }
                db.PendingUser.Remove(model);
                await db.SaveChangesAsync();
            }
        }
Пример #13
0
        public async Task RemoveUserSettingsRecordAsync(UserSettingsModel model)
        {
            model.NullInspect(nameof(model));

            using (var db = new GmailBotDbContext())
            {
                var existModel = await db.UserSettings
                                 .Where(userSettings => userSettings.Id == model.Id)
                                 .Include(userSettings => userSettings.IgnoreList)
                                 .Include(userSettings => userSettings.Blacklist)
                                 .Include(userSettings => userSettings.Whitelist)
                                 .SingleOrDefaultAsync();

                if (existModel == null)
                {
                    return;
                }

                db.UserSettings.Remove(existModel);
                await db.SaveChangesAsync();
            }
        }
Пример #14
0
        public async Task RemoveNmStoreAsync(NmStoreModel model)
        {
            model.NullInspect(nameof(model));

            using (var dbContext = new GmailBotDbContext())
            {
                var existModel = await dbContext.NmStore
                                 .Where(nmStore => nmStore.Id == model.Id)
                                 .Include(nmStore => nmStore.To)
                                 .Include(nmStore => nmStore.Cc)
                                 .Include(nmStore => nmStore.Bcc)
                                 .Include(nmStore => nmStore.File)
                                 .SingleOrDefaultAsync();

                if (existModel == null)
                {
                    return;
                }

                dbContext.NmStore.Remove(existModel);
                await dbContext.SaveChangesAsync();
            }
        }