Esempio n. 1
0
        public async Task <string[]> RequestAnalysis(CreateAnalysisModel model)
        {
            HttpResponseMessage req = await client.PostAsync("api/text/analysis", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"));

            if (req != null && req.IsSuccessStatusCode)
            {
                var data = await req.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <string[]>(data));
            }

            return(null);
        }
Esempio n. 2
0
        public IHttpActionResult Post(CreateAnalysisModel model)
        {
            try
            {
                var context        = Repository.HomeContext();
                var heuristicsRepo = new Repository <Heuristic>(context);
                var groupRepo      = new Repository <UserGroup>(context);
                var versionRepo    = new Repository <Version>(context);
                if (model == null)
                {
                    return(BadRequest("Model is null"));
                }

                var version    = new Repository <Version>(context).Get(model.VersionId);
                var groups     = model.Groups.Where(h => h.Checked).Select(g => Parser.CreateGroupWithUsers(g, context)).ToList();
                var heuristics = model.Heuristics.Where(h => h.Checked).ToList();
                foreach (var heuristic in heuristics)
                {
                    var h = heuristicsRepo.Get(heuristic.Id);
                    version.AnalysisApplicationForm.Heuristics.Add(h);
                }
                var nielsen = heuristicsRepo.Get().Where(x => x.Id <= 10).ToList();
                version.AnalysisApplicationForm.Heuristics = version.AnalysisApplicationForm.Heuristics.Concat(nielsen).ToList();
                foreach (var group in groups)
                {
                    var g = groupRepo.Get(group.Id);
                    version.AnalysisApplicationForm.Groups.Add(g);
                }
                versionRepo.Update(version, version.Id);
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }