SHARE
TWEET

Untitled

a guest Apr 20th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public ActionResult GetMiningLedger(int UserId, bool IncludeAlts)
  2.         {
  3.             using (EHRContext _Context = new EHRContext())
  4.             {
  5.                 LedgerViewModel model = new LedgerViewModel();
  6.  
  7.                 APIHelper api = new APIHelper();
  8.  
  9.                 string Corp = _Context.GetCorporationId(CorpId);
  10.                 User user = _Context.GetUser(UserId);
  11.  
  12.                 if (Corp != user.CorporationId)
  13.                     return JsonHttpStatusResult.Error(this, "Nice try, but this user isnt in your corp.");
  14.  
  15.                 model.Ledger = api.GetMiningLedger(user);
  16.  
  17.                 if (model.Ledger == null)
  18.                     return JsonHttpStatusResult.Error(this, "No ledger data was returned.");
  19.  
  20.                 if (api.HasError())
  21.                     JsonHttpStatusResult.ErrorSR(this, api.ErrorMessage() + $":{user.UserName}");
  22.  
  23.                 if (IncludeAlts)
  24.                 {
  25.                     List<User> Alts = _Context.Users.Where(x => x.MainUserId == user.UserId).ToList();
  26.  
  27.                     List<MiningApi> TotalResult = new List<MiningApi>();
  28.                     foreach (var item in Alts)
  29.                     {
  30.                         api.ResetError();
  31.  
  32.                         var results = api.GetMiningLedger(item);
  33.  
  34.                         if (results != null)
  35.                             TotalResult.AddRange(results);
  36.  
  37.                         if (api.HasError())
  38.                             JsonHttpStatusResult.ErrorSR(this, api.ErrorMessage() + $":{item.UserName}");
  39.                     }
  40.  
  41.                     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();
  42.  
  43.                 }
  44.  
  45.                 if (api.HasError())
  46.                     JsonHttpStatusResult.Error(this, api.ErrorMessage());
  47.  
  48.                 if (model.Ledger == null)
  49.                     return JsonHttpStatusResult.Error(this, "No results found for member.");
  50.  
  51.                 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();
  52.  
  53.                 if (Invoiced != null)
  54.                     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();
  55.  
  56.  
  57.                 model.Dates = model.Ledger.Select(x => x.Date).Distinct().ToList();
  58.                 model.CurrentUser = this.User.Identity.Name;
  59.                 model.UserName = user.UserName;
  60.                 return PartialView("_Ledger", model);
  61.  
  62.             }
  63.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top