public GroupMemberViewModel AddMemberToGroup(GroupMemberViewModel groupMember) { var member = Services.MemberService.GetById(groupMember.MemberId); var structuralGroup = ApplicationContext.DatabaseContext.Database.Query <StructuralGroup>("SELECT * FROM StructuralGroup WHERE Id = " + groupMember.StructuralGroupId).FirstOrDefault(); //TODO: Move this to a common domain service if (member == null || structuralGroup == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } MemberHelper.AddMemberToGroup(ApplicationContext.DatabaseContext.Database, groupMember.MemberId, groupMember.StructuralGroupId); return(new GroupMemberViewModel(new MemberViewModel(member), StructuralGroupViewModel.FromModel(structuralGroup))); }
public StructuralGroupViewModel UpdateGroup(StructuralGroupViewModel viewModel) { var root = GetRoot(); if (!viewModel.ValidateUpdate(root)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } using (var structureRepository = new StructureRepository(ApplicationContext.DatabaseContext.Database, ApplicationContext.Services.MemberService)) { var targetModel = structureRepository.GetById(viewModel.Id); targetModel.Name = viewModel.Name; targetModel.ParentId = viewModel.ParentId; structureRepository.Update(targetModel); } return(viewModel); }
public StructuralGroupViewModel InsertGroup(StructuralGroupViewModel viewModel) { var root = GetRoot(); if (!viewModel.ValidateNew(root)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var type = root == null ? StructuralGroupType.Root : viewModel.TypeDescription == "Class" ? StructuralGroupType.Leaf : StructuralGroupType.Intermediate; var model = new StructuralGroup(type, viewModel.Name); model.ParentId = viewModel.ParentId; using (var structureRepository = new StructureRepository(ApplicationContext.DatabaseContext.Database, ApplicationContext.Services.MemberService)) { structureRepository.Insert(model); } return(StructuralGroupViewModel.FromModel(model)); }