Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult GetMiningLedger(int UserId, bool IncludeAlts)
- {
- using (EHRContext _Context = new EHRContext())
- {
- LedgerViewModel model = new LedgerViewModel();
- APIHelper api = new APIHelper();
- string Corp = _Context.GetCorporationId(CorpId);
- User user = _Context.GetUser(UserId);
- if (Corp != user.CorporationId)
- return JsonHttpStatusResult.Error(this, "Nice try, but this user isnt in your corp.");
- model.Ledger = api.GetMiningLedger(user);
- if (model.Ledger == null)
- return JsonHttpStatusResult.Error(this, "No ledger data was returned.");
- if (api.HasError())
- JsonHttpStatusResult.ErrorSR(this, api.ErrorMessage() + $":{user.UserName}");
- if (IncludeAlts)
- {
- List<User> Alts = _Context.Users.Where(x => x.MainUserId == user.UserId).ToList();
- List<MiningApi> TotalResult = new List<MiningApi>();
- foreach (var item in Alts)
- {
- api.ResetError();
- var results = api.GetMiningLedger(item);
- if (results != null)
- TotalResult.AddRange(results);
- if (api.HasError())
- JsonHttpStatusResult.ErrorSR(this, api.ErrorMessage() + $":{item.UserName}");
- }
- model.Ledger = model.Ledger.Union(TotalResult).GroupBy(x => new { x.Date, x.type_id }).Select(xx => new MiningApi() { Date = xx.Key.Date, Quantity = xx.Sum(p => p.Quantity), type_id = xx.Key.type_id }).ToList();
- }
- if (api.HasError())
- JsonHttpStatusResult.Error(this, api.ErrorMessage());
- if (model.Ledger == null)
- return JsonHttpStatusResult.Error(this, "No results found for member.");
- IList<MiningApi> Invoiced = _Context.Invoices.Where(x => x.CorpId == CorpId && x.PayeeId == UserId).SelectMany(x => x.InvoiceItems).ToList().Select(xx => new MiningApi() { Date = xx.Mined, Quantity = xx.Amount, type_id = xx.ItemTypeId, Invoiced = true }).ToList();
- if (Invoiced != null)
- model.Ledger = model.Ledger.Union(Invoiced).GroupBy(x => new { x.Date, x.type_id }).Select(xx => new MiningApi() { Date = xx.Key.Date, Quantity = xx.Sum(p => p.Quantity), type_id = xx.Key.type_id, Invoiced = xx.Any(x => x.Invoiced == true) }).ToList();
- model.Dates = model.Ledger.Select(x => x.Date).Distinct().ToList();
- model.CurrentUser = this.User.Identity.Name;
- model.UserName = user.UserName;
- return PartialView("_Ledger", model);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement