示例#1
0
        public ActionResult CheckStatusOwner()
        {
            string userId = User.Identity.GetUserId();

            if (User.IsInRole("Administrator"))
            {
                return(RedirectToAction("ResourceIndex", "Account"));
            }

            SailiRepository repository = new SailiRepository();
            string          ownerid    = repository.CheckStatus(User.Identity.GetUserId());

            if (!String.IsNullOrEmpty(ownerid))
            {
                return(RedirectToAction("CheckStatusTrader", "TraderAccount", new
                {
                    OwnerID = ownerid
                }));
            }
            else
            {
                return(RedirectToAction("Create", new
                {
                    userId = User.Identity.GetUserId()
                }));
            }
        }
示例#2
0
        public ActionResult Buy(BuyModel model)
        {
            if (model.Quantity < 1)
            {
                TempData["BuyException"] = "Buying 0 stocks... Please try again";
                return(RedirectToAction("ConfirmBuy", new { symbol = model.Symbol }));
            }

            decimal transactionCost = (decimal)TransactionCost.BuyCost * (model.Quantity * model.PurchasePrice);

            string[]        temp       = model.Symbol.Split(',');
            SailiRepository repository = new SailiRepository();
            Buy             buy        = new Buy();

            buy.TradeDate         = DateTime.Now;
            buy.TickerSymbol      = temp[0];
            buy.Quantity          = model.Quantity;
            buy.PurchasePrice     = model.PurchasePrice;
            buy.TransactionAmount = model.Quantity * model.PurchasePrice + transactionCost;
            buy.TransactionCost   = transactionCost;
            buy = repository.Finalizebuy(buy, User.Identity.GetUserId());

            Owner owner = repository.GetOwner(User.Identity.GetUserId());

            TraderAccount trader = repository.GetTrader(owner.OwnerID);

            return(RedirectToAction("Details", "TraderAccount", new
            {
                TradingAccountID = trader.TradingAccountID
            }));
        }
示例#3
0
        public ActionResult ConfirmSell(string tradingAccountID, int buyID)
        {
            if (tradingAccountID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Portfolio       portfolio  = null;
            SailiRepository repository = new SailiRepository();

            portfolio = repository.GetPortfolio(tradingAccountID);

            if (portfolio == null)
            {
                return(HttpNotFound());
            }

            var buy = DefaultConnection.Buys.Find(buyID);

            if (!buy.PortfolioId.Equals(portfolio.PortfolioID))
            {
                DataSerializer <string> .SecurityPriorityNumberOne(User.Identity.GetUserId());

                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }

            Company         company  = new Company();
            List <Listings> listings = new List <Listings>();

            company = repository.GetCompany(company, buy.TickerSymbol);
            DataSerializer <string> .GetSingleListings(ref listings, company.Symbol);

            Sell sell = new Sell();

            sell.BuyID         = buy.BuyID;
            sell.TickerSymbol  = buy.TickerSymbol;
            sell.PurchasePrice = buy.PurchasePrice;

            foreach (var list in listings)
            {
                if (list.Symbol.Equals(sell.TickerSymbol))
                {
                    sell.SoldPrice = list.Close;
                }
            }

            TempData["ShareQuantity"] = buy.Quantity;
            TempData["CompanyName"]   = company.CompanyName;

            return(View(sell));
        }
示例#4
0
        public ActionResult Sell(Sell model)
        {
            try
            {
                Buy             buy        = DefaultConnection.Buys.Find(model.BuyID);
                Portfolio       portfolio  = DefaultConnection.Portfolios.Find(buy.PortfolioId);
                SailiRepository repository = new SailiRepository();
                Owner           owner      = new Owner();
                owner = repository.GetOwner(User.Identity.GetUserId());
                TraderAccount trader = new TraderAccount();
                trader = repository.GetTrader(owner.OwnerID);

                if (model.Quantity > buy.Quantity)
                {
                    TempData["SellException"] = "Selling more stocks than what is baught... Please try again";
                    return(RedirectToAction("ConfirmSell", new { tradingAccountID = portfolio.TradingAccountID, buyID = buy.BuyID }));
                }
                decimal transactionCost = (decimal)TransactionCost.SellCost * (model.Quantity * model.SoldPrice);
                model.PortfolioID       = portfolio.PortfolioID;
                model.TradeDate         = DateTime.Now;
                model.BuyID             = buy.BuyID;
                model.TransactionCost   = transactionCost;
                model.TransactionAmount = model.Quantity * model.SoldPrice - transactionCost;
                trader.Balance          = trader.Balance + model.TransactionAmount;
                buy.Quantity            = buy.Quantity - model.Quantity;
                TryUpdateModel(buy);
                DefaultConnection.Entry(buy).State = EntityState.Modified;
                DefaultConnection.SaveChanges();
                TryUpdateModel(trader);
                DefaultConnection.Entry(trader).State = EntityState.Modified;
                DefaultConnection.SaveChanges();
                TryUpdateModel(model);
                DefaultConnection.Sells.Add(model);
                DefaultConnection.SaveChanges();

                return(RedirectToAction("Details", "TraderAccount", new
                {
                    TradingAccountID = portfolio.TradingAccountID
                }));
            }
            catch
            {
                return(View(model));
            }
        }
        public ActionResult CheckStatusTrader(string OwnerID)
        {
            repository = new SailiRepository();
            TraderAccount trader = new TraderAccount();

            trader = repository.CheckTradingAccount(OwnerID);
            if (trader == null)
            {
                return(RedirectToAction("Create", new{
                    OwnerID = OwnerID
                }));
            }
            else
            {
                return(RedirectToAction("Details", "TraderAccount", new
                {
                    TradingAccountID = trader.TradingAccountID.ToString()
                }));
            }
        }
示例#6
0
        public ActionResult Create(Owner model)
        {
            bool check = false;

            if (model.FirstName == null)
            {
                check = true;
            }
            if (model.MiddleName == null)
            {
                check = true;
            }
            if (model.LastName == null)
            {
                check = true;
            }
            if (model.DOB == null)
            {
                check = true;
            }
            if (model.AddressNumber == null)
            {
                check = true;
            }
            if (model.AddressName == null)
            {
                check = true;
            }
            if (model.PostcodeID == null)
            {
                check = true;
            }
            if (check)
            {
                return(View(model));
            }


            char[]             delimiter         = { ',' };
            string[]           temp              = model.PostcodeID.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
            EncryptionServices encryptionService = new EncryptionServices();
            SailiRepository    repository        = new SailiRepository();
            Vector <Postcode>  Locality          = new Vector <Postcode>();

            model.UserID = User.Identity.GetUserId();
            model        = encryptionService.EncryptOwner(model);

            temp = repository.RemoveEmptyEntries(temp);
            string post = temp[0];

            Locality = repository.GetLocality(post);

            try
            {
                foreach (var item in Locality)
                {
                    if (item == null)
                    {
                        break;
                    }

                    if (item.postcode.Equals(temp[0].ToString()) &&
                        item.Locality.Equals(temp[1].ToString()))
                    {
                        model.PostcodeID = item.PostcodeID.ToString();
                    }
                }
                DefaultConnection.Owners.Add(new Owner()
                {
                    OwnerID       = model.OwnerID,
                    UserID        = model.UserID,
                    FirstName     = model.FirstName,
                    MiddleName    = model.MiddleName,
                    LastName      = model.LastName,
                    DOB           = model.DOB,
                    AddressNumber = model.AddressNumber,
                    AddressName   = model.AddressName,
                    PostcodeID    = model.PostcodeID
                });
                DefaultConnection.SaveChanges();


                return(RedirectToAction("CheckStatusTrader", "TraderAccount", new
                {
                    OwnerID = model.OwnerID.ToString()
                }));
            }
            catch
            {
                return(View(model));
            }
        }