public ActionResult Groups() { GroupData gd = new GroupData(); var gds = gd.GetGroupsInfo(); List<GroupModel> grModel = new List<GroupModel>(); foreach (var item in gds) { grModel.Add(convert.GroupDataToModel(item)); } return View(grModel); }
/// <summary> /// GroupModel convert to GroupData /// </summary> /// <param name="gm"></param> /// <returns></returns> public GroupData GroupModelToData(GroupModel gm) { GroupData gd = new GroupData() { Description = gm.Description, id = gm.id, isSelected = gm.isSelected, Name = gm.Name, StoriesCount = gm.StoriesCount, UsersCount= gm.UsersCount }; return gd; }
/// <summary> /// GroupData convert to GroupModel /// </summary> /// <param name="gd"></param> /// <returns></returns> public GroupModel GroupDataToModel(GroupData gd) { GroupModel gm = new GroupModel() { Description = gd.Description, id = gd.id, isSelected = gd.isSelected, Name = gd.Name, StoriesCount = gd.StoriesCount, UsersCount = gd.UsersCount }; return gm; }
public ActionResult AddEditStory(int? id) { StoryData sd = new StoryData(); StoryModel sm = new StoryModel(); if (id != null) { sm = convert.StoryDataToModel( sd.GetStory(id.Value)); } GroupData gd = new GroupData(); var gds = gd.GetGroups(id); List<GroupModel> grModel = new List<GroupModel>(); foreach (var item in gds) { grModel.Add(convert.GroupDataToModel(item)); } sm.Groups = grModel; return View(sm); }
public List<GroupData> GetGroups(int? id) { var groups = db.Groups.ToList(); List<Group> selected = new List<Group>(); if (id != null) { selected = db.Groups.Where(u => u.Stories.Any(e => e.id == id.Value)).ToList(); } List<GroupData> gms = new List<GroupData>(); foreach (var item in groups) { bool isselected = selected.Where(s => s.id == item.id).ToList().Count > 0; GroupData gm = new GroupData() { id = item.id, Description = item.Description, Name = item.Name, isSelected = isselected }; gms.Add(gm); } return gms; }
public List<GroupData> GetGroupsInfo() { var groups = db.Groups.ToList(); List<GroupData> gms = new List<GroupData>(); foreach (var item in groups) { var usersCount = item.Stories.GroupBy(s => s.UsersID).Select(g => g.Count()).ToList().Count(); GroupData gm = new GroupData() { id = item.id, Description = item.Description, Name = item.Name, StoriesCount = item.Stories.Count, UsersCount = usersCount }; gms.Add(gm); } return gms; }