Esempio n. 1
0
        public ActionResult Index(GraphViewModel model)
        {
            try
            {
                FetchItemServiceResponse <Graph <UserDto> > responseGraph;

                if (model == null || model.FileImported == false)
                {
                    model = new GraphViewModel
                    {
                        TeamMembers          = TeamMembers,
                        SelectedTeamMemberId = 1,
                    };

                    if (model.FromDate == null || model.ToDate == null)
                    {
                        List <DateTime> startAndEndDateOfConversations = GetStartAndEndDateOfConversations(model.SelectedTeamMemberId.ToString());
                        model.FromDate = startAndEndDateOfConversations.First().ToString("MM/dd/yyyy");
                        model.ToDate   = startAndEndDateOfConversations.Last().ToString("MM/dd/yyyy");
                    }

                    DateTime from = DateTime.ParseExact(model.FromDate, "MM/dd/yyyy", null);
                    DateTime to   = DateTime.ParseExact(model.ToDate, "MM/dd/yyyy", null);

                    responseGraph = _graphService.FetchEmailsGraph(GetConnectionStringBasedOnSelectedMember(model.SelectedTeamMemberId.ToString()), from, to);
                }
                else // file is imported
                {
                    if (model.FromDate == null || model.ToDate == null)
                    {
                        List <DateTime> startAndEndDateOfConversations = GetStartAndEndDateOfConversations(model.SelectedTeamMemberId.ToString(), true);
                        model.FromDate = startAndEndDateOfConversations.First().ToString("MM/dd/yyyy");
                        model.ToDate   = startAndEndDateOfConversations.Last().ToString("MM/dd/yyyy");
                    }

                    DateTime from = DateTime.ParseExact(model.FromDate, "MM/dd/yyyy", null);
                    DateTime to   = DateTime.ParseExact(model.ToDate, "MM/dd/yyyy", null);

                    responseGraph = _graphService.FetchEmailsGraph(_importConnectionString, from, to);
                }

                responseGraph.Item.SetDegrees();

                List <NodeDto> nodes = responseGraph.Item.Nodes.Select(x => new NodeDto()
                {
                    id    = x.Id,
                    label = x.NodeElement.Name,
                    title = $"Node degree: {x.Degree}",
                    size  = 10,
                    color = "#f5cbee"
                }).ToList();
                List <EdgeDto> edges = responseGraph.Item.Edges.Select(x => new EdgeDto()
                {
                    from = x.Node1.Id, to = x.Node2.Id
                }).ToList();

                GraphDto graphDto = new GraphDto
                {
                    nodes = nodes,
                    edges = edges
                };

                model.Graph    = responseGraph.Item;
                model.GraphDto = graphDto;
            }
            catch (Exception e)
            {
                this.AddToastMessage("Error", e.Message, ToastType.Error);
            }
            return(View(model));
        }