/// <summary> /// Handles login process /// </summary> /// <param name="email">User's email input</param> /// <param name="password">User's password input</param> /// <returns></returns> public ActionResult Login(string email, string password) { // Create a error message variable for login failure alert ViewBag.ErrorMessage = null; // Object for data access layer AmigoWalletRepository dal = new AmigoWalletRepository(); // Check if the entered credentials match database records var status = dal.ValidateCredentials(email, password); if (status == 1) { // Upon success, create a session with user's emailID and direct user to account home page Session["email"] = email; Session.Timeout = 20; return(RedirectToAction("Home", "Account")); } // Return the error message on failure else { ViewBag.ErrorMessage = "Password/Email Combination Incorrect, Try Again"; } return(View("Index")); }
/// <summary> /// Register the user to the database with the entered user info /// </summary> /// <param name="user">User model object with user information</param> /// <returns></returns> public ActionResult RegisterUser(Models.User user) { try { // Object for data access layer AmigoWalletRepository dal = new AmigoWalletRepository(); // Maps User from model to DAL var mapObj = new AmigoWalletMapper <Models.User, User>(); // Send user object to database, and directly show user home page var status = dal.RegisterUser(mapObj.Translate(user)); if (status == 1) { Session["email"] = user.EmailId; return(RedirectToAction("Home", "Account")); } else { Session["regError"] = "Something went wrong, your email/phone may already be in use"; return(RedirectToAction("Index", "Register")); } } catch (Exception ex) { // For debugging exceptions return(RedirectToAction("Index", "Register")); } }
/// <summary> /// Handles bill payment when user clicks Pay /// </summary> /// <param name="collection">Form collection for bank info</param> /// <returns></returns> public ActionResult PayBill(FormCollection collection) { // Data access layer object var repObj = new AmigoWalletRepository(); // Reset previous session alert messages Session["message"] = null; Session["messageState"] = 0; // Put together a info string to be sent to database string info = "Utility Type: " + collection["Utilities"] + " Merchant: " + collection["Merchants"]; try { // Make the transaction and send success alert to view repObj.PayMerchant(Session["email"].ToString(), collection["Merchants"], Convert.ToDecimal(collection["amount"])); Session["message"] = info; Session["messageState"] = 1; } catch (Exception ex) { // Show error alert to the view with exception message Session["message"] = "Some error occurred: " + ex.Message; Session["messageState"] = -1; } // Refresh homepage return(RedirectToAction("Home")); }
/// <summary> /// Transfers amount to bank /// </summary> /// <param name="collection">Form collection for bank info</param> /// <returns></returns> public ActionResult TransferToBank(FormCollection collection) { // Data access layer object var repObj = new AmigoWalletRepository(); // Reset previous session alert messages Session["message"] = null; Session["messageState"] = 0; // Put together a info string to be sent to database string info = "IFSC: " + collection["ifsc"] + " Account Number: " + collection["accountNumber"] + " Account Holder: " + collection["accountHolder"]; try { // Make the transaction and send success alert to view repObj.TransferToBank(Session["email"].ToString(), Convert.ToDecimal(collection["amount"]), info, collection["remarks"]); Session["message"] = info; Session["messageState"] = 1; } catch (Exception ex) { // Show error alert to the view with exception message Session["message"] = "Some error occurred: " + ex.Message; Session["messageState"] = -1; } // Refresh homepage return(RedirectToAction("Home")); }
/// <summary> /// Adds a new card to the current user's account /// </summary> /// <param name="cardNumber">New card's number</param> /// <param name="expMonth">New card's expiry month</param> /// <param name="expYear">New card's expiry year</param> /// <returns></returns> public ActionResult AddNewCard(string cardNumber, int expMonth, int expYear) { // Data access layer object AmigoWalletRepository dal = new AmigoWalletRepository(); // New UserCard object with the required fields UserCard newCard = new UserCard(); newCard.CardNumber = cardNumber; newCard.EmailId = Session["email"].ToString(); newCard.ExpiryDate = new DateTime(expYear, expMonth, 1); // Add the card to the database var status = dal.AddNewCard(newCard); // Check for success if (status == 1) { // Refresh homepage to show new card information return(RedirectToAction("Home")); } else { // Show error if DAL failure return(View("Error")); } }
static void Main(string[] args) { //var dal = new AmigoWalletRepository(); //User usr = new User(); //usr.Name = "g"; //usr.EmailId = "*****@*****.**"; //usr.Password = "******"; //usr.MobileNumber = "1115550000"; //Console.WriteLine(""+dal.RegisterUser(usr).ToString()); var repobj = new AmigoWalletRepository(); var transList = repobj.ViewUserTransaction("*****@*****.**", new DateTime(2017, 7, 1), new DateTime(2017, 7, 2)); if (transList.Any()) { foreach (var transaction in transList) { Console.WriteLine(transaction.Amount.ToString()); } } else { Console.WriteLine("nothing"); } }
/// <summary> /// Transfer money from selected user's card /// </summary> /// <param name="card">User's selected card ID</param> /// <param name="amount">Desired amount to transfer to wallet</param> /// <returns></returns> public ActionResult TransferFromCard(int card, decimal amount) { // Data access layer object AmigoWalletRepository dal = new AmigoWalletRepository(); // Add money to wallet and check return status var status = dal.AddMoneyUsingCard(Session["email"].ToString(), card, amount, "none"); if (status == 1) { return(RedirectToAction("Home")); } // Refresh homepage return(RedirectToAction("Home")); }
/// <summary> /// Push the password change to the database /// </summary> /// <param name="oldPassword">User's old password</param> /// <param name="newPassword">User's new password</param> /// <returns></returns> public ActionResult SaveNewPassword(string oldPassword, string newPassword) { // Data access layer object AmigoWalletRepository dal = new AmigoWalletRepository(); // Make the password change for the user var status = dal.ResetPassword(Session["email"].ToString(), oldPassword, newPassword); if (status == 1) { // Password changed, refresh homepage return(RedirectToAction("Home")); } else { // Something went wrong, show status return(View(status.ToString())); } }
public ActionResult RedeemPoints() { if (Convert.ToInt32(Session["Rewards"]) < 10) { Session["message"] = "Not Enough Points To Redeem, Spend Some More Money"; Session["messageState"] = -1; } var repObj = new AmigoWalletRepository(); var status = repObj.RedeemPoints(Session["email"].ToString()); // Calculate rewards points and pass it to the view ViewBag.ViewRewards = repObj.GetRewardPoints(Session["email"].ToString()); Session["Rewards"] = repObj.GetRewardPoints(Session["email"].ToString()); if (status == 1) { return(RedirectToAction("Home", "Account")); } return(RedirectToAction("Home", "Account")); }
/// <summary> /// Fetches a JSON result for the selected service type for bill payment /// </summary> /// <param name="id">Selected service type ID</param> /// <returns></returns> public JsonResult GetMerchants(string id) { // Make a list of options for the select dropdown var merchants = new List <SelectListItem>(); // Data access layer object var repObj = new AmigoWalletRepository(); // Get a list of merchants who belongs to the selected service type and add them to the list of choices var merchantList = repObj.GetMerchantsByServiceType(Convert.ToByte(id)); for (int i = 0; i < merchantList.Count; i++) { merchants.Add(new SelectListItem { Text = merchantList[i].EmailId, Value = merchantList[i].EmailId }); } // Return the JSON result return(Json(new SelectList(merchants, "Value", "Text"))); }
public ActionResult PerformTransferToUser(Models.UserTransaction trans) { if (ModelState.IsValid) { try { var repObj = new AmigoWalletRepository(); var status = repObj.TransferToEWallet(Session["email"].ToString(), trans.EmailId, trans.Amount); if (status == 1) { return(RedirectToAction("Home", "Account")); } else { return(RedirectToAction("Home", "Account")); } } catch (Exception ex) { return(View(ex.Message.ToString())); } } return(RedirectToAction("Home", "Account")); }
public ActionResult PerformAddMoneyFromBank(string emailId, decimal amount) { if (ModelState.IsValid) { try { var repObj = new AmigoWalletRepository(); var status = repObj.AddMoneyUsingBank(emailId, amount); if (status == 1) { return(View("Success")); } else { return(View("Error")); } } catch (Exception) { return(View("Error")); } } return(View("AddMoneyFromBank")); }
/// <summary> /// Generates the account homepage with transactions, balance, cards, merchants, and utilities /// </summary> /// <param name="from">from date for the transactions to be fetched</param> /// <param name="from">to date for the transactions to be fetched</param> /// <returns></returns> public ActionResult Home(DateTime?from = null, DateTime?to = null) { try { // Data access layer object AmigoWalletRepository repObj = new AmigoWalletRepository(); // Calculate rewards points and pass it to the view ViewBag.ViewRewards = repObj.GetRewardPoints(Session["email"].ToString()); Session["Rewards"] = repObj.GetRewardPoints(Session["email"].ToString()); // Calculate balance points and pass it to the view ViewBag.ViewBalance = repObj.ViewBalance(Session["email"].ToString()); //------- Get cards ------- // Mapper for UserCard model to DAL AmigoWalletMapper <UserCard, Models.UserCard> map = new AmigoWalletMapper <UserCard, Models.UserCard>(); // Get the list of all cards current user has, and add to a model list via mapping List <UserCard> lstCards = repObj.getCardsBySessionEmail(Session["email"].ToString()); List <Models.UserCard> cards = new List <Models.UserCard>(); foreach (var card in lstCards) { cards.Add(map.Translate(card)); } // Pass cards to the view ViewBag.UserCards = cards; //------- Get transactions ------- // Mapper for the UserTransaction DAL to model var mapObj = new AmigoWalletMapper <UserTransaction, Models.UserTransaction>(); // Create non-nullable DateTime objects for from and to and set them to the required range if passed in as null var f = from ?? DateTime.Today.AddMonths(-1); var t = to ?? DateTime.Today.AddDays(2); // added two days to compensate for time difference // Get user's list of transactions var transList = repObj.ViewUserTransaction(Session["email"].ToString(), f, t); var transModelList = new List <Models.UserTransaction>(); // Pass date range as passed in to display on the view's date range selectors ViewBag.fromDate = f.ToString("yyyy-MM-dd"); ViewBag.toDate = t.ToString("yyyy-MM-dd"); // Fill the model list with mapper and pass it to the view for display foreach (var transaction in transList) { transModelList.Add(mapObj.Translate(transaction)); } ViewBag.Transactions = transModelList; //------- Pay bill utility list ------- // Fill list with the available service/utility types var utilList = new List <SelectListItem>(); var serviceTypeList = repObj.GetServiceTypes(); // Create a list of selection options for the utility list dropdown and pass it to the view utilList.Add(new SelectListItem { Text = "Please select a utility type", Value = "0" }); for (int i = 0; i < serviceTypeList.Count; i++) { utilList.Add(new SelectListItem { Text = serviceTypeList[i].ServiceType, Value = (i + 1).ToString() }); } ViewData["utilities"] = utilList; // Draw the account homepage return(View()); } catch (Exception) { // Show session expiration page and allow re-log return(View("_SessionExpired")); } }