/// <summary> /// Tem perfil? /// </summary> /// <param name="r"></param> /// <param name="l"></param> /// <returns></returns> public void AddProfileRole(ProfileRole.Role r, RacMsg.Language l) { if (l == RacMsg.Language.Indifferent) { for (int i = 0; i < roles.Count; i++) { if (roles[i].role == r) { return; } } } else { for (int i = 0; i < roles.Count; i++) { if (roles[i].role == r && roles[i].language == l) { return; } } } ProfileRole p = new ProfileRole(this); p.role = r; p.language = l; roles.Add(p); }
/// <summary> /// Carrega o artigo pelo id /// </summary> /// <param name="id"></param> /// <returns></returns> public static List <ProfileRole> LoadAllFrom(Profile p) { List <ProfileRole> lst = new List <ProfileRole>(); SqlCommand sel = new SqlCommand(); sel.CommandText = "SELECT role, language FROM " + Base.conf.prefix + "[newsprofilerole] WHERE id=@userid"; sel.Parameters.Add(new SqlParameter("@userid", p.user.id)); sel.Connection = Base.conf.Open(); SqlDataReader rdr = sel.ExecuteReader(); while (rdr.Read()) { // Pega as informações ProfileRole pm = new ProfileRole(p); pm.roleInt = rdr.GetInt32(0); pm.languageInt = rdr.GetInt32(1); lst.Add(pm); } rdr.Close(); sel.Connection.Close(); return(lst); }
/// <summary> /// Salva a ticket /// </summary> /// <returns></returns> public bool Save() { bool res = false; SqlCommand sel = new SqlCommand(); sel.CommandText = "SELECT id FROM " + Base.conf.prefix + "[newsprofile] WHERE id=@id"; sel.Parameters.Add(new SqlParameter("@id", user.id)); sel.Connection = Base.conf.Open(); SqlDataReader rdr = sel.ExecuteReader(); if (!rdr.Read()) { rdr.Close(); sel.Connection.Close(); SqlCommand ins = new SqlCommand(); ins.CommandText = "INSERT INTO " + Base.conf.prefix + "[newsprofile] (id, bitcoin, lastmodified) VALUES (@id, @bitcoin, @lastmodified)"; ins.Parameters.Add(new SqlParameter("@id", user.id)); ins.Parameters.Add(new SqlParameter("@bitcoin", bitcoinInt)); ins.Parameters.Add(new SqlParameter("@lastmodified", lastmodifiedInt)); ins.Connection = Base.conf.Open(); ins.ExecuteNonQuery(); ins.Connection.Close(); res = true; } else { rdr.Close(); sel.Connection.Close(); SqlCommand upd = new SqlCommand(); upd.CommandText = "UPDATE " + Base.conf.prefix + "[newsprofile] SET bitcoin=@bitcoin, lastmodified=@lastmodified WHERE id=@id"; upd.Parameters.Add(new SqlParameter("@id", user.id)); upd.Parameters.Add(new SqlParameter("@bitcoin", bitcoinInt)); upd.Parameters.Add(new SqlParameter("@lastmodified", lastmodifiedInt)); upd.Connection = Base.conf.Open(); upd.ExecuteNonQuery(); upd.Connection.Close(); res = true; } if (res) { if (rolesInt != null) { ProfileRole.SaveAll(this, roles); } if (pointsInt != null) { foreach (ProfilePoints pts in points) { pts.Save(); } } if (medalsInt != null) { foreach (ProfileMedals med in medals) { med.Save(); } } if (paymentsInt != null) { foreach (Payment pay in payments) { pay.Save(); } } } return(res); }