public void SubscribeOnSections(int profileId, IList <int> sectionIds, int id = 0) { if (profileId == 0) { throw new ArgumentException(nameof(profileId)); } ProfileSettingsEntity settings = null; if (id > 0) { settings = DbSettings.Find(id); } else { settings = new ProfileSettingsEntity(); settings.ProfileId = profileId; } foreach (var item in sectionIds ?? new List <int>()) { var section = DbContext.Sections.Find(item); if (section != null) { settings.SubscribeOnSections?.Add(section); } } DbContext.SaveChanges(); }
public void SubscribeOnAuthors(int profileId, IList <int> authorIds, int id = 0) { if (profileId == 0) { throw new ArgumentException(nameof(profileId)); } ProfileSettingsEntity settings = null; if (id > 0) { settings = DbSettings.Find(id); } else { settings = new ProfileSettingsEntity(); settings.ProfileId = profileId; } foreach (var item in authorIds ?? new List <int>()) { var profile = DbContext.UserProfile.Find(item); if (profile != null) { settings.SubscribeOnAuthors?.Add(profile); } } DbContext.SaveChanges(); }
public void UnSubscribeOnAuthors(int id, int profileId, IList <int> authorIds) { if (id == 0) { throw new ArgumentException(nameof(id)); } if (profileId == 0) { throw new ArgumentException(nameof(profileId)); } ProfileSettingsEntity settings = null; settings = DbSettings.Find(id); foreach (var item in authorIds ?? new List <int>()) { var userPofile = DbContext.UserProfile.Find(item); if (userPofile != null) { settings.SubscribeOnAuthors?.Remove(userPofile); } } DbContext.SaveChanges(); }
public ProfileSettingsEntity Create(int profileId) { ProfileSettingsEntity settings = new ProfileSettingsEntity(); using (var transaction = DbContext.Database.BeginTransaction()) { try { settings.ProfileId = profileId; settings = DbContext.ProfileSettings.Add(settings); var profile = DbContext.UserProfile.FirstOrDefault(u => u.Id == profileId); profile.ProfileSettingsId = settings.Id; DbContext.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); } } return(settings); }