public ActionResult AddDTHPackage(DTHPackage dthPackage)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (dthPackage.ProviderId <= 0)
                    {
                        ModelState.AddModelError("", "Specifying Provider Name is mandatory.");
                        return View(dthPackage);
                    }
                    DTHManager.SaveDTHPackage(dthPackage);
                    MvcApplication.SetMessage("DTH Package added successfully.");

                    return RedirectToAction("ViewPackages");
                }
                catch (Exception ex)
                {
                    MvcApplication.SetMessage(ex.Message);
                    ViewBag.message = MvcApplication.GetMessage();
                }
            }
            else
            {
                if (dthPackage.ProviderId <= 0)
                    ModelState.AddModelError("", "Specifying Provider Name is mandatory.");
            }

            return View(dthPackage);
        }
        public static DTHPackage GetDTHPackage(int packageid)
        {
            DTHPackage DTHPackageDetails = new DTHPackage();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[Connection.ConnectionName].ConnectionString))
            {
                string sqlstmt = "select id, name, provider, duration, details, cost, points from [dbo].[DTHPackages] where id=@packageid";

                SqlCommand myCommand = new SqlCommand(sqlstmt, myConnection);
                myCommand.CommandType = CommandType.Text;

                myCommand.Parameters.AddWithValue("@packageid", packageid);

                myConnection.Open();
                using (SqlDataReader myReader = myCommand.ExecuteReader())
                {
                    if (myReader.Read())
                    {
                        DTHPackageDetails = FillDataRecord(myReader);
                    }
                    myReader.Close();
                }
                myConnection.Close();
            }
            return DTHPackageDetails;
        }
        public static int Insert(DTHPackage dthPackage)
        {
            int result = 0;
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[Connection.ConnectionName].ConnectionString))
            {
                string insertstmt = "INSERT INTO [dbo].[DTHPackages] ([name], [provider], [details], [duration], [cost], [points]) VALUES (@name, @provider, @details, @duration, @cost, @points)";

                SqlCommand command = new SqlCommand(insertstmt, myConnection);

                command.CommandType = CommandType.Text;

                command.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = dthPackage.Name;

                command.Parameters.Add("@provider", SqlDbType.Int).Value = dthPackage.ProviderId;

                if (dthPackage.Description == null)
                    command.Parameters.Add("@details", SqlDbType.VarChar, 400).Value = DBNull.Value;
                else
                    command.Parameters.Add("@details", SqlDbType.VarChar, 400).Value = dthPackage.Description;

                command.Parameters.Add("@duration", SqlDbType.Int).Value = dthPackage.Duration;

                command.Parameters.Add("@cost", SqlDbType.Money).Value = dthPackage.Cost;

                command.Parameters.Add("@points", SqlDbType.Int).Value = dthPackage.Points;

                DbParameter returnValue;
                returnValue = command.CreateParameter();
                returnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(returnValue);

                myConnection.Open();
                command.ExecuteNonQuery();
                result = Convert.ToInt32(returnValue.Value);
                myConnection.Close();
            }
            return result;
        }
 public static int SaveDTHPackage(DTHPackage dthPackage)
 {
     return DTHPackageDB.Insert(dthPackage);
 }
        private static DTHPackage FillDataRecord(IDataRecord myDataRecord)
        {
            DTHPackage package = new DTHPackage();

            package.Id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("id"));
            package.Name = myDataRecord.GetString(myDataRecord.GetOrdinal("name"));
            package.ProviderId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("provider"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("details")))
                package.Description = myDataRecord.GetString(myDataRecord.GetOrdinal("details"));
            else
                package.Description = "";

            package.Duration = myDataRecord.GetInt32(myDataRecord.GetOrdinal("duration"));
            package.Cost = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("cost"));
            package.Points = myDataRecord.GetInt32(myDataRecord.GetOrdinal("points"));

            return package;
        }
 public AvailPackageViewModel()
 {
     dthPackage = new DTHPackage();
     paymentModel = new PaymentControlModel();
 }