public ActionResult Details(string initiativeId, string machineId) { var initiative = _initiativeBusiness.GetInitiative(Guid.Parse(initiativeId)); var sessions = _sessionBusiness.GetSessionsForMachine(machineId).ToArray(); var applicationIds = sessions.GroupBy(x => x.ApplicationId).Select(x => x.First()).Select(x => x.ApplicationId).ToArray(); var userIds = sessions.GroupBy(x => x.UserFingerprint).Select(x => x.First()).Select(x => x.UserFingerprint).ToArray(); var applications = new List <IApplication>(); foreach (var applicationId in applicationIds) { applications.Add(initiative.ApplicationGroups.SelectMany(x => x.Applications).SingleOrDefault(x => x.Id == applicationId)); } var users = new List <IUser>(); foreach (var userId in userIds) { users.Add(_userBusiness.GetUser(userId)); } var machines = new List <IMachine>(); foreach (var session in sessions) { machines.Add(_machineBusiness.GetMachine(session.MachineFingerprint)); } var model = new MachineDetailsModel() { Sessions = sessions, Applications = applications, Users = users, Machines = machines, MachineName = _machineBusiness.GetMachine(machineId).Name }; //var applications = _initiativeBusiness //var sessions = _sessionBusiness. return(View(model)); }
private MachineData GetMachineData(RegisterIssueRequest request, ISession session) { MachineData md; if (request.Session.Machine == null) { var machine = _machineBusiness.GetMachine(session.MachineFingerprint); md = new MachineData { Fingerprint = machine.Id, Name = machine.Name, Data = machine.Data, }; } else { md = request.Session.Machine; } return(md); }
public ActionResult Details(string initiativeidentifier, string userId) { if (initiativeidentifier == null) { throw new ArgumentNullException("initiativeidentifier", "InitiativeId was not provided."); } var i = _initiativeBusiness.GetInitiativesByDeveloper(_accountRepository.FindById(User.Identity.GetUserId()).Email).Where(x => x.Name == initiativeidentifier).ToArray(); var initiativeId = Guid.Empty; if (i.Count() == 1)//Name is unique { initiativeId = _initiativeBusiness.GetInitiativesByDeveloper(_accountRepository.FindById(User.Identity.GetUserId()).Email).Single(x => x.Name == initiativeidentifier).Id; } else//go with id { initiativeId = _initiativeBusiness.GetInitiativesByDeveloper(_accountRepository.FindById(User.Identity.GetUserId()).Email).Single(x => x.Id == Guid.Parse(initiativeidentifier)).Id; } if (initiativeId == Guid.Empty) { throw new NullReferenceException("No initiative found for the specified uid."); } var initiative = _initiativeBusiness.GetInitiative(initiativeId); var initiativeName = initiative.Name; var sessions = _sessionBusiness.GetSessionsForUser(userId).ToArray(); var applicationIds = sessions.GroupBy(x => x.ApplicationId).Select(x => x.First().ApplicationId).ToArray(); var applicationNames = new List <string>(); foreach (var applicationId in applicationIds) { var singleOrDefault = initiative.ApplicationGroups.SelectMany(x => x.Applications).SingleOrDefault(x => x.Id == applicationId); if (singleOrDefault != null) { applicationNames.Add(singleOrDefault.Name); } } var machineIds = sessions.GroupBy(x => x.MachineFingerprint).Select(x => x.First().MachineFingerprint).ToArray(); var machineNames = new List <string>(); foreach (var machineId in machineIds) { machineNames.Add(_machineBusiness.GetMachine(machineId).Name); } var machines = new List <IMachine>(); var users = new List <IUser>(); foreach (var session in sessions) { machines.Add(_machineBusiness.GetMachine(session.MachineFingerprint)); users.Add(_userBusiness.GetUser(session.UserFingerprint)); } var model = new UserViewModel() { Sessions = sessions, Users = users, ApplicationNames = applicationNames, Machines = machines, MachineNames = machineNames, InitiativeName = initiativeName, InitiativeUniqueIdentifier = initiativeidentifier, }; return(View(model)); }