public async Task <IActionResult> ShareholderPairs(PortfoViewModel model) { var portfo = await _portfoRepository.GetByIDAsync(model.Id); portfo.AggregatePercentage = model.AggregatePercentage; await _portfoRepository.UpdateAsync(portfo); var result = await _portfoShareholderPairRepository.DeleteAllAsync(x => x.PortfoId == model.Id); var items = model.PortfoShareholderPairs.Where(x => x.Pair != null).Select(x => new PortfoShareholderPair { PortfoId = model.Id, AddedDate = DateTime.Now, CompanyId = int.Parse(x.Pair.Split('-')[0]), ShareholderId = int.Parse(x.Pair.Split('-')[1]), Row = x.Row, Column = 0, }).ToList(); await _portfoShareholderPairRepository.InsertAllAsync(items); ErrorMessage = Resources.Messages.ChangesSavedSuccessfully; if (Request.Form.Keys.Contains("SaveAndReturn")) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", new { id = model.Id })); } }
public IActionResult Edit(int id) { HttpContext.Session.SetString("portfoId", id.ToString()); PortfoViewModel model = getPortfo(id); return(View(model)); }
private PortfoViewModel getPortfo(int id) { var item = _portfoRepository.GetAsQueryable(x => x.Id == id, includeProperties: "Company.CompanyType,PortfoShareholderPairs").FirstOrDefault(); PortfoViewModel model = _mapper.Map <Portfo, PortfoViewModel>(item); model.CurrentCapital = _companyShareRepository.GetAsQueryable(x => x.CompanyId == item.CompanyId) .OrderByDescending(x => x.Id).Select(x => x.CurrentCapital).FirstOrDefault(); model.CompanyTypeTitle = item.Company.CompanyType.Title; //&& x.ShareholderId == 47 && x.CompanyId == 19 //var shareholderList = _companyShareholderRepository.GetAsQueryable(x => x.IncludeInFormula).GroupBy(woak => new { woak.CompanyId, woak.ShareholderId }).Select(g => g.OrderByDescending(c => c.Id).FirstOrDefault()).ToList(); var shareholderList = _companyShareholderRepository.GetAsQueryableGroupBy(woak => new { woak.CompanyId, woak.ShareholderId }, x => x.IncludeInFormula).Select(g => g.OrderByDescending(c => c.Id).FirstOrDefault()).ToList(); var allPossibleShareholders = shareholderList.Join(_companyRepository.GetAll(), a => a.CompanyId, b => b.Id, (a, b) => new { companiesShare = a, companies = b }).Join(_shareholderRepository.GetAll(), a => a.companiesShare.ShareholderId, b => b.Id, (a, b) => new { companiesShare2 = a, shares = b }).ToList(); List <CompanyShareholderViewModel> fakes = new List <CompanyShareholderViewModel>(); foreach (var woak in allPossibleShareholders) { //x => x.CompanyId == item.CompanyId && x.FormStatusFilter == KavoshFrameWorkCore.FormStatus.Verified).OrderByDescending(x => x.Date) var companyShare = _companyShareRepository .GetAsQueryable(x => x.CompanyId == woak.companiesShare2.companiesShare.CompanyId && x.FormStatus == KavoshFrameWorkCore.FormStatus.Verified).OrderByDescending(x => x.Date).FirstOrDefault(); if (companyShare != null) { var capitalChangePercentage = 100 * ((companyShare.CurrentCapital - companyShare.PreviousCapital) / (double)companyShare.PreviousCapital); var totalShare = companyShare.PreviousShares * (1 + (capitalChangePercentage) / 100); var ownershipPercentage = (woak.companiesShare2.companiesShare.Shares / totalShare) * 100; var sh = new CompanyShareholderViewModel { CompanyId = woak.companiesShare2.companiesShare.CompanyId, CompanyTitle = woak.companiesShare2.companies.Title, ShareholderTitle = woak.shares.Title, IsMainShareholder = woak.companiesShare2.companiesShare.IsMainShareholder, ShareholderId = woak.companiesShare2.companiesShare.ShareholderId, OwnershipPercentage = ownershipPercentage, }; fakes.Add(sh); } } var items = new List <KeyValueViewModel>(); foreach (var fake in fakes) { items.Add(new KeyValueViewModel { Key = fake.CompanyId + "-" + fake.ShareholderId, Value = fake.ShareholderTitle + " در " + fake.CompanyTitle + " (" + Math.Round((fake.OwnershipPercentage / 100), 2) + ")" }); } model.ValidShareholderTreeNodes = items; return(model); }
public async Task <IActionResult> Create(PortfoViewModel model) { model.SystemUserId = UserId; if (ModelState.IsValid) { var item = _mapper.Map <PortfoViewModel, Portfo>(model); await _portfoRepository.InsertAsync(item); ErrorMessage = Resources.Messages.ChangesSavedSuccessfully; if (Request.Form.Keys.Contains("SaveAndReturn")) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", new { id = item.Id })); } } return(View(model)); }
private List <PortfoResult> getPortfo2(int id) { var item = _portfoRepository.GetAsQueryable(x => x.Id == id, includeProperties: "Company.CompanyType,PortfoShareholderPairs").FirstOrDefault(); PortfoViewModel model = _mapper.Map <Portfo, PortfoViewModel>(item); model.CurrentCapital = _companyShareRepository.GetAsQueryable(x => x.CompanyId == item.CompanyId) .OrderByDescending(x => x.Id).Select(x => x.CurrentCapital).FirstOrDefault(); model.CompanyTypeTitle = item.Company.CompanyType.Title; //var shareholderList = _companyShareholderRepository.GetAsQueryable(x => x.IncludeInFormula).GroupBy(woak => new { woak.CompanyId, woak.ShareholderId }).Select(g => g.OrderByDescending(c => c.Id).FirstOrDefault()).ToList(); var shareholderList = _companyShareholderRepository.GetAsQueryableGroupBy(woak => new { woak.CompanyId, woak.ShareholderId }, x => x.IncludeInFormula).Select(g => g.OrderByDescending(c => c.Id).FirstOrDefault()).ToList(); var companies = _companyRepository.GetAll(); var shareholders = _shareholderRepository.GetAll(); var portfoShareholders = _portfoShareholderPairRepository.GetAsQueryable(woak => woak.PortfoId == id).OrderBy(p => p.Row).ToList(); var allPossibleShareholders = portfoShareholders.Join(shareholderList, a => new { a.CompanyId, a.ShareholderId }, b => new { b.CompanyId, b.ShareholderId }, (a, b) => new { portfo = a, companiesShare = b }).Join(companies, a => a.companiesShare.CompanyId, b => b.Id, (a, b) => new { companiesShare = a, companies = b }).Join(shareholders, a => a.companiesShare.companiesShare.ShareholderId, b => b.Id, (a, b) => new { companiesShare2 = a, shares = b }).ToList(); List <CompanyShareholderViewModel> fakes = new List <CompanyShareholderViewModel>(); foreach (var woak in allPossibleShareholders) { var companyShare = _companyShareRepository .GetAsQueryable(x => x.CompanyId == woak.companiesShare2.companiesShare.companiesShare.CompanyId && x.FormStatus == KavoshFrameWorkCore.FormStatus.Verified).OrderByDescending(x => x.Date).FirstOrDefault(); if (companyShare != null) { var capitalChangePercentage = 100 * ((companyShare.CurrentCapital - companyShare.PreviousCapital) / (double)companyShare.PreviousCapital); var totalShare = companyShare.PreviousShares * (1 + (capitalChangePercentage) / 100); var ownershipPercentage = (woak.companiesShare2.companiesShare.companiesShare.Shares / totalShare); var sh = new CompanyShareholderViewModel { Id = woak.companiesShare2.companiesShare.portfo.Id, CompanyId = woak.companiesShare2.companiesShare.companiesShare.CompanyId, CompanyTitle = woak.companiesShare2.companies.Title, ShareholderTitle = woak.shares.Title, IsMainShareholder = woak.companiesShare2.companiesShare.companiesShare.IsMainShareholder, ShareholderId = woak.companiesShare2.companiesShare.companiesShare.ShareholderId, OwnershipPercentage = ownershipPercentage, Row = woak.companiesShare2.companiesShare.portfo.Row }; fakes.Add(sh); } } List <PortfoResult> bitPush = new List <PortfoResult>(); double total = 0; IEnumerable <IGrouping <int, CompanyShareholderViewModel> > group = fakes.GroupBy(woak => woak.Row); foreach (IGrouping <int, CompanyShareholderViewModel> woak in group) { int row = woak.Key; string id1 = string.Empty; string title = string.Empty; string value = string.Empty; double sum = 1; foreach (var put in woak) { id1 += put.Id; string strVal = String.Format("{0:.##}", (put.OwnershipPercentage * 100)); title += put.ShareholderTitle + " در " + put.CompanyTitle + "(" + strVal + ")>> " + "<a class='btn btn-sm btn-danger' onclick='deletePortfo2(" + put.Id + ")'>x</a>" + " "; value += Math.Round((put.OwnershipPercentage / 100), 2).ToString() + "-"; sum *= (put.OwnershipPercentage); } id1 = id1.Remove(id1.Length - 1); //title = title.Remove(title.Length - 1);2345 value = value.Remove(value.Length - 1); total += sum; string strSum = String.Format("{0:.##}", sum * 100); string strTotla = String.Format("{0:.##}", total); bitPush.Add(new PortfoResult { Id = id1, Title = title, Value = value, Sum = strSum == "" ? "0" : strSum, Total = strTotla, Row = row }); } item.AggregatePercentage = total; int update = _portfoRepository.Update(item); return(bitPush); }