Example #1
0
        // GET: Holdings/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Holding holding = db.Holdings.Find(id);

            if (holding == null)
            {
                return(HttpNotFound());
            }
            return(View(holding));
        }
Example #2
0
        public ActionResult Create(Stock stock, int quantity, float buyingPrice, float totalSum)
        {
            Holding         holding     = new Holding();
            Stock           stockToBuy  = db.Stocks.FirstOrDefault(s => s.ID == stock.ID);
            ApplicationUser currentUser = db.Users.Where(user => user.UserName == User.Identity.Name).FirstOrDefault();

            if (currentUser == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            holding.Buyer       = currentUser;
            holding.BuyingDate  = DateTime.Now;
            holding.BuyingPrice = buyingPrice;
            holding.Quantity    = quantity;
            holding.BuyingValue = totalSum;
            holding.StockName   = stock.Name;
            holding.Stock       = stockToBuy;

            db.Holdings.Add(holding);
            db.SaveChanges();
            return(new HttpStatusCodeResult(HttpStatusCode.Created));
        }