0

I'm creating a feature which allows a user to add an certain amount of money to a 'Swiss bank'. The balance of the swiss bank is stored in the db (idand balance) for each user. I'm stuck on how to display the current balance of the user and how to add or witdraw an amount of money. I'm very new on c#and mvc4 so help is really appreciated (just a push in the right direction would be awesome).

Controller:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FiveGangs.Models;

namespace FiveGangs.Controllers {
public class BankController : Controller {
    private FGEntities db = new FGEntities();
    //
    // GET: /SwissBank/

    [HttpGet]
    public ActionResult Index()
    {
        var gangster =
            db.UserGangster.FirstOrDefault(g => g.UserProfile.UserName == User.Identity.Name && g.Health > 0);
    }

    public ActionResult Index() {
        return View(db.SwissBank);
    }

}
}

Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FiveGangs.Models
{
public partial class SwissBank {
    public int Id { get; set; }
    public string Balance { get; set; }
 }
 }

View:

    @using FiveGangs.Models
    @model System.Data.Entity.DbSet<SwissBank>

    @{
    ViewBag.Title = "Bank";
    }

<h2>Bank</h2>

<form>
  <fieldset>
    <legend>Swiss Bank</legend>
      <label>Balance: @String.Format("{0:C0}", @Model.Balance)</label>
      <span class="add-on">$</span>
      <input type="text" placeholder="Amount...">
      <span class="help-block">Withdrawing from your Swiss bank will cost you 25% of the amount of cash withdrawn!</span>
     <button class="btn" type="button">Deposit</button>
  <button class="btn" type="button">Withdraw</button>
  </fieldset>
</form>
2
  • Have you designed the database tables to store the account informations Commented May 19, 2013 at 11:11
  • Here are a few steps, 1. You create a model to represent the account [Account Id] 2. Your account model will have userId, Amt_Withdrawl, Amt_Deposit, Amt_balance etc... where the Amt_balance is a calculated property. 3. When you are trying to get the user's balance amount, you will just call the query that returns based on the UserId Commented May 19, 2013 at 11:27

1 Answer 1

1

Step 1: Create a Action Method for Create.

public ActionResult Create() {
    return View();
}

Step 2: Add View with same name

Step 3: Add Another Action Method to receive post data and save

[HttpPost]
public ActionResult Create(SwissBank swisBank) {
    if(ModelState.Isvalid)
    {
        db.SwisBank.Add(swisBank);
        db.SaceChanges()
    }
    return View();
}

Read this documents:

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application

It will help you.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this got me further!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.