public ActionResult AddScheme(MobileScheme mobileScheme) { if (ModelState.IsValid) { try { if (mobileScheme.ProviderId <= 0) { ModelState.AddModelError("", "Specifying Provider Name is mandatory."); } else { MobileManager.AddMobileScheme(mobileScheme); MvcApplication.SetMessage("Mobile Scheme added successfully."); return RedirectToAction("Index", "Home"); } } catch (Exception ex) { MvcApplication.SetMessage(ex.Message); ViewBag.message = MvcApplication.GetMessage(); } } else { if (mobileScheme.ProviderId <= 0) ModelState.AddModelError("", "Specifying Provider Name is mandatory."); } mobileScheme.ConnectionTypes.Add(new SelectListItem { Text = "Prepaid", Value = ConnectionType.Prepaid.ToString(), Selected = true }); mobileScheme.ConnectionTypes.Add(new SelectListItem { Text = "Postpaid", Value = ConnectionType.Postpaid.ToString() }); List<Company> mobileCompanies = MobileManager.GetMobileCompanies(); foreach (var item in mobileCompanies) { mobileScheme.ServiceProviders.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); } return View(mobileScheme); }
public ActionResult AddScheme() { var schemeModel = new MobileScheme(); schemeModel.ConnectionTypes.Add(new SelectListItem { Text = "Prepaid", Value = ConnectionType.Prepaid.ToString(), Selected = true }); schemeModel.ConnectionTypes.Add(new SelectListItem { Text = "Postpaid", Value = ConnectionType.Postpaid.ToString() }); List<Company> mobileCompanies = MobileManager.GetMobileCompanies(); foreach (var item in mobileCompanies) { schemeModel.ServiceProviders.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); } return View(schemeModel); }
public static int Insert(MobileScheme mobileScheme) { int result = 0; using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[Connection.ConnectionName].ConnectionString)) { string insertstmt = "INSERT INTO [dbo].[MobileScheme] ( [name], [provider], [ctype], [deposit], [activationcharge], [rent], [price], [talktime], [localtosame], [localtoother], [localtolandline], [stdtosame], [stdtoother], [stdtolandline], [international], [nationalsms], [internationalsms]) VALUES (@name,@provider,@ctype,@deposit,@activationcharge,@rent,@price,@talktime,@localtosame,@localtoother,@localtolandline,@stdtosame,@stdtoother,@stdtolandline,@international,@nationalsms,@internationalsms)"; SqlCommand command = new SqlCommand(insertstmt, myConnection); command.CommandType = CommandType.Text; command.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = mobileScheme.Name; command.Parameters.Add("@provider", SqlDbType.Int).Value = mobileScheme.ProviderId; command.Parameters.Add("@ctype", SqlDbType.Int).Value = (int)mobileScheme.Type; command.Parameters.Add("@deposit", SqlDbType.Money).Value = mobileScheme.Deposit; command.Parameters.Add("@activationcharge", SqlDbType.Money).Value = mobileScheme.ActivationCharge; command.Parameters.Add("@rent", SqlDbType.Money).Value = mobileScheme.Rent; command.Parameters.Add("@price", SqlDbType.Money).Value = mobileScheme.Price; command.Parameters.Add("@talktime", SqlDbType.Int).Value = mobileScheme.TalkTime; command.Parameters.Add("@localtosame", SqlDbType.Money).Value = mobileScheme.LocalToSame; command.Parameters.Add("@localtoother", SqlDbType.Money).Value = mobileScheme.LocalToOther; command.Parameters.Add("@localtolandline", SqlDbType.Money).Value = mobileScheme.LocalToLandline; command.Parameters.Add("@stdtosame", SqlDbType.Money).Value = mobileScheme.StdToSame; command.Parameters.Add("@stdtoother", SqlDbType.Money).Value = mobileScheme.StdToOther; command.Parameters.Add("@stdtolandline", SqlDbType.Money).Value = mobileScheme.StdToLandline; command.Parameters.Add("@international", SqlDbType.Money).Value = mobileScheme.International; command.Parameters.Add("@nationalsms", SqlDbType.Money).Value = mobileScheme.NationalSms; command.Parameters.Add("@internationalsms", SqlDbType.Money).Value = mobileScheme.InternationalSms; 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 AddMobileScheme(MobileScheme mobileScheme) { return MobileSchemeDB.Insert(mobileScheme); }
private static MobileScheme FillDataRecord(IDataRecord myDataRecord) { MobileScheme mobileScheme = new MobileScheme(); mobileScheme.Id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("Id")); mobileScheme.Name = myDataRecord.GetString(myDataRecord.GetOrdinal("name")); mobileScheme.ProviderId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("provider")); mobileScheme.Type = (ConnectionType)myDataRecord.GetInt32(myDataRecord.GetOrdinal("ctype")); mobileScheme.Deposit = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("deposit")); mobileScheme.ActivationCharge = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("activationcharge")); mobileScheme.Rent = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("rent")); mobileScheme.Price = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("price")); mobileScheme.TalkTime = myDataRecord.GetInt32(myDataRecord.GetOrdinal("talktime")); mobileScheme.LocalToSame = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("localtosame")); mobileScheme.LocalToOther = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("localtoother")); mobileScheme.LocalToLandline = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("localtolandline")); mobileScheme.StdToSame = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("stdtosame")); mobileScheme.StdToOther = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("stdtoother")); mobileScheme.StdToLandline = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("stdtolandline")); mobileScheme.International = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("international")); mobileScheme.NationalSms = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("nationalsms")); mobileScheme.InternationalSms = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("internationalsms")); return mobileScheme; }