public Investment GetInvestment(InvestmentViewModel investment) { return(_context.Investments .Include(i => i.Company) .Where(i => i.Company.Id.ToString() == investment.CompanyId) .SingleOrDefault(i => i.BankAccount.Id == investment.AccountId)); }
public async Task <IActionResult> Create(InvestmentViewModel model) { var user = await _userManager.GetUserAsync(User); var investment = new Investment { Amount = model.Investment.Amount, InvestmentTypeId = model.Investment.InvestmentTypeId, ProjectId = model.Project.Id, InvestorId = user.Id }; string regNo = _customizedId.InvestmentRegNo(model, user.Id); investment.InvestmentRegNo = regNo; _context.Investments.Add(investment); await _context.SaveChangesAsync(); var owner = _getProjectOwner.GetOwner(investment.ProjectId); var callbackUrl = Url.Page( "/Projects/Details", pageHandler: null, values: new { id = model.Project.Id }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(owner.Email, model.Project.Name, $"{user.Email} pledge {model.Investment.Amount} taka to {model.Project.Name}. Please contact with admin for more details. To see your project <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>"); return(RedirectToAction(nameof(ConfirmPayment))); }
// GET: Investment/Create public ActionResult Create() { var investment = new InvestmentViewModel(); //investment.FinancialYearFrom = DateTime.Now.Year; //investment.FinancialYearTo = DateTime.Now.Year; investment.PermitDate = DateTime.Now; investment.CapitalDetails = new List <CapitalDetail>(); investment.CapitalDetails.Add(new CapitalDetail { Description = "Cash" }); investment.CapitalDetails.Add(new CapitalDetail { Description = "Machinery" }); investment.CapitalDetails.Add(new CapitalDetail { Description = "Land Rental" }); investment.CapitalDetails.Add(new CapitalDetail { Description = "Utilities & Infrastructure" }); investment.CapitalDetails.Add(new CapitalDetail { Description = "Building" }); investment.CapitalDetails.Add(new CapitalDetail { Description = "Raw Material" }); investment.CapitalDetails = investment.CapitalDetails.OrderBy(cd => cd.Description).ToList(); return(View(investment)); }
public string InvestmentRegNo(InvestmentViewModel model, string userId) { string regNo = string.Empty; var user = _userManager.FindByIdAsync(userId); regNo += model.Project.Id.ToString() + model.Investment.Id.ToString(); return(regNo); }
public ActionResult ExampleCheckBoxListFor() { var viewModel = new InvestmentViewModel { InvestmentOptions = GetInvestmentOptions() }; viewModel.InvestmentOptions.First().IsChecked = true; return(View(viewModel)); }
public ActionResult ExampleCheckBoxListFor(InvestmentViewModel viewModel) { if (ModelState.IsValid) { var selectedOptions = viewModel.InvestmentOptions .Where(i => i.IsChecked).Select(i => i.Text); ViewBag.SelectedOptionsText = string.Join(", ", selectedOptions); } return(View(viewModel)); }
public ActionResult Create(InvestmentViewModel investment) { try { InvestmentRepository.InsertInvestment(investment, User.Identity.Name); return(RedirectToAction("Index")); } catch (Exception ex) { //throw ex; return(View(investment)); } }
public async Task <ActionResult <InvestmentViewModel> > Post( [FromBody] InvestmentViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _investimentRepository.Create(_mapper.Map <Investment>(model)); return(model); }
public ActionResult Buy(InvestmentViewModel investment) { if (!ModelState.IsValid) { return(View("InvestmentForm", investment)); } var currentInvestment = _unitOfWork.Investment.GetInvestment(investment); var account = _unitOfWork.BankAccount.GetBankAccountById(investment.AccountId); var company = _unitOfWork.Company.GetCompanyById(int.Parse(investment.CompanyId)); Transaction transaction; if (account == null) { return(HttpNotFound()); } if (currentInvestment == null) { var newInvestment = new Investment(account, company); newInvestment.CalculateNewInvestmentAmount(investment.SharePrice, investment.ShareQuantity); newInvestment.DecreaseInvestmentCostToBankAccount(account); //account.IncreaseBankAccountBalance(investmentAmount); _unitOfWork.Investment.AddInvestment(newInvestment); transaction = _log.LogTransaction(TransactionType.Buy, newInvestment); } else { currentInvestment.CalCurrentInvestmentAmountAndShareQuantity(investment.SharePrice, investment.ShareQuantity, investment.Type); account.DecreaseBankAccountBalance(investment.SharePrice * investment.ShareQuantity); transaction = _log.LogTransaction(TransactionType.Buy, currentInvestment); } if (!account.CheckBalanceGreaterThanZero()) { return(Json(new { success = false, responseText = "Account Balance Too Low " }, JsonRequestBehavior.AllowGet)); } _unitOfWork.Transaction.AddTransaction(transaction); _unitOfWork.Complete(); return(Json(new { success = true, responseText = "Share Purchase Was Successfull" }, JsonRequestBehavior.AllowGet)); // var viewModel = new InvestmentViewModel(currentInvestment) {Type = TransactionType.Buy}; // return View("InvestmentForm", investment); }
public async Task <IActionResult> Create(int id) { var project = await _context.Projects.FindAsync(id); var investmentTypes = await _context.investmentTypes.Where(x => x.ProjectId == id).ToListAsync(); var investmentViewModel = new InvestmentViewModel { Project = project, InvestmentTypes = investmentTypes }; return(View(investmentViewModel)); }
// GET: Fundeds/Create public IActionResult Create(InvestmentViewModel model) { var userId = _userManager.GetUserId(HttpContext.User); var funded = new Funded { ProjectId = model.Project.Id, InvestorId = userId, Amount = model.Investment.Amount }; return(View()); }
public ActionResult Edit(InvestmentViewModel investment) { try { // TODO: Add update logic here InvestmentRepository.UpdateInvestment(investment, User.Identity.Name); return(RedirectToAction("Index")); } catch (Exception ex) { throw ex; return(View(investment)); } }
public ActionResult Sell(InvestmentViewModel investment) { var currentInvestment = _unitOfWork.Investment.GetInvestment(investment); var account = _unitOfWork.BankAccount.GetBankAccountById(investment.AccountId); if ((currentInvestment == null) || (account == null)) { return(HttpNotFound()); } if (investment.ShareQuantity > investment.CurrentShareQuantity) { return(Json(new { success = false, responseText = "Share Quantity Too High" }, JsonRequestBehavior.AllowGet)); } currentInvestment.CalCurrentInvestmentAmountAndShareQuantity(investment.SharePrice, investment.ShareQuantity, investment.Type); account.IncreaseBankAccountBalance(investment.SharePrice * investment.ShareQuantity); //currentInvestment.AddInvestmentSaleToBankAccount(account); var transaction = _log.LogTransaction(TransactionType.Sell, currentInvestment); if (currentInvestment.ShareQuantity == 0) { _unitOfWork.Investment.RemoveInvestment(currentInvestment); } _unitOfWork.Transaction.AddTransaction(transaction); _unitOfWork.Complete(); return(Json(new { success = true, responseText = "Share Sale Was Successfull" }, JsonRequestBehavior.AllowGet)); //var model = new InvestmentViewModel(currentInvestment) {Type = TransactionType.Sell}; //return View("InvestmentForm", model); }
public HttpResponseMessage GetInvestment(int id) { var response = new InvestmentViewModel(); try { response = GetStaticInvestmentList().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)); } }
public static void InsertInvestment(InvestmentViewModel investmentViewModel, string userName) { using (var db = new ApplicationDbContext()) { var investorAddress = investmentViewModel.InvestorAddress; investorAddress.UID = Guid.NewGuid(); var organizationAddress = investmentViewModel.OrganizationAddress; organizationAddress.UID = Guid.NewGuid(); var investmentPermittedAddress = investmentViewModel.InvestmentPermittedAddress; investmentPermittedAddress.UID = Guid.NewGuid(); TimeZone time2 = TimeZone.CurrentTimeZone; DateTime test = time2.ToUniversalTime(DateTime.Now); var yangone = TimeZoneInfo.FindSystemTimeZoneById("Myanmar Standard Time"); var yangoneTime = TimeZoneInfo.ConvertTimeFromUtc(test, yangone); var investment = Mapper.Map <InvestmentViewModel, Investment>(investmentViewModel); investment.UID = Guid.NewGuid(); investment.CreatedBy = userName; investment.CreatedOn = yangoneTime; investment.InvestorAddressId = investorAddress.UID; investment.OrganizationAddressId = organizationAddress.UID; investment.InvestmentPermittedAddressId = investmentPermittedAddress.UID; investment.EnvironmentandSocialImpactAssessment = string.Join(",", investmentViewModel.EnvironmentandSocialImpactAssessment); db.Addresses.Add(investorAddress); db.Addresses.Add(organizationAddress); db.Addresses.Add(investmentPermittedAddress); db.Investments.Add(investment); if (investmentViewModel.FormofInvestment.Equals("JV")) { if (investmentViewModel.JointVenturePercentages != null && investmentViewModel.JointVenturePercentages.Count > 0) { foreach (JointVenturePercentage jv in investmentViewModel.JointVenturePercentages) { if (!string.IsNullOrEmpty(jv.CompanyName)) { jv.UID = Guid.NewGuid(); jv.InvestmentId = investment.UID; db.JointVenturePercentages.Add(jv); } } } } if (investmentViewModel.Taxes != null && investmentViewModel.Taxes.Count > 0) { foreach (Tax tax in investmentViewModel.Taxes) { tax.UID = Guid.NewGuid(); tax.InvestmentId = investment.UID; db.Taxes.Add(tax); } } if (investmentViewModel.CapitalDetails != null && investmentViewModel.CapitalDetails.Count > 0) { foreach (CapitalDetail cd in investmentViewModel.CapitalDetails) { cd.UID = Guid.NewGuid(); cd.InvestmentId = investment.UID; db.CapitalDetails.Add(cd); } } db.SaveChanges(); } }
public Company GetCompany(InvestmentViewModel investment) { return(_context.Companies.SingleOrDefault(c => c.Id.ToString() == investment.CompanyId)); }
public static void UpdateInvestment(InvestmentViewModel investmentViewModel, string userName) { TimeZone time2 = TimeZone.CurrentTimeZone; DateTime test = time2.ToUniversalTime(DateTime.Now); var yangone = TimeZoneInfo.FindSystemTimeZoneById("Myanmar Standard Time"); var yangoneTime = TimeZoneInfo.ConvertTimeFromUtc(test, yangone); using (var db = new ApplicationDbContext()) { var investment = db.Investments.FirstOrDefault(i => i.UID == investmentViewModel.UID); investment.TypeOfInvestment = investmentViewModel.TypeOfInvestment; investment.InvestorName = investmentViewModel.InvestorName; investment.Citizenship = investmentViewModel.Citizenship; investment.InvestorAddressId = investmentViewModel.InvestorAddress.UID; investment.OrganizationName = investmentViewModel.OrganizationName; investment.OrganizationAddressId = investmentViewModel.OrganizationAddress.UID; investment.IncorporationPlace = investmentViewModel.IncorporationPlace; investment.BusinessType = investmentViewModel.BusinessType; investment.InvestmentPermittedAddressId = investmentViewModel.InvestmentPermittedAddress.UID; investment.AmountofForeignCapital = investmentViewModel.AmountofForeignCapital; investment.PeriodforForeignCapitalBroughtin = investmentViewModel.PeriodforForeignCapitalBroughtin; investment.PeriodforForeignCapitalBroughtinType = investmentViewModel.PeriodforForeignCapitalBroughtinType; investment.TotalAmountofCapital = investmentViewModel.TotalAmountofCapital; investment.CapitalCurrency = investmentViewModel.CapitalCurrency; investment.ConstructionPeriod = investmentViewModel.ConstructionPeriod; investment.ConstructionPeriodType = investmentViewModel.ConstructionPeriodType; investment.ValidityofInvestmentPermit = investmentViewModel.ValidityofInvestmentPermit; investment.ValidityofInvestmentPermitPeriodType = investmentViewModel.ValidityofInvestmentPermitPeriodType; investment.FormofInvestment = investmentViewModel.FormofInvestment; investment.CompanyNameinMyanmar = investmentViewModel.CompanyNameinMyanmar; investment.PermitNo = investmentViewModel.PermitNo; investment.PermitDate = investmentViewModel.PermitDate; investment.Sector = investmentViewModel.Sector; investment.SectorCategory = investmentViewModel.SectorCategory; investment.InvestingCountry = investmentViewModel.InvestingCountry; investment.Landowner = investmentViewModel.Landowner; investment.LandArea = investmentViewModel.LandArea; investment.LandAreaUnit = investmentViewModel.LandAreaUnit; investment.LeaseTerm = investmentViewModel.LeaseTerm; investment.ExtendedLeaseTerm = investmentViewModel.ExtendedLeaseTerm; investment.AnnualLeaseFee = investmentViewModel.AnnualLeaseFee; investment.AnnualLeaseFeeCurrency = investmentViewModel.AnnualLeaseFeeCurrency; investment.TotalNoofForeignEmployee = investmentViewModel.TotalNoofForeignEmployee; investment.TotalNoofLocalEmployee = investmentViewModel.TotalNoofLocalEmployee; investment.CorporateSocialResponsibility = investmentViewModel.CorporateSocialResponsibility; investment.EnvironmentandSocialImpactAssessment = string.Join(",", investmentViewModel.EnvironmentandSocialImpactAssessment); investment.ModifiedBy = userName; investment.ModifiedOn = yangoneTime; investment.Note = investmentViewModel.Note; investment.LandUsePremium = investmentViewModel.LandUsePremium; investment.LandUsePreminumCurrency = investmentViewModel.LandUsePreminumCurrency; db.Addresses.Attach(investmentViewModel.InvestorAddress); db.Entry(investmentViewModel.InvestorAddress).State = EntityState.Modified; db.Addresses.Attach(investmentViewModel.OrganizationAddress); db.Entry(investmentViewModel.OrganizationAddress).State = EntityState.Modified; db.Addresses.Attach(investmentViewModel.InvestmentPermittedAddress); db.Entry(investmentViewModel.InvestmentPermittedAddress).State = EntityState.Modified; db.Investments.Attach(investment); db.Entry(investment).State = EntityState.Modified; db.JointVenturePercentages.RemoveRange(db.JointVenturePercentages.Where(x => x.InvestmentId == investment.UID)); if (investmentViewModel.FormofInvestment.Equals("JV")) { if (investmentViewModel.JointVenturePercentages != null && investmentViewModel.JointVenturePercentages.Count > 0) { foreach (JointVenturePercentage jv in investmentViewModel.JointVenturePercentages) { if (!string.IsNullOrEmpty(jv.CompanyName)) { jv.UID = Guid.NewGuid(); jv.InvestmentId = investment.UID; db.JointVenturePercentages.Add(jv); } } } } db.Taxes.RemoveRange(db.Taxes.Where(x => x.InvestmentId == investment.UID)); if (investmentViewModel.Taxes != null && investmentViewModel.Taxes.Count > 0) { foreach (Tax tax in investmentViewModel.Taxes) { tax.UID = Guid.NewGuid(); tax.InvestmentId = investment.UID; db.Taxes.Add(tax); } } db.CapitalDetails.RemoveRange(db.CapitalDetails.Where(x => x.InvestmentId == investment.UID)); if (investmentViewModel.CapitalDetails != null && investmentViewModel.CapitalDetails.Count > 0) { foreach (CapitalDetail cd in investmentViewModel.CapitalDetails) { cd.UID = Guid.NewGuid(); cd.InvestmentId = investment.UID; db.CapitalDetails.Add(cd); } } db.SaveChanges(); } }
public List <ChartsViewModel.PieViewModel> GetPieReport(string lang, int[] years, int[] quarters, List <string> headers) { var finalResult = new List <ChartsViewModel.PieViewModel>(); //add total quarter if no quarters exist if (quarters.Length < 1) { quarters = new int[1] { (int)DFQuarterEnum.Total } } ; var resultData = GetReportResult(years, quarters).FirstOrDefault(); var resultView = new InvestmentViewModel(); List <DFGDP> headersData; List <List <object> > dataRows = new List <List <object> >(); resultView = new InvestmentViewModel() { //multiply values to million to be as their unit AccommodationAndFoodServiceActivities = resultData.AccommodationAndFoodServiceActivities, Agriculture = resultData.Agriculture, Construction = resultData.Construction, Education = resultData.Education, Electricity = resultData.Electricity, FinancialIntermediaryInsuranceAndSocialSecurity = resultData.FinancialIntermediaryInsuranceAndSocialSecurity, Health = resultData.Health, InformationAndCommunication = resultData.InformationAndCommunication, NaturalGas = resultData.NaturalGas, OtherExtractions = resultData.OtherExtractions, OtherManufacturing = resultData.OtherManufacturing, OtherSrvices = resultData.OtherSrvices, Petroleum = resultData.Petroleum, PetroleumRefining = resultData.PetroleumRefining, RealEstateActivities = resultData.RealEstateActivities, StorageAndTransportation = resultData.StorageAndTransportation, SuezCanal = resultData.SuezCanal, TotalInvestments = resultData.TotalInvestments, WaterAndSewerage = resultData.WaterAndSewerage, WholesaleAndRetailTrade = resultData.WholesaleAndRetailTrade, }; if (lang == null || lang.ToLower() == "ar") { headersData = _db.DFGDP.Where(x => (headers.Contains(x.NameAr)) && x.Type == 3).OrderBy(x => x.order).ToList(); //if only one selected compare it with the others if (headersData.Count == 1) { var allOtherHeaders = _db.DFGDP.Where(x => !x.IsBasic && !headers.Contains(x.NameAr) && x.Type == (int)ReportEnum.Investment); double otherHeadersValue = 0; foreach (var otherHeader in allOtherHeaders) { var val = new object(); val = resultView.GetType().GetProperty(otherHeader.Name).GetValue(resultView, null); var numFlag = double.TryParse("" + val, out double num); num = Math.Round(num, 2); otherHeadersValue += numFlag ? num : 0; } var resultItem = new ChartsViewModel.PieViewModel("الباقي", otherHeadersValue); finalResult.Add(resultItem); var val2 = new object(); val2 = resultView.GetType().GetProperty(headersData[0].Name).GetValue(resultView, null); var numFlag2 = double.TryParse("" + val2, out double num2); num2 = Math.Round(num2, 2); var resultItem2 = new ChartsViewModel.PieViewModel(headersData[0].NameAr, numFlag2 ? num2 : 0); finalResult.Add(resultItem2); } else { foreach (var header in headersData) { var val = new object(); val = resultView.GetType().GetProperty(header.Name).GetValue(resultView, null); var numFlag = double.TryParse("" + val, out double num); num = Math.Round(num, 2); var resultItem = new ChartsViewModel.PieViewModel(header.NameAr, numFlag ? num : 0); finalResult.Add(resultItem); } } } else { headersData = _db.DFGDP.Where(x => (headers.Contains(x.NameEn)) && x.Type == 3).OrderBy(x => x.order).ToList(); //if only one selected compare it with the others if (headersData.Count == 1) { var allOtherHeaders = _db.DFGDP.Where(x => !x.IsBasic && !headers.Contains(x.NameEn) && x.Type == (int)ReportEnum.Investment); double otherHeadersValue = 0; foreach (var otherHeader in allOtherHeaders) { var val = new object(); val = resultView.GetType().GetProperty(otherHeader.Name).GetValue(resultView, null); var numFlag = double.TryParse("" + val, out double num); num = Math.Round(num, 2); otherHeadersValue += numFlag ? num : 0; } var resultItem = new ChartsViewModel.PieViewModel("Others", otherHeadersValue); finalResult.Add(resultItem); var val2 = new object(); val2 = resultView.GetType().GetProperty(headersData[0].Name).GetValue(resultView, null); var numFlag2 = double.TryParse("" + val2, out double num2); num2 = Math.Round(num2, 2); var resultItem2 = new ChartsViewModel.PieViewModel(headersData[0].NameEn, numFlag2 ? num2 : 0); finalResult.Add(resultItem2); } else { foreach (var header in headersData) { var val = new object(); val = resultView.GetType().GetProperty(header.Name).GetValue(resultView, null); var numFlag = double.TryParse("" + val, out double num); num = Math.Round(num, 2); var resultItem = new ChartsViewModel.PieViewModel(header.NameEn, numFlag ? num : 0); finalResult.Add(resultItem); } } } return(finalResult); }
// GET: Investment/Details/5 public ActionResult Details(Guid id) { InvestmentViewModel investment = InvestmentRepository.GetInvestment(id); return(View(investment)); }