public async Task <IActionResult> addFriend(string username, string friendname) { //var res = await _service.GetProfileByUsername(username); if (await _service.GetProfileByUsername(username) == null) { return(NotFound("user not found")); } if (await _service.GetProfileByUsername(friendname) == null) { return(NotFound("friend not found")); } if (await _service.isFriend(username, friendname)) { return(BadRequest("already friend")); } var tem = await _service.AddUserFriend(username, friendname); if (tem == null) { return(BadRequest("add friend error")); } await _groupService.MakeFriend(username, friendname); return(Ok()); }
public async Task <String> insert() { var ms_wang = new Profile() { Username = "******", Groups = new List <string>(), Friends = new List <string>() }; ms_wang.Groups.Add("family"); var ms_yang = new Profile() { Username = "******", Groups = new List <string>(), Friends = new List <string>() }; var ms_li = new Profile() { Username = "******", Groups = new List <string>(), Friends = new List <string>() }; var ms_he = new Profile() { Username = "******", Groups = new List <string>(), Friends = new List <string>() }; await profileservice.CreateProfile(ms_wang); await profileservice.CreateProfile(ms_yang); await profileservice.CreateProfile(ms_li); await profileservice.CreateProfile(ms_he); await profileservice.AddUserFriend("wang", "li"); await groupservice.MakeFriend("wang", "li"); await profileservice.AddUserFriend("wang", "yang"); await groupservice.MakeFriend("wang", "yang"); var group1 = new ChatGroup() { name = "family", isFriend = false, owner = "wang", describe = "wei are family", members = new List <string>(), UserLatestRead = new Dictionary <string, ObjectId>(), }; group1.UserLatestRead.Add("wang", ObjectId.GenerateNewId()); group1.members.Add("wang"); await groupservice.MakeGroup(group1); await profileservice.AddUserGroup("he", "family"); await groupservice.AddGroup("he", "family"); await profileservice.AddUserGroup("li", "family"); await groupservice.AddGroup("li", "family"); await userservice.InsertUser(new Models.User() { Username = "******", Password = "******" }); await userservice.InsertUser(new Models.User() { Username = "******", Password = "******" }); await userservice.InsertUser(new Models.User() { Username = "******", Password = "******" }); await userservice.InsertUser(new Models.User() { Username = "******", Password = "******" }); return("Ok"); }