public void ToDbGroup(Sec_Groups _dbGroup) { _dbGroup.GroupID = this.GroupID; _dbGroup.Name_Ara = this.Name_Ara; _dbGroup.Name_Eng = this.Name_Eng; _dbGroup.IsDisable = this.IsDisable; }
public void SaveGroupUsers(Sec_Groups _dbGroup, NewAppsCnn newAppsCnn) { // Add New User To Group foreach (var user in Users) { var dbUsers = from u in _dbGroup.Sec_Users where u.UserID == user.UserID select u; if (dbUsers.Count() == 0) { var dbUser = newAppsCnn.Sec_Users.First(u => u.UserID == user.UserID); _dbGroup.Sec_Users.Add(dbUser); } } // Delete User Groups foreach (var dbUser in _dbGroup.Sec_Users.ToList()) { var user = Users.Find(u => u.UserID == dbUser.UserID); if (user == null) { _dbGroup.Sec_Users.Remove(dbUser); } } }
public void LoadGroupUsers(Sec_Groups _dbGroup) { Users.Clear(); foreach (var dbUser in _dbGroup.Sec_Users) { User user = new User(); user.FromDbUser(dbUser); Users.Add(user); } }
public DataSaveResult Save() { Sec_Groups dbGroup; try { NewAppsCnn newAppsCnn = new NewAppsCnn(AppSettings.CrAppSettings.NewAppsConnectionString); dbGroup = (from g in newAppsCnn.Sec_Groups where g.GroupID == this.GroupID select g).FirstOrDefault(); if (dbGroup == null) { dbGroup = new Sec_Groups(); this.ToDbGroup(dbGroup); newAppsCnn.Sec_Groups.Add(dbGroup); SaveGroupUsers(dbGroup, newAppsCnn); newAppsCnn.SaveChanges(); } else { this.ToDbGroup(dbGroup); SaveGroupUsers(dbGroup, newAppsCnn); newAppsCnn.SaveChanges(); Audit.AddDataAudit(Audit.AuditActionTypes.AddNew, "Sec_Groups", this); } this.FromDbGroup(dbGroup); return new DataSaveResult() { SaveStatus = true, ErrorMessage = "", Data = this }; } catch (Exception ex) { return new DataSaveResult() { SaveStatus = false, ErrorMessage = ex.Message }; } }
public void FromDbGroup(Sec_Groups _dbGroup) { this.GroupID = _dbGroup.GroupID; this.Name_Ara = _dbGroup.Name_Ara; this.Name_Eng = _dbGroup.Name_Eng; this.IsDisable = _dbGroup.IsDisable; this.IsNew = false; }