public void SaveSystemUserRoleActions(List <SystemUser> systemUsers) { foreach (SystemUser systemUser in systemUsers) { List <UserRoleAction> itemsToDelete = GetRoleActionsToDelete(systemUser); //systemUser.OriginalRoleActions.Except(systemUser.RoleActions).ToList(); List <UserRoleAction> itemsToAdd = GetRoleActionsToAdd(systemUser); // systemUser.RoleActions.Except(systemUser.OriginalRoleActions).ToList(); //string sql = "DELETE from UserRoleAction WHERE UserId=" + systemUser.UserId; //DataTable dt = dbc.GetDataTable("SELECT * FROM UserRoleAction WHERE UserId="+systemUser.UserId); UpdatesystemUser(systemUser); //dbc.ExecuteCommand(sql); foreach (UserRoleAction roleAction in itemsToAdd) { StringBuilder sb = new StringBuilder(); sb.Append("INSERT INTO UserRoleAction (UserId,RoleId,RoleActionId) VALUES ("); sb.Append(systemUser.UserId); sb.Append("," + roleAction.RoleId); sb.Append("," + roleAction.RoleActionId); sb.Append(")"); string sql = sb.ToString(); dbc.ExecuteCommand(sql); } foreach (UserRoleAction roleAction in itemsToDelete) { StringBuilder sb = new StringBuilder(); sb.Append("DELETE FROM UserRoleAction Where UserRoleActionId=" + roleAction.UserRoleActionId); string sql = sb.ToString(); dbc.ExecuteCommand(sql); } } dbc.CommitTransactions(); dbc.CloseConnection(); }
public override void Remove(Person person, int StudentId) { StringBuilder sb = new StringBuilder(); sb.Append("DELETE FROM StudentNextOfKin WHERE NextOfKinId=" + person.PersonId + " AND StudentId=" + StudentId); string sql = sb.ToString(); DBCommand db = new DBCommand(DBCommand.TransactionType.WithTransaction); int returnDoctorId = db.ExecuteCommand(sql); db.CommitTransactions(); db.CloseConnection(); }
public override void Save() { DBCommand dbc = new DBCommand(DBCommand.TransactionType.WithTransaction); try { DataBase db = new StudentData(dbc); if (Student.PersonId == 0) { int studentId = db.Add(Student); if (Student.Doctors.Count > 0) { db = new DoctorData(dbc); foreach (Doctor doctor in Student.Doctors) { db.Allocate(doctor, studentId); } } if (Student.NextOfKin.Count > 0) { db = new NextOfKinData(dbc); foreach (NextOfKin nok in Student.NextOfKin) { if (nok.PersonId == 0) { nok.PersonId = db.Add(nok, studentId); } else { db.Allocate(nok, studentId); } } } if (Student.EmergencyContacts.Count > 0) { db = new EmergencyContactData(dbc); foreach (EmergencyContact ec in Student.EmergencyContacts) { //if (ec.PersonId == 0) //{ ec.PersonId = db.Add(ec, studentId); //} //db.Allocate(ec, studentId); } } if (Student.MedicalConditions.Count > 0) { MedicalConditionData mdc = new MedicalConditionData(dbc); foreach (MedicalCondition mc in Student.MedicalConditions) { mdc.Add(mc, studentId); } } } else { db.Update(Student); } dbc.CommitTransactions(); dbc.CloseConnection(); Student.RemovedObjects.Clear(); } catch (Exception ex) { dbc.rollbackTransactions(); dbc.CloseConnection(); throw new Exception(ex.Message); } }