Example #1
0
 public ActionResult Edit(string id, Group group)
 {
     try
     {
         if (!group.DisciplineConfiguration.Any())
         {
             group.DisciplineConfiguration = new List <DisciplineConfiguration>
             {
                 new DisciplineConfiguration {
                     DisciplineType = DisciplineType.Socio, RequiredAmount = 1, Semester = 1
                 },
                 new DisciplineConfiguration {
                     DisciplineType = DisciplineType.Socio, RequiredAmount = 1, Semester = 2
                 },
                 new DisciplineConfiguration {
                     DisciplineType = DisciplineType.Special, RequiredAmount = 1, Semester = 1
                 },
                 new DisciplineConfiguration {
                     DisciplineType = DisciplineType.Special, RequiredAmount = 1, Semester = 2
                 }
             };
         }
         if (ModelState.IsValid)
         {
             Service.Update(id, group);
             var users = _userService.Find(SearchFilter <User> .FilterByEntity(new User {
                 GroupId = group.Id
             }));
             foreach (var user in users)
             {
                 user.Course = group.Course;
                 _userService.Update(user.Id, user);
             }
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         throw;
     }
     ViewBag.Cathedras = ServiceFactory.CathedraService.Find(SearchFilter <Cathedra> .Empty);
     return(View(group));
 }
Example #2
0
        public void Seed()
        {
            _userService.Add(new Core.Entities.User()
            {
                Login    = $"AndrewThe",
                Password = "******",
                Email    = "*****@*****.**",
                Roles    = new List <Role> {
                    Role.Admin
                },
                UserName    = "******",
                GroupId     = "29627000-e32d-11e7-b070-a7a2334df747",
                PhoneNumber = "123-123-123"
            });
            var lecturer = new User()
            {
                Id       = Guid.NewGuid().ToString(),
                Login    = $"Lecturer",
                Password = "******",
                Email    = "*****@*****.**",
                Roles    = new List <Role> {
                    Role.Lecturer
                },
                UserName    = "******",
                GroupId     = "29627000-e32d-11e7-b070-a7a2334df747",
                PhoneNumber = "123-123-123"
            };

            _userService.Add(lecturer);

            var cathedra = new Cathedra
            {
                Id   = Guid.NewGuid().ToString(),
                Name = "App Math"
            };

            c.Add(cathedra);
            var group = new Group()
            {
                Id         = Guid.NewGuid().ToString(),
                CathedraId = cathedra.Id,
                Name       = "PMP-51",
                DisciplineConfiguration = new List <DisciplineConfiguration>
                {
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Socio, RequiredAmount = 1, Semester = 1
                    },
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Socio, RequiredAmount = 1, Semester = 2
                    },
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Special, RequiredAmount = 1, Semester = 1
                    },
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Special, RequiredAmount = 1, Semester = 2
                    },
                },
                Course = 5,
            };

            g.Add(group);

            for (int i = 0; i < 99; i++)
            {
                _userService.Add(new User()
                {
                    Login    = $"student{i}",
                    Password = "******",
                    Email    = $"*****@*****.**",
                    Roles    = new List <Role> {
                        Role.Student
                    },
                    UserName    = $"student{i}",
                    Course      = 5,
                    GroupId     = group.Id,
                    PhoneNumber = "123-123-123",
                });

                d.Add(new Discipline
                {
                    Id                 = Guid.NewGuid().ToString(),
                    DisciplineType     = i % 2 == 0 ? DisciplineType.Socio : DisciplineType.Special,
                    IsAvailable        = true,
                    LecturerId         = lecturer.Id,
                    Name               = $"Discipline{i}_11",
                    Semester           = 11,
                    ProviderCathedraId = cathedra.Id
                });
                var di = new Discipline
                {
                    Id                 = Guid.NewGuid().ToString(),
                    DisciplineType     = i % 2 == 0 ? DisciplineType.Socio : DisciplineType.Special,
                    IsAvailable        = true,
                    LecturerId         = lecturer.Id,
                    Name               = $"Discipline{i}_12",
                    Semester           = 12,
                    ProviderCathedraId = cathedra.Id
                };
                d.Add(di);
            }
            var disciplines = d.Find(SearchFilter <Discipline> .FilterByEntity(new Discipline {
                DisciplineType = DisciplineType.Special
            }));

            disciplines = new List <Discipline> {
                disciplines[0], disciplines[1]
            };
            group.DisciplineSubscriptions = disciplines.Select(d => d.Id).ToList();

            g.Update(group.Id, group);
        }