Esempio n. 1
0
        public ActionResult Create([Bind(Include = "GroupId,GroupName")] Group group)
        {
            var groups = this.DbContext.Groups.ToList();
            SetGroups(groups);
            if (!ModelState.IsValid)
            {
                return View(groups);
            }
            this.DbContext.Groups.Add(group);


            ParticipantUserGroup participantUserGroup = new ParticipantUserGroup();
            participantUserGroup.ParticipantUser = this.DbContext.Users.OfType<ParticipantUser>().First(u => u.ID == this.CurrentUser.ID);
            group.ParticipantUsers.Add(participantUserGroup);

            this.DbContext.SaveChanges();
            return RedirectToAction("Create");
        }
Esempio n. 2
0
        public ActionResult Create(int? projectId, [Bind(Include = "GroupName, Accessibility")]ProjectGroup projectGroup)
        {
            // ユーザーとプロジェクトの取得は親クラスで実行ずみ。

            if (!ModelState.IsValid)
            {
                return View(projectGroup);
            }

            projectGroup.Project = this.Project;

            ParticipantUserGroup pug = new ParticipantUserGroup();
            pug.Group = projectGroup;
            pug.ParticipantUser = this.CurrentUser;

            this.DbContext.Groups.Add(projectGroup);
            this.DbContext.ParticipantUserGroups.Add(pug);
            this.DbContext.Users.Attach(pug.ParticipantUser);
            this.DbContext.SaveChanges();
            return RedirectToAction("Index", new { projectId = projectId });
        }
 public ActionResult AssignGroup(int? id, Dictionary<int, bool> belongsToGroup)
 {
     if (id == null)
     {
         return RedirectToAction("Index");
     }
     var db = this.DbContext;
     var selectedGroup = FindGroup(db, this.Project, id.Value);
     if (selectedGroup == null)
     {
         return RedirectToAction("Index");
     }
     var users = GetUsers(db, this.Project);
     GetRelationships(db, this.Project);
     foreach (var u in users)
     {
         if (!belongsToGroup.ContainsKey(u.ID))
         {
             continue;
         }
         // プロジェクトの参加ユーザーを全て取得しているので、selectedGroup -> user はnullにならない。
         var relationship = selectedGroup.ParticipantUsers.FirstOrDefault(pug => pug.ParticipantUser.ID == u.ID);
         if ((relationship == null) && (belongsToGroup[u.ID]))
         {
             relationship = new ParticipantUserGroup();
             relationship.Group = selectedGroup;
             relationship.ParticipantUser = u;
             db.ParticipantUserGroups.Add(relationship);
         }
         else if ((relationship != null) && (!belongsToGroup[u.ID]))
         {
             db.ParticipantUserGroups.Remove(relationship);
         }
     }
     db.SaveChanges();
     return RedirectToAction("Index");
 }
Esempio n. 4
0
        public ActionResult Enter(int? projectId, int? groupId)
        {
            // ユーザーとプロジェクトの取得は親クラスで実行ずみ。

            if (groupId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            // 指定したグループが現在のプロジェクトのグループであり、かつ、公開範囲が「公開」であることを確認する。
            var group = this.DbContext
                .Entry(this.Project)
                .Collection(p => p.ProjectGroups)
                .Query()
                .Where(g => g.ID == groupId && g.Accessibility == ProjectGroupAccessibility.Public)
                .Include(g => g.ParticipantUsers)
                .Include(g => g.ParticipantUsers.Select(pug => pug.ParticipantUser))
                .FirstOrDefault();

            if (group == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var relashonship = this.DbContext
                .Entry(this.Project)
                .Collection(p => p.ProjectGroups)
                .Query()
                .Where(g => g.ID == groupId)
                .SelectMany(g => g.ParticipantUsers)
                .FirstOrDefault(pug => pug.ParticipantUser.ID == this.CurrentUser.ID);

            // 現在のユーザーがそのグループに参加していない場合のみグループに参加する
            if (group.ParticipantUsers.All(pug => pug.ParticipantUser.ID != this.CurrentUser.ID))
            {
                ParticipantUserGroup pug = new ParticipantUserGroup();
                pug.Group = group;
                pug.ParticipantUser = this.CurrentUser;
                this.DbContext.ParticipantUserGroups.Add(pug);
                this.DbContext.SaveChanges();
            }

            return RedirectToAction("Index", new { projectId = projectId });
        }
 public ActionResult AssignUser(int? id, Dictionary<int, bool> containsUser)
 {
     if (id == null)
     {
         return RedirectToAction("Index");
     }
     var db = this.DbContext;
     var selectedUser = FindUser(db, this.Project, id.Value);
     if (selectedUser == null)
     {
         return RedirectToAction("Index");
     }
     var groups = GetGroups(db, this.Project);
     GetRelationships(db, this.Project);
     foreach (var g in groups)
     {
         if (!containsUser.ContainsKey(g.ID))
         {
             continue;
         }
         // プロジェクトのグループを全て取得しているので、selectedUser -> group はnullにならない。
         var relationship = selectedUser.Groups.FirstOrDefault(pug => pug.Group.ID == g.ID);
         if ((relationship == null) && (containsUser[g.ID]))
         {
             relationship = new ParticipantUserGroup();
             relationship.Group = g;
             relationship.ParticipantUser = selectedUser;
             db.ParticipantUserGroups.Add(relationship);
         }
         else if ((relationship != null) && (!containsUser[g.ID]))
         {
             db.ParticipantUserGroups.Remove(relationship);
         }
     }
     db.SaveChanges();
     return RedirectToAction("Index");
 }