Beispiel #1
0
        private SessionViewModel GetSessionsModel(string Name, PostedSessions postedSessions)
        {
            var model            = new SessionViewModel();
            var selectedSessions = new List <Session>();
            var postedSessionIds = new string[0];

            if (postedSessions == null)
            {
                postedSessions = new PostedSessions();
            }

            // if a view model array of posted sessions names exists
            // and is not empty,save selected names
            if (postedSessions.SessionNames != null && postedSessions.SessionNames.Any())
            {
                postedSessionIds = postedSessions.SessionNames;
            }

            //select group by name in dropdownlist
            var group = (from a in doc.Descendants("groups").Descendants("group")
                         where a.Element("name").Value == Name
                         select new Group
            {
                Name = a.Element("name").Value,
                Sessions = a.Descendants("session")
                           .Select(x => new Session
                {
                    SessionDate = x.Element("sessiondate").Value,
                    averagseTumorSize = Math.Round((x.Descendants("animals").Descendants("animal").Descendants("data").Descendants("datum")
                                                    .Select(y => new Animal
                    {
                        TumorSize = Convert.ToDouble(y.Element("value").Value.Replace(".", ","))
                    }).ToList().Average(t => t.TumorSize)), 2)
                }).ToList()
            }).SingleOrDefault();

            ViewBag.groupName = group.Name;

            //check the name of the group change
            //if the previous name is not equal to the current one, select all days
            if (previous_group_name == Name)
            {
                // if there are any selected names saved, create a list of sessions
                if (postedSessionIds.Any())
                {
                    selectedSessions = group.Sessions
                                       .Where(x => postedSessionIds.Any(s => x.SessionDate.ToString().Equals(s)))
                                       .ToList();
                }
                model.SelectedSessions = selectedSessions;
            }
            else
            {
                model.SelectedSessions = group.Sessions.ToList();
                previous_group_name    = Name;
            }

            //setup a view model
            model.AvailableSessions = group.Sessions.ToList();
            model.PostedSessions    = postedSessions;

            return(model);
        }
Beispiel #2
0
 public ActionResult Index(string Name, PostedSessions postedSessions)
 {
     svm = GetSessionsModel(Name, postedSessions);
     GetDataForPlot(svm.SelectedSessions);
     return(View(svm));
 }