コード例 #1
0
        public IActionResult EditGymEquipment(int id)
        {
            GymEquipment model = new GymEquipment();

            model = gymDAL.GetEquipment(id);
            return(View(model));
        }
コード例 #2
0
ファイル: GymSqlDAL.cs プロジェクト: swcollins92/gymcompanion
        public GymEquipment GetEquipment(int id)
        {
            GymEquipment equip = new GymEquipment();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("Select * From gym_equipment WHERE id = @id ", conn);
                    cmd.Parameters.AddWithValue("@id", id);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        equip = MapRowToEquipment(reader);
                    }

                    return(equip);
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
        }
コード例 #3
0
ファイル: GymSqlDAL.cs プロジェクト: swcollins92/gymcompanion
        public List <GymEquipment> GetEquipments()
        {
            List <GymEquipment> list  = new List <GymEquipment>();
            GymEquipment        equip = new GymEquipment();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("Select * From gym_equipment ", conn);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        equip = MapRowToEquipment(reader);
                        list.Add(equip);
                    }

                    return(list);
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
        }
コード例 #4
0
ファイル: GymSqlDAL.cs プロジェクト: swcollins92/gymcompanion
        public bool AddGymEquipment(GymEquipment equip)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("INSERT INTO gym_equipment (name, usage, photo_path) " +
                                                    "VALUES (@name, @usage, @photo_path)", conn);
                    cmd.Parameters.AddWithValue("@name", equip.Name);
                    cmd.Parameters.AddWithValue("@usage", equip.ProperUsage);
                    cmd.Parameters.AddWithValue("@photo_path", equip.PhotoPath);

                    cmd.ExecuteNonQuery();

                    return(true);
                }
            }
            catch (SqlException ex)
            {
                return(false);

                throw;
            }
        }
コード例 #5
0
        public IActionResult AddGymEquipment(GymEquipment model)
        {
            if (ModelState.IsValid)
            {
                gymDAL.AddGymEquipment(model);
            }

            return(RedirectToAction(nameof(ViewEquipments)));
        }
コード例 #6
0
        public IActionResult AddGymEquipment()
        {
            GymEquipment model = new GymEquipment();

            return(View(model));
        }