HBS.Data.Concrete.AdminRepository.GetModulesByCompany C# (CSharp) Method

GetModulesByCompany() public method

public GetModulesByCompany ( int companyid ) : List
companyid int
return List
        public List<Module> GetModulesByCompany(int companyid)
        {
            List<Module> lstModules = null;
            Module module = null;
            using (var conn = new SqlConnection(PrescienceRxConnectionString))
            {
                conn.Open();
                using (var cmd = new SqlCommand(GetModulesByCompanyIdSp, conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("@CompanyId", System.Data.SqlDbType.Int);
                    cmd.Parameters["@CompanyId"].Value = companyid;
                    using (var myReader = cmd.ExecuteReader())
                    {
                        try
                        {
                            if (myReader.HasRows)
                            {
                                lstModules = new List<Module>();
                                while (myReader.Read())
                                {
                                    module = new Module(myReader);
                                    lstModules.Add(module);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            // TODO Logg Error here
                        }
                    }
                }

            }

            return lstModules;
        }

Usage Example

        //
        public Company GetCompnay(int companyId)
        {
            Company company = null;
            using (var conn = new SqlConnection(PrescienceRxConnectionString))
            {
                conn.Open();

                using (var cmd = new SqlCommand(GetCompanyByIdSp, conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.Add("@CompanyId", System.Data.SqlDbType.Int);
                    cmd.Parameters["@CompanyId"].Value = companyId;

                    using (var myReader = cmd.ExecuteReader())
                    {
                        try
                        {
                            if (myReader.HasRows)
                            {
                                myReader.Read();
                                company = new Company(myReader);
                                AdminRepository admrep = new AdminRepository();
                                List<Module> modules = admrep.GetModulesByCompany(Convert.ToInt32(myReader["CompanyId"]));
                                company.LstModules = new List<int>();
                                foreach (var item in modules)
                                {
                                    company.LstModules.Add(item.ModuleId);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            // TODO Logg Error here
                        }
                    }
                }

            }
            return company;
        }
All Usage Examples Of HBS.Data.Concrete.AdminRepository::GetModulesByCompany