public Group LoadGroup(int groupId) { bool exist = db.GroupMembers.Any(x => x.GroupId == groupId); if (exist) { IQueryable <Models.GroupMember> list = db.GroupMembers.Where(x => x.GroupId == groupId); Group group = new Group { groupId = groupId }; foreach (Models.GroupMember groupMemberDB in list) { var groupMember = new GroupMember(); groupMember.user.username = groupMemberDB.Username; groupMember.role = groupMemberDB.GroupRole; groupMember.groupID = groupId; group.AddMember(groupMember); } Console.WriteLine(group.groupMembers[0].role); return(group); } return(null); }
public bool CreateGroup(Group group) { try { var groupId = db.Groups.Count() + 1; List <GroupMember> groupMembers = new List <GroupMember>(); foreach (GroupMember groupMember in group.groupMembers) { groupMembers.Add(groupMember); } db.Add(new Database.Models.Group { GroupId = groupId }); db.SaveChanges(); //Creating group creates automatically PB db.Add(new ProductBacklog { GroupId = groupId }); db.SaveChanges(); //Creating SprintList with no data db.Add(new Models.SprintList { GroupId = groupId, Duration = 0, NumberOfSprints = 0 }); db.SaveChanges(); //Create all users that are in the group foreach (GroupMember groupMember in groupMembers) { db.Add(new Models.GroupMember { Username = groupMember.user.username, GroupId = groupId, GroupRole = groupMember.role }); } db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }