public IHttpActionResult GetAvailablePaymentMethods([FromUri] UserPaymentModel requestModel) { if (requestModel == null || !ModelState.IsValid) { return(Json(new { Success = false, Message = "Invalid data supplied" })); } ; //first check if the customer has an address, otherwise first address form will be shown var currentUser = ApplicationContext.Current.CurrentUser; var battleId = requestModel.BattleId; var battleType = requestModel.BattleType; var purchaseType = requestModel.PurchaseType; //TODO: Remove comment when picture battles are ready var battle = _videoBattleService.Get(battleId); // Model.BattleType == BattleType.Video ? _videoBattleService.GetById(Model.BattleId) : null; var responseModel = new UserPaymentPublicModel { IsAmountVariable = purchaseType == PurchaseType.SponsorPass || battle.CanVoterIncreaseVotingCharge, MinimumPaymentAmount = purchaseType == PurchaseType.SponsorPass ? battle.MinimumSponsorshipAmount : battle.MinimumVotingCharge, PurchaseType = requestModel.PurchaseType }; //if purchase type is sponsor and customer is already a sponsor, he should not have a minimum amount criteria if (purchaseType == PurchaseType.SponsorPass) { var alreadySponsor = _sponsorService.Get(x => x.BattleId == battleId && x.BattleType == battleType, null).Any(); if (alreadySponsor) { responseModel.MinimumPaymentAmount = 1; } } //get available credits responseModel.AvailableCredits = _creditService.GetAvailableCreditsCount(currentUser.Id, null); //set the usable credits now responseModel.UsableCredits = _creditService.GetUsableCreditsCount(currentUser.Id); //let's get the payment methods for the logged in user var paymentMethods = _paymentMethodService.GetCustomerPaymentMethods(currentUser.Id); foreach (var pm in paymentMethods) { responseModel.UserPaymentMethods.Add(new System.Web.Mvc.SelectListItem() { Text = pm.NameOnCard + " (" + pm.CardNumberMasked + ")", Value = pm.Id.ToString() }); } if (battle.VideoBattleStatus == BattleStatus.Complete) { return(Json(new { Success = false, Message = "Battle completed" })); } //battle should not be complete before payment form can be opened return(Json(new { Success = true, AvailablePaymentMethods = responseModel })); }
public PaymentVML GetOrdersPaymentsByUser(UserPaymentModel upm) { MECProjectDBEntities t = new MECProjectDBEntities(); List <PaymentVM> og = new List <PaymentVM>(); PaymentVML pml = new PaymentVML(); string userId = upm.emailId; string status = upm.status; int adminTotal = 0; int shopkeeperTotal = 0; //string connectionString = "Data Source=(local);Initial Catalog=MECProjectDB;Integrated Security=true"; string connectionString = "data source=184.154.206.133; initial catalog=MECProjectDB;user id=MECProjectUser; password=$Default123"; using (SqlConnection connection = new SqlConnection(connectionString)) { // Create the Command and Parameter objects. SqlCommand command = new SqlCommand("sp_OrdersPaymentByUsers", connection); command.CommandType = CommandType.StoredProcedure; //command.Parameters.AddWithValue("@date", DateTime.Now); command.Parameters.Add(new SqlParameter("@userId", SqlDbType.VarChar)); command.Parameters["@userId"].Value = userId; if (status == "received") { command.Parameters.Add(new SqlParameter("@status", SqlDbType.VarChar)); command.Parameters["@status"].Value = "Completed"; } else { command.Parameters.Add(new SqlParameter("@status", SqlDbType.VarChar)); command.Parameters["@status"].Value = status; } try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { PaymentVM ogv = new PaymentVM(); if (reader != null) { ogv.order_ID = Convert.ToInt32(reader["order_ID"]); ogv.dateOfOrder = Convert.ToDateTime(reader["dateOfOrder"]); ogv.order_amount = Convert.ToInt32(reader["order_amount"]); ogv.order_status = reader["order_status"].ToString(); ogv.trackingId = reader["trackingId"].ToString(); ogv.user_name = reader["clint_name"].ToString(); ogv.phone = reader["clint_phone"].ToString(); ogv.address = reader["clint_address"].ToString(); ogv.serviceId = Convert.ToInt32(reader["service_ID"]); shopkeeperTotal = Convert.ToInt32(reader["totalShopkeerAmount"]); try { if (reader["Admin_amount"] != null) { if (reader["Admin_amount"] != DBNull.Value) { ogv.Admin_amount = Convert.ToInt32(reader["Admin_amount"]); } } } catch (Exception) { } try { if (reader["shopkeeper_amount"] != null) { if (reader["shopkeeper_amount"] != DBNull.Value) { ogv.shopkeeper_amount = Convert.ToInt32(reader["shopkeeper_amount"]); } } } catch (Exception) { } ogv.adminTotal = adminTotal; ogv.shopkeeperTotal = shopkeeperTotal; og.Add(ogv); } } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } pml.paymentList = og; pml.adminTotal = adminTotal; pml.shopkeeperTotal = shopkeeperTotal; return(pml); }