// All in one, becouse I work on the same attachment public void GroupTest() { string groupName = "TestGroup"; var groupModel = new PostGroupModel() { Name = groupName, Users = new string[] { this.userId.ToString() }, }; this.groupService.AddGroup(groupModel, this.userId); var groups = this.groupService.GetAllGroups(this.userId); var group = groups.Where(g => g.Name == groupName).FirstOrDefault(); Assert.NotNull(group); string editedName = groupName + "Edited"; var updateGroupModel = new UpdateGroupModel() { Id = group.Id.ToString(), Name = editedName, Users = Array.Empty <string>(), }; this.groupService.UpdateGroup(updateGroupModel, this.userId); groups = this.groupService.GetAllGroups(this.userId); group = groups.Where(g => g.Name == editedName).FirstOrDefault(); Assert.NotNull(group); Assert.True(group.Name == editedName); Assert.True(group.UserGroups.Count == 0); }
public IActionResult PostGroup([FromBody] PostGroupModel createGroupModel) { var userId = this.GetUserId(); this.groupService.AddGroup(createGroupModel, userId); return(this.NoContent()); }
public void AddGroup(PostGroupModel model, Guid ownerId) { ICollection <UserGroup> userGroups = new HashSet <UserGroup>(); Guid groupId = Guid.NewGuid(); foreach (string item in model.Users) { userGroups.Add(new UserGroup() { UserId = Guid.Parse(item), GroupId = groupId }); } Group group = new Group() { Id = groupId, Name = model.Name, GroupOwnerId = ownerId, UserGroups = userGroups, }; this.Create(group); }