public ActionResult Activate([FromBody] InvestorViewModel model)
        {
            var investor = dbContext.Investors.FirstOrDefault(p => p.Id == model.Id);

            if (investor != null)
            {
                investor.Status = Status.Active;
                investor.Date   = DateTime.ParseExact(model.Date, "d/M/yyyy", CultureInfo.InvariantCulture);
                //investor.DeactivateDate = DateTime.ParseExact(model.DeactivateDate, "d/M/yyyy", CultureInfo.InvariantCulture); ;
                investor.SharesBurned   = 0;
                investor.AmountReturned = 0;
                investor.AmountInvested = model.AmountInvested;
                investor.SharesReceived = model.SharesReceived;
                var list = JsonConvert.DeserializeObject <List <DateTime> >(investor.JsonDateList);
                list.Add(investor.Date);
                investor.JsonDateList = JsonConvert.SerializeObject(list);
                dbContext.Investors.Update(investor);

                var usd = dbContext.Assets.FirstOrDefault(a => a.Name == "USD");
                if (usd != null)
                {
                    usd.Quantity += investor.AmountInvested;
                    dbContext.Assets.Update(usd);
                }

                dbContext.SaveChanges();
            }
            return(this.Json(new MetaResponse <object> {
                StatusCode = 200
            }));
        }
Beispiel #2
0
        public IActionResult Create(InvestorViewModel investor)
        {
            if (ModelState.IsValid)
            {
                Investor investorObj = new Investor()
                {
                    CompanyName   = investor.CompanyName,
                    InvestorName  = investor.InvestorName,
                    Email         = investor.Email,
                    LandPhone     = investor.LandPhone,
                    Mobile        = investor.Mobile,
                    Address       = investor.Address,
                    HasCommission = investor.HasCommission,
                };

                _work.Investor.Add(investorObj);

                bool isSaved = _work.Save() > 0;

                if (isSaved)
                {
                    return(Json(true));
                }
            }
            return(Json(false));
        }
Beispiel #3
0
        public IActionResult EditView(int id)
        {
            var investor = _work.Investor.Get(id);
            InvestorViewModel investorViewModel = new InvestorViewModel();

            investorViewModel.CompanyName   = investor.CompanyName;
            investorViewModel.InvestorName  = investor.InvestorName;
            investorViewModel.Email         = investor.Email;
            investorViewModel.LandPhone     = investor.LandPhone;
            investorViewModel.Mobile        = investor.Mobile;
            investorViewModel.Address       = investor.Address;
            investorViewModel.HasCommission = investor.HasCommission;
            return(PartialView("_EditView", investorViewModel));
        }
        public async Task <IActionResult> GetUserInfo(Guid id)
        {
            var investor = await Context.Investors
                           .AsNoTracking()
                           .Include(i => i.Fundings)
                           .ThenInclude(f => f.Project)
                           .SingleOrDefaultAsync(i => i.Id == id);

            if (investor == null)
            {
                return(NotFound($"Investor not found with id: {id}"));
            }
            return(Ok(InvestorViewModel.GetFrom(investor)));
        }
Beispiel #5
0
 public Investor(InvestorViewModel viewModel)
 {
     Id                 = viewModel.Id;
     Status             = viewModel.Status;
     Name               = viewModel.Name;
     Date               = DateTime.ParseExact(viewModel.Date, "d/M/yyyy", CultureInfo.InvariantCulture);;
     HistoricalDateList = new List <DateTime> {
         Date
     };
     HistoricalDeactivateDateList = new List <DateTime>();
     JsonDateList           = JsonConvert.SerializeObject(HistoricalDateList);
     JsonDeactivateDateList = JsonConvert.SerializeObject(HistoricalDeactivateDateList);
     Agreement      = viewModel.Agreement;
     AmountInvested = viewModel.AmountInvested;
     AmountReturned = 0;
     SharesReceived = viewModel.SharesReceived;
     SharesBurned   = 0;
 }
        public IActionResult Info(long?id)
        {
            var model    = new InvestorViewModel();
            var investor = dbContext.Investors.FirstOrDefault(p => p.Id == id);

            if (investor != null)
            {
                model.Id                           = investor.Id;
                model.Status                       = investor.Status;
                model.Name                         = investor.Name;
                model.Date                         = investor.Date.ToString();
                model.DeactivateDate               = investor.DeactivateDate.ToString();
                model.HistoricalDateList           = JsonConvert.DeserializeObject <List <DateTime> >(investor.JsonDateList);
                model.HistoricalDeactivateDateList = JsonConvert.DeserializeObject <List <DateTime> >(investor.JsonDeactivateDateList);
                model.Agreement                    = investor.Agreement;
                model.AmountInvested               = investor.AmountInvested;
                model.SharesReceived               = investor.SharesReceived;
            }
            return(PartialView("Info", model));
        }
Beispiel #7
0
        public HttpResponseMessage GetInvestor(int id)
        {
            var response = new InvestorViewModel();

            try
            {
                response = GetStaticInvestorsList().Find(i => i.Id == id);
                if (response == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, response));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Beispiel #8
0
        public IActionResult Edit(InvestorViewModel investor)
        {
            var investorObj = _work.Investor.Get(investor.Id);

            if (ModelState.IsValid)
            {
                // investorObj.Id = investor.Id;
                investorObj.CompanyName   = investor.CompanyName;
                investorObj.InvestorName  = investor.InvestorName;
                investorObj.Email         = investor.Email;
                investorObj.LandPhone     = investor.LandPhone;
                investorObj.Mobile        = investor.Mobile;
                investorObj.Address       = investor.Address;
                investorObj.HasCommission = investor.HasCommission;
            }
            _work.Investor.Update(investorObj);
            bool isUpdate = _work.Save() > 0;

            if (isUpdate)
            {
                return(Json(true));
            }
            return(Json(false));
        }
Beispiel #9
0
        public HttpResponseMessage PostHoldings([FromBody] InvestorViewModel value)
        {
            var investors   = GetStaticInvestorsList();
            var investments = GetStaticInvestmentList();

            try
            {
                if (!investors.Any(i => i.Id == value.Id))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Invalid investor id: {value.Id}"));
                }
                if (value.Accounts == null || !value.Accounts.Any())
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, $"No investor accounts found."));
                }

                var investor = investors.Find(i => i.Id == value.Id);

                if (!investor.Accounts.Any(i => i.Id == value.Accounts[0].Id))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Invalid investor account. Investor id: {value.Id} does not contain account id: {value.Accounts[0].Id}"));
                }

                var account = investor.Accounts.Find(i => i.Id == value.Accounts[0].Id);

                if (value.Accounts[0].Holdings == null || !value.Accounts[0].Holdings.Any())
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, $"No investor account holdings found."));
                }

                var cash = account.AvailableCash;
                foreach (var holding in value.Accounts[0].Holdings)
                {
                    if (!investments.Any(i => i.InvestmentCode == holding.InvestmentCode))
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Invalid investment code: {holding.InvestmentCode}"));
                    }
                    var investment = investments.Find(i => i.InvestmentCode == holding.InvestmentCode);
                    if (investment.Currency != account.LocalCurrency)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Investment '{investment.InvestmentCode}' currency code '{investment.Currency}' does not match accounts local currency code '{account.LocalCurrency}'."));
                    }
                    if (holding.PurchaseDateUtc == null)
                    {
                        holding.PurchaseDateUtc = DateTime.UtcNow;
                    }

                    holding.Id    = investment.Id;
                    holding.Price = investment.Price;
                    cash          = cash - holding.Units * investment.Price;
                    if (cash < 0.0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Account '{account.AccountCode}' does not have enough available cash for the account holdings. Over by {Math.Abs(cash)}"));
                    }
                }

                for (var i = 0; i < investor.Accounts.Count; i++)
                {
                    if (investor.Accounts[i].Id == account.Id)
                    {
                        account.Holdings     = value.Accounts[0].Holdings;
                        investor.Accounts[i] = account;
                        break;
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, investor));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public ActionResult UpdateInvestment(InvestorViewModel viewModel, FormCollection formCollection)
        {
            var operation = formCollection["oper"];
            if (operation.Equals("edit"))
            {
                var investment = _context.Investments.Include("UserProfile").FirstOrDefault(p => p.Id == viewModel.InvestmentId);
                if (investment != null)
                {
                    investment.UserProfile.LastName = viewModel.LastName;
                    investment.UserProfile.Email = viewModel.Email;
                    investment.DateOfInvestment = viewModel.DateOfInvestment;
                    investment.InvestedAmount = viewModel.InvestedAmount;
                    investment.Maturity = viewModel.Maturity;
                    investment.FinalAmount = viewModel.FinalAmount;
                    investment.Rate = viewModel.Rate;
                }
                _context.SaveChanges();
            }
            else if (operation.Equals("del"))
            {
                var investment = _context.Investments.Include("UserProfile").FirstOrDefault(p => p.Id == viewModel.InvestmentId);
                if (investment != null)
                {
                    investment.IsActive = false;
                }
                _context.SaveChanges();
            }

            return null; //Content(repository.HasErrors.ToString().ToLower());
        }
        public async Task <ActionResult> InsertInvestor([FromBody] InvestorViewModel viewModel)
        {
            try
            {
                var investor = new Investor(viewModel);
                var invCnt   = dbContext.Investors.Count();
                dbContext.Investors.Add(investor);
                var usd = dbContext.Assets.FirstOrDefault(a => a.Name == "USD");
                if (usd != null)
                {
                    usd.Quantity += investor.AmountInvested;
                    dbContext.Assets.Update(usd);

                    if (invCnt == 0)
                    {
                        var time = DateTime.Now;
                        var nav  = new NavHistory
                        {
                            Date  = time,
                            Value = usd.Quantity / investor.SharesReceived
                        };

                        var rate = await coinApi.GetCurrencyRateToUsd("BTC");

                        var btc = new BtcHistory
                        {
                            Date  = time,
                            Value = rate.Rate
                        };

                        dbContext.NavHistories.Add(nav);
                        dbContext.BtcHistories.Add(btc);

                        //if (!dbContext.Assets.ToList().Exists(a => a.ShortName == "BTC"))
                        //{
                        //    try
                        //    {
                        //        var rate = await coinApi.GetCurrencyRateToUsd("BTC");
                        //        var currency = dbContext.Currencies.FirstOrDefault(c => c.ShortName == "BTC");
                        //        if (currency != null)
                        //        {
                        //            currency.Rate = rate.Rate;
                        //            dbContext.Currencies.Update(currency);
                        //        }
                        //        dbContext.CurrencyRates.Add(rate);
                        //    }
                        //    catch (Exception e)
                        //    {
                        //        Console.WriteLine(e);
                        //    }
                        //}
                    }
                }

                dbContext.SaveChanges();
                return(this.Json(new MetaResponse <object> {
                    StatusCode = 200
                }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(this.Json(new MetaResponse <object> {
                    StatusCode = 200
                }));
            }
        }
Beispiel #12
0
        public IActionResult CreateView()
        {
            InvestorViewModel investor = new InvestorViewModel();

            return(PartialView("_CreateView", investor));
        }