Esempio n. 1
0
        public async Task <ActionResult> Index(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(View());
            }

            OrleansHelper.EnsureOrleansClientInitialized();

            Guid          classGuid = new Guid(id);
            ICollegeClass grain     = GrainFactory.GetGrain <ICollegeClass>(classGuid);

            ClassInfo classInfo = await grain.GetClassInfo();

            IList <IStudent> students = await grain.GetStudents();

            string[] studentNames = new string[0];
            if (students != null && students.Count > 0)
            {
                var studentNameTasks = new Task <string> [students.Count];
                for (int i = 0; i < students.Count; i++)
                {
                    studentNameTasks[i] = students[i].GetFullName();
                }

                studentNames = await Task.WhenAll(studentNameTasks);
            }

            ITeacher teacherGrain = GrainFactory.GetGrain <ITeacher>(classInfo.Teacher);
            string   teacherName  = await teacherGrain.GetFullName();

            var classView = new ClassViewModel()
            {
                Id        = new Guid(id),
                Name      = classInfo.Name,
                Subject   = classInfo.Subject,
                Teacher   = teacherName,
                ClassSize = studentNames.Length,
                Students  = studentNames
            };

            return(View(classView));
        }