public DoctrinaGroup CreateGroup(CreateGroupViewModel model, string ownerId) { DoctrinaGroup result = new DoctrinaGroup { Name = model.Name }; _db.Add <DoctrinaGroup>(result); _db.SaveChanges(); _db.Entry(result).GetDatabaseValues(); DoctrinaUserDoctrinaGroup newUserGroup = new DoctrinaUserDoctrinaGroup { DoctrinaGroupId = result.Id, DoctrinaUserId = ownerId, IsAdmin = true, IsInvitePending = false, IsRequestPending = false, }; _db.Add <DoctrinaUserDoctrinaGroup>(newUserGroup); _db.SaveChanges(); string folderPath = Path.Combine(_hostingEnvironment.WebRootPath, "DynamicResources/groups", result.Id); Directory.CreateDirectory(folderPath); return(result); }
public void UpdateGroup(string id, GroupSettingsViewModel newModel) { DoctrinaGroup group = _db.Find <DoctrinaGroup>(id); if (group != null) { if (!string.IsNullOrEmpty(newModel.NewName)) { group.Name = newModel.NewName; } _db.DoctrinaGroups.Attach(group); _db.Entry(group).State = EntityState.Modified; _db.SaveChanges(); } }
public DoctrinaGroupSection CreateSection(CreateSectionViewModel model) { DoctrinaGroup currentGroup = this.GetGroup(model.GroupId); DoctrinaGroupSection newSection = new DoctrinaGroupSection { Name = model.Name, DoctrinaGroup = currentGroup }; _db.Add <DoctrinaGroupSection>(newSection); _db.SaveChanges(); string folderPath = Path.Combine(_hostingEnvironment.WebRootPath, $"DynamicResources/groups/{currentGroup.Id}/{newSection.Id}"); Directory.CreateDirectory(folderPath); return(newSection); }
public void DeleteGroup(string id) { DoctrinaGroup group = _db.Find <DoctrinaGroup>(id); IList <DoctrinaGroupSection> sections = _db.DoctrinaGroupSections.Where(s => s.DoctrinaGroup.Id == group.Id).ToList(); IList <DoctrinaUserDoctrinaGroup> userGroupRelations = _db.DoctrinaUserDoctrinaGroup.Where(gu => gu.DoctrinaGroupId == group.Id).ToList(); foreach (var section in sections) { DeleteSection(section.Id); } foreach (var relation in userGroupRelations) { _db.Remove <DoctrinaUserDoctrinaGroup>(relation); } string folderPath = Path.Combine(_hostingEnvironment.WebRootPath, "DynamicResources/groups", group.Id); Directory.Delete(folderPath); _db.Remove <DoctrinaGroup>(group); _db.SaveChanges(); }