Example #1
0
        //public async Task<StudentE> GetById(int Id)
        //{
        //    using (SqlConnection sql = new SqlConnection(_connectionString))
        //    {
        //        using (SqlCommand cmd = new SqlCommand("sdGetById", sql))
        //        {
        //            cmd.CommandType = System.Data.CommandType.StoredProcedure;
        //            cmd.Parameters.Add(new SqlParameter("@id", Id));
        //            StudentE response = null;
        //            await sql.OpenAsync();

        //            using (var reader = await cmd.ExecuteReaderAsync())
        //            {
        //                while (await reader.ReadAsync())
        //                {
        //                    response = MapToValue(reader);
        //                }
        //            }

        //            return response;
        //        }
        //    }
        //}


        public async Task <bool> Insert(StudentE value)
        {
            using (SqlConnection sql = new SqlConnection(_connectionString))
            {
                using (SqlCommand cmd = new SqlCommand("spAddStudent", sql))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@name", value.name));
                    cmd.Parameters.Add(new SqlParameter("@address", value.address));
                    cmd.Parameters.Add(new SqlParameter("@city", value.city));
                    cmd.Parameters.Add(new SqlParameter("@phone", value.phone));

                    await sql.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();

                    return(true);
                }
            }
        }
Example #2
0
        public async Task <bool> Update(int id, StudentE smodel)
        {
            using (SqlConnection sql = new SqlConnection(_connectionString))
            {
                using (SqlCommand cmd = new SqlCommand("spUpdateStudent", sql))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@id", id));
                    cmd.Parameters.Add(new SqlParameter("@name", smodel.name));
                    cmd.Parameters.Add(new SqlParameter("@address", smodel.address));
                    cmd.Parameters.Add(new SqlParameter("@city", smodel.city));
                    cmd.Parameters.Add(new SqlParameter("@phone", smodel.phone));

                    await sql.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();

                    return(true);
                }
            }
        }