public ActionResult Portfolio(int id) { PortfolioModel model = new PortfolioModel(); if (!IsAuthorized(model)) { return(RedirectToAction("Index", "Home")); } using (var db = new SqlLinkDataContext()) { if (db.Fios.Any(f => f.Id == id)) { var portfolio = db.Fios.Single(f => f.Id == id); if (model.UserId != portfolio.UserId) { return(new HttpStatusCodeResult(403, "That portfolio doesn't belong to you!")); } model.Portfolio = portfolio; model.Bills = portfolio.Bills.Select(b => new BillModel() { Bill = b, Payers = b.PaymentDetails.Select(pd => new KeyValuePair <Payer, PaymentDetail>(pd.Payer, pd)).ToArray() }).ToArray(); model.People = portfolio.Payers.ToArray(); return(View("Summary", model)); } else { return(new HttpNotFoundResult("That ID doesn't exist :(")); } } }
public ActionResult Bill(int id) { var model = new BillModel(); if (!IsAuthorized(model)) { return(RedirectToAction("Index", "Home")); } using (var db = new SqlLinkDataContext()) { if (db.Bills.Any(b => b.Id == id)) { var bill = db.Bills.Single(f => f.Id == id); if (model.UserId != bill.Fio.UserId) { return(new HttpStatusCodeResult(403, "That bill doesn't belong to you!")); } model.Bill = bill; model.Payers = bill.PaymentDetails.Select(pd => new KeyValuePair <Payer, PaymentDetail>(pd.Payer, pd)).ToArray(); return(View(model)); } else { return(new HttpNotFoundResult("That ID doesn't exist :(")); } } }
public static string PayLink(int pdId) { using (var db = new SqlLinkDataContext()) { var pd = db.PaymentDetails.Single(p => p.Id == pdId); return($"https://venmo.com/{pd.Bill.Fio.User.VenmoId}?txn=pay&amount={(double)pd.Bill.RAmount * pd.RPercent}"); } }
public static string RequestLink(int pdId, bool recurring = true) { using (var db = new SqlLinkDataContext()) { var pd = db.PaymentDetails.Single(p => p.Id == pdId); if (recurring) { return($"https://venmo.com/{pd.Payer.VenmoId}?txn=charge&amount={(double)pd.Bill.RAmount * pd.RPercent}¬e=via+splitwithfio.com"); } return($"https://venmo.com/{pd.Payer.VenmoId}?txn=charge&amount={(double)pd.Bill.SAmount * pd.SPercent}¬e=via+splitwithfio.com"); } }
public ActionResult CheckUsername(string username) { using (var db = new SqlLinkDataContext()) { if (db.Users.Any(u => u.Username.ToLower() == username.ToLower())) { return(new HttpStatusCodeResult(409)); } else { return(new HttpStatusCodeResult(200)); } } }
// GET: Dashboard public ActionResult Index() { var model = new DashboardModel(); if (!IsAuthorized(model)) { return(RedirectToAction("Index", "Home")); } using (var db = new SqlLinkDataContext()) { model.Portfolios = db.Fios.Where(f => f.UserId == model.UserId).ToArray(); } return(View(model)); }
/// <summary> /// Checks if the current session is an authorised user /// </summary> /// <param name="model">The model, must inherit from <see cref="AuthModel"/> </param> /// <returns>True if authorized, false if not logged in</returns> private bool IsAuthorized(AuthModel model) { if (Session["UserId"] == null) { return(false); } using (var db = new SqlLinkDataContext()) { model.UserId = (int)Session["UserId"]; model.Username = (string)Session["Username"]; model.Name = (string)Session["UserRealname"]; model.IsLoggedIn = true; return(true); } }
public ActionResult Login(string username, string password) { using (var db = new SqlLinkDataContext()) { if (db.Users.Any(u => u.Username.ToLower() == username.ToLower() && u.Password.Equals(password))) { var user = db.Users.Single(u => u.Username.ToLower() == username.ToLower()); Session["UserId"] = user.Id; Session["Username"] = user.Username; Session["UserRealname"] = user.RealName; return(RedirectToAction("Index", "Dashboard")); } return(RedirectToAction("Index", "Home")); } }
/// <summary> /// Create a user account /// </summary> /// <param name="username">Desired username <see cref="User.Username"/> </param> /// <param name="venmoId">Venmo Identifier for the user to receive payments <see cref="User.VenmoId"/> </param> /// <param name="password">Password <see cref="User.Password"/> </param> /// <returns>Redirects to dashboard if user created, goes back to signup if error</returns> //[HttpPost] public ActionResult CreateAccount(string username, string venmoId, string password, string name) { using (var db = new SqlLinkDataContext()) { if (db.Users.Any(u => u.Username.ToLower() == username.ToLower())) { return(RedirectToAction("Index", new { Error = "Username taken" })); } var user = new User() { Username = username, Password = password, VenmoId = venmoId, RealName = name }; db.Users.InsertOnSubmit(user); db.SubmitChanges(); return(RedirectToAction("Login", new { username = user.Username, password = user.Password })); } }
public ActionResult CreatePortfolio(string json) { var model = new AuthModel(); if (!IsAuthorized(model)) { return(new HttpStatusCodeResult(401)); } var data = JsonConvert.DeserializeObject <CreatePortfolio>(json); using (var db = new SqlLinkDataContext()) { var portfolio = new Fio() { Name = data.Name, UserId = model.UserId }; db.Fios.InsertOnSubmit(portfolio); db.SubmitChanges(); var payers = data.Roommates.Select(r => new Payer() { Name = r.Name, Fio = portfolio, VenmoId = r.VenmoId }); db.Payers.InsertAllOnSubmit(payers); db.SubmitChanges(); var inc = new IdNameCombo() { Id = portfolio.Id, Payers = payers.OrderBy(p => p.Id).Select(p => p.Name).ToArray() }; return(Json(inc)); } return(new HttpStatusCodeResult(200)); }
public ActionResult AddBills(string json, int id) { var model = new AuthModel(); if (!IsAuthorized(model)) { return(new HttpStatusCodeResult(401)); } json = json.Replace("null", "0"); var data = JsonConvert.DeserializeObject <Bills>(json); using (var db = new SqlLinkDataContext()) { var por = db.Fios.Single(x => x.Id == id); var rentBill = new Bill() { Name = "Rent", RAmount = (decimal)data.RentTotal }; var oneTime = new Bill() { Name = "OneTime", SAmount = (decimal)data.OneTime.Sum() }; var utilities = new Bill() { Name = "Utilities", RAmount = (decimal)data.Utilities.Sum() }; por.Bills.Add(rentBill); por.Bills.Add(oneTime); por.Bills.Add(utilities); db.SubmitChanges(); var pays = por.Payers.OrderBy(p => p.Id); int i = 0; foreach (var p in pays) { try { p.PaymentDetails.Add(new PaymentDetail() { Payer = p, Bill = rentBill, RPercent = data.Rent[i] / 100 }); } catch { } try { if (oneTime.SAmount == 0) { oneTime.SAmount = 0.01M; } p.PaymentDetails.Add(new PaymentDetail() { Payer = p, Bill = oneTime, SPercent = data.OneTime[i] / (double)oneTime.SAmount }); } catch { } try { if (utilities.RAmount == 0) { utilities.RAmount = 0.01M; } p.PaymentDetails.Add(new PaymentDetail() { Payer = p, Bill = utilities, RPercent = data.Utilities[i] / (double)utilities.RAmount }); } catch { } i++; } try { db.SubmitChanges(); }catch (Exception e) { } return(new HttpStatusCodeResult(200)); } }