public static bool areAlreadyFriends(int idApplicant, int idReciever) { if (friendsRepository.FindBy(x => x.IdApplicant == idApplicant && x.IdReciever == idReciever && x.IsDeleted == false || x.IdReciever == idApplicant && x.IdApplicant == idReciever && x.IsDeleted == false).FirstOrDefault() == null) { return(false); } else { return(true); } }
public IDtoOutObjects Accept(DtoInAddFriend dtoInFriend) { DtoOutError error = new DtoOutError(); if (TokenTools.Authentication(dtoInFriend.Token, dtoInFriend.DeviceName)) { User acceptant = TokenTools.getUserFromToken(dtoInFriend.Token); Friend friend = _friendsRepository.FindBy(x => x.IdReciever == acceptant.Id && x.IsDeleted == false && x.ObjectApplicant.Email == dtoInFriend.EmailReciever).FirstOrDefault(); if (friend == null) { UserDoesNotAskedForFriendshipException ex = new UserDoesNotAskedForFriendshipException(); error.Exception = ex; return(error); } if (friend.Accepted == true) { YouAreAlreadyFriendsExceptions ex = new YouAreAlreadyFriendsExceptions(); error.Exception = ex; return(error); } friend.Accepted = true; _friendsRepository.Edit(friend); _friendsRepository.Save(); ChatRoomTools.Create(new List <User>() { acceptant, _usersRepository.FindBy(x => x.Email == dtoInFriend.EmailReciever).FirstOrDefault() }); var config = new MapperConfiguration(cfg => { cfg.CreateMap <Friend, DtoOutFriend>(); }); IMapper mapper = config.CreateMapper(); DtoOutFriend dtoOutFriend = new DtoOutFriend(); mapper.Map(friend, dtoOutFriend); return(dtoOutFriend); } else { NotAuthenticatedException ex = new NotAuthenticatedException(); error.Exception = ex; return(error); } }