Example #1
0
 public bool Login(string userName, string passWord)
 {
     object[] sqlParams = new sqlParameter[]
     {
         new SqlParameter("@Username", userName),
         new Sqlparameter("@Password", passWord),
     };
     var res = context.Database.SqlQuery <bool>("Sp_Account_Login, @Username,@Password", sqlParams).SingleOrDefault();
 }
        public List <Animal> GetAnimals()
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand   cmd             = new SqlCommand("SELECT * FROM animals WHERE type_id = @TypeId;", conn);
            SqlParameter typeIdParameter = new sqlParameter();

            typeIdParameter.ParameterName = "@TypeId";
            typeIdParameter.Value         = this.GetId();
            cmd.Parameters.Add(typeIdParameter);
            SqlDataReader rdr = cmd.ExecuteReader();

            List <Animal> animals = new List <Animal> {
            };

            while (rdr.Read())
            {
                int      animalId         = rdr.GetInt32(0);
                string   animalName       = rdr.GetString(1);
                string   animalGender     = rdr.GetString(2);
                DateTime animalAdmittance = rdr.GetDateTime(3);
                string   animalBreed      = rdr.GetString(4);
                int      animalTypeId     = rdr.GetInt32(5);

                Animal newAnimal = new Animal(animalName, animalGender, animalAdmittance, animalBreed, animalTypeId);
                animals.Add(newAnimal);
            }

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                rdr.Close();
            }
            return(animals);
        }