private List <Witness> CreateWitness(WitnessFileDownload response, ScenarioModel scenario)
        {
            List <Witness>      lWitness  = new List <Witness>();
            List <ResponseFile> responseF = response.Scenario;

            for (int i = 0; i < responseF.Count(); i++)
            {
                //for(int i=0; i< response.responses.Count; i++)
                try
                {
                    {
                        lWitness.Add(new Witness()
                        {
                            Killer = new Killer()
                            {
                                Gun = scenario.Guns.Where(g => g.Name == responseF[i].Gun).FirstOrDefault(), Local = scenario.Locals.Where(l => l.Name == responseF[i].Local).FirstOrDefault(), Suspect = scenario.Suspects.Where(s => s.Name == responseF[i].Suspect).FirstOrDefault()
                            }
                        });
                    }
                }
                catch (Exception e)
                {
                    lWitness = null;
                }
            }
            return(lWitness);
        }
        public ActionResult GenerateWitnessJsonFile()
        {
            /* Get the scenario model to save into a file */
            WitnessFileDownload fileToDownload = new WitnessFileDownload();

            /* Get current grid */
            if (this.TempData["WitnessGridItems"] != null)
            {
                fileToDownload = (WitnessFileDownload)this.TempData["WitnessGridItems"];
            }
            this.TempData["WitnessGridItems"] = fileToDownload;

            try
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Converters.Add(new JavaScriptDateTimeConverter());
                serializer.NullValueHandling = NullValueHandling.Ignore;

                using (StreamWriter sw = new StreamWriter(@"c:\temp\response"))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, fileToDownload);
                    }
            }
            catch (Exception e)
            {
                Error("Ocorreu um erro ao gerar o arquivo: " + e.Message);
                return(View("Scenario"));
            }

            Success("Arquivo de testemunhas gerado com sucesso na pasta C:\\TEMP!");
            return(View("Witness"));
        }
        public List <Witness> DeserializeJsonFileWitness(Stream file, ScenarioModel scenario)
        {
            /* Get contents to string */
            string str = (new StreamReader(file)).ReadToEnd();

            /* Deserializes string into object */
            WitnessFileDownload response = JsonConvert.DeserializeObject <WitnessFileDownload>(str);


            /* Create objects from the deserialized json */
            return(CreateWitness(response, scenario));
        }
        public string DeleteWitnessItem(string idItem)
        {
            WitnessFileDownload response = new WitnessFileDownload();

            /* Get current grid */
            if (this.TempData["WitnessGridItems"] != null && idItem != null)
            {
                response = (WitnessFileDownload)this.TempData["WitnessGridItems"];

                response.Scenario.RemoveAt(int.Parse(idItem));
                return(WitnessGridGenerator(string.Empty, string.Empty, string.Empty, response));
            }
            else
            {
                return("");
            }
        }
        public string AddWitnessItem(string suspect, string local, string gun)
        {
            if (suspect != null && local != null && gun != null)
            {
                WitnessFileDownload response = new WitnessFileDownload();
                /* Get current grid */
                if (this.TempData["WitnessGridItems"] != null)
                {
                    response = (WitnessFileDownload)this.TempData["WitnessGridItems"];
                }
                else
                {
                    response.Scenario = new List <ResponseFile>();
                }

                return(WitnessGridGenerator(suspect, local, gun, response));
            }
            else
            {
                return("");
            }
        }
        private string WitnessGridGenerator(string suspect, string local, string gun, WitnessFileDownload response)
        {
            StringBuilder sb = new StringBuilder();

            /* Generate table header */
            sb.AppendLine("<table class=\"table table-hover\">");
            sb.AppendLine(" <thead>");
            sb.AppendLine("   <tr>");
            sb.AppendLine("     <th>#</th>");
            sb.AppendLine("     <th>Suspeito</th>");
            sb.AppendLine("     <th>Local</th>");
            sb.AppendLine("     <th>Arma</th>");
            sb.AppendLine("     <th>Excluir</th>");
            sb.AppendLine("   </tr>");
            sb.AppendLine(" </thead>");
            sb.AppendLine(" <tbody>");



            if (suspect != string.Empty && local != string.Empty && gun != string.Empty)
            {
                response.Scenario.Add(new ResponseFile()
                {
                    Suspect = suspect, Local = local, Gun = gun
                });
            }

            for (int i = 0; i < response.Scenario.Count(); i++)
            {
                sb.AppendLine("     <tr>");
                sb.AppendLine("         <td>");
                sb.AppendLine(i.ToString());
                sb.AppendLine("         </td>");
                sb.AppendLine("         <td>");
                sb.AppendLine(response.Scenario[i].Suspect);
                sb.AppendLine("         </td>");
                sb.AppendLine("         <td>");
                sb.AppendLine(response.Scenario[i].Local);
                sb.AppendLine("         </td>");
                sb.AppendLine("         <td>");
                sb.AppendLine(response.Scenario[i].Gun);
                sb.AppendLine("         </td>");
                sb.AppendLine("         <td>");
                sb.AppendLine(string.Concat("<a href=\"javascript:DeleteWitnessItem('", i, "','", "S", "');\"><img src=\"" + Url.Content("~/Content/img/glyphicons_197_remove.png") + "\"></a>"));
                sb.AppendLine("         </td>");
            }

            this.TempData["WitnessGridItems"] = response;

            sb.AppendLine(" </tbody>");
            sb.AppendLine("</tbody>");

            return(sb.ToString());
        }