public IHttpActionResult Report(Flag flag) { if (ModelState.IsValid) { var result = new FlagRepository().ReportAnIssue(flag); return Ok(result); } return new System.Web.Http.Results.ExceptionResult(new System.Exception(), this); }
/// public ScreenResponse ProvideScriptsForAScreen(ScriptRequestViewModel viewModel) { var agent = _context.Agents.FirstOrDefault(x => x.UserName.Equals(viewModel.AgentName, System.StringComparison.InvariantCultureIgnoreCase)); var language = _context.Languages.FirstOrDefault(x => x.Name.Equals(viewModel.LanguagePreference, System.StringComparison.InvariantCultureIgnoreCase)); var screen = _context.Screens.FirstOrDefault(x => x.Name.Equals(viewModel.ScreenName, System.StringComparison.InvariantCultureIgnoreCase)); var team = _context.Teams.FirstOrDefault(x => x.Agents.Any(ag => ag.Id.Equals(agent.Id))); var release = _context .Releases .Include(x => x.Scripts) .Include(x => x.Scripts.Select(y => y.Language)) .Include(x => x.Scripts.Select(y => y.Screen)) .Include(x => x.Scripts.Select(y => y.Field)) .Include(x => x.Scripts.Select(y => y.Product)) .Include(x => x.Scripts.Select(y => y.SubProduct)) .FirstOrDefault(x => x.Teams.Any(te => te.Id.Equals(team.Id))); if (release == null) throw new Exception("Nothing has been released to this agent."); var scripts = release.Scripts.Where (la => (language == null || la.Language.Id.Equals(language.Id)) && la.Screen.Id.Equals(screen.Id) ).ToList(); var screenResponse = new ScreenResponse() { ScreenName = viewModel.ScreenName }; screenResponse.Scripts = (from s in scripts select new ScriptResponse { Text = s.Text, Screen = s.Screen, Field = s.Field }).ToList(); var flagRepository = new FlagRepository(); foreach (var script in screenResponse.Scripts) { var flag = flagRepository.FlaggedForAfield(script.Screen.Id, script.Field.Id, agent.Id); if (flag!=null) { script.FlagMessage = flag.Comment; script.IsFlaggedForAgent = true; } } return screenResponse; }