Beispiel #1
0
        public ActionResult Create(GroupCreateEditViewModel groupView)
        {
            if (ModelState.IsValid)
            {
                groupView.Group.CreatedDate = DateTime.Now;
                db.Groups.Add(groupView.Group);
                db.SaveChanges();
                UpdateUsers(groupView);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(groupView);
        }
Beispiel #2
0
 private void UpdateUsers(GroupCreateEditViewModel groupView)
 {
     var group = db.Groups.Include(e=>e.Users).Where(x => x.GroupId == groupView.Group.GroupId).FirstOrDefault();
     if (groupView.SelectedTeacherIds == null)
     {
         groupView.SelectedTeacherIds = new int[0];
     }
     if (groupView.SelectedStudentIds == null)
     {
         groupView.SelectedStudentIds = new int[0];
     }
     foreach (var user in db.UserProfiles)
     {
         if (groupView.SelectedTeacherIds.Contains(user.UserId) || groupView.SelectedStudentIds.Contains(user.UserId))
         {
             if (!group.Users.Contains(user))
             {
                 group.Users.Add(user);
             }
         }
         else
         {
             if (group.Users.Contains(user))
             {
                 group.Users.Remove(user);
             }
         }
     }
 }
Beispiel #3
0
 private GroupCreateEditViewModel GetGroupCreateRecords()
 {
     var model = new GroupCreateEditViewModel
     {
         Students = new MultiSelectList(db.Students.ToList(), "UserId", "FullName"),
         Teachers = new MultiSelectList(db.Teachers.ToList(), "UserId", "FullName")
     };
     return model;
 }
Beispiel #4
0
 private GroupCreateEditViewModel GetGroupEditRecords(int id)
 {
     Group group = db.Groups.Include(e=>e.Users).Include(e=>e.ParentGroup).Where(x => x.GroupId == id).FirstOrDefault();
     var GroupStudents = group.Users.Where(x => Roles.IsUserInRole(x.UserName, Helpers.STUDENT_ROLE)).Select(x => x.UserId);
     var GroupTeachers = group.Users.Where(x => Roles.IsUserInRole(x.UserName, Helpers.TEACHER_ROLE)).Select(x => x.UserId);
     var model = new GroupCreateEditViewModel
     {
         Students = new MultiSelectList(db.Students.ToList(), "UserId", "FullName", GroupStudents),
         Teachers = new MultiSelectList(db.Teachers.ToList(), "UserId", "FullName", GroupTeachers),
         Group = group
     };
     return model;
 }
Beispiel #5
0
        public ActionResult Edit(GroupCreateEditViewModel groupView, FormCollection collection)
        {
            if (ModelState.IsValid)
            {

                groupView.Group.CreatedDate = DateTime.Now;
                int GroupId = groupView.Group.GroupId;
                db.Entry(groupView.Group).State = EntityState.Added;
                db.SaveChanges();
                groupView.Group.ParentGroup =  db.Groups.Find(GroupId);
                db.SaveChanges();
                UpdateUsers(groupView);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(groupView);
        }