public FriendDTO GetFriendById(int friendId) { Friend friendFromDb = _billManagerRepository.GetFriendById(friendId, true); if (friendFromDb == null) { return(null); } else { FriendDTO friend = new FriendDTO() { Id = friendFromDb.Id, FirstName = friendFromDb.FirstName, LastName = friendFromDb.LastName }; if (friendFromDb.SplitBills.Any()) { foreach (var splitBill in friendFromDb.SplitBills) { friend.SplitBills.Add(new SplitBillDTO() { Amount = splitBill.Amount, Description = splitBill.Bill.Description, FriendName = friendFromDb.FirstName + " " + friendFromDb.LastName, FriendId = friendFromDb.Id, BillId = splitBill.BillId }); } } return(friend); } }
public void addFriendTest() { MockTokenService tokenService = new MockTokenService(); MockUserDataMapper mockMapper = new MockUserDataMapper(); IUserService _service = new UserService(tokenService, mockMapper); mockMapper.Users.Add(new User { id = 1, username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór" }); mockMapper.Users.Add(new User { id = 2, username = "******", email = "*****@*****.**", password = "******", fullName = "Steinn" }); var authDTO = new FriendDTO { username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór", accessToken = "1", friendUsername = "******" }; _service.addFriend(authDTO); Assert.Equal(1, mockMapper.Friends.Count()); }
public void AddFriend(string friend) { // Init db Db db = new Db(); // Get user's id UserDTO userDTO = db.Users.Where(x => x.Username.Equals(User.Identity.Name)).FirstOrDefault(); int userId = userDTO.Id; // Get friend to be id UserDTO userDTO2 = db.Users.Where(x => x.Username.Equals(friend)).FirstOrDefault(); int friendId = userDTO2.Id; // Add DTO FriendDTO friendDTO = new FriendDTO(); friendDTO.User1 = userId; friendDTO.User2 = friendId; friendDTO.Active = false; db.Friends.Add(friendDTO); db.SaveChanges(); }
public FriendDTO GetDetailFriend(int userId, int friendId) { using (var uow = new UnitOfWork()) { var accountRepo = uow.GetRepository <Account>(); var friendshipRepo = uow.GetRepository <Friendship>(); Account account = accountRepo.GetById(friendId); Friendship existFriendship = friendshipRepo.GetAll().FirstOrDefault(f => ( (f.UserOneId == userId & f.UserTwoId == friendId) | (f.UserOneId == friendId & f.UserTwoId == userId))); FriendMapper fm = new FriendMapper(); FriendDTO frDTO = fm.MapToDTO(account); if (existFriendship != null) { frDTO.IsFriend = true; frDTO.Since = existFriendship.Since; } else { frDTO.IsFriend = false; } return(frDTO); } }
public bool Save(FriendDTO friendDTO) { if (friendDTO == null) { return(false); } Friend friend = new Friend { UserId = friendDTO.User.Id, FriendId = friendDTO.Friend.Id, CreatedOn = friendDTO.CreatedOn }; try { UoW.FriendRepo.Insert(friend); UoW.Save(); return(true); } catch { return(false); } }
public void addFriend(FriendDTO friendReq) { // If userid is null the user does not exist int?userId = _mapper.getUserId(friendReq.username); if (userId == null) { throw new InvalidParametersException("User does not exist in database"); } // If friendId is null the friend does not exist int?friendId = _mapper.getUserId(friendReq.friendUsername); if (friendId == null) { throw new InvalidParametersException("User does not exist in database"); } // if friendUsername is null the friend does not exist if (friendReq.friendUsername == null) { throw new InvalidParametersException("Friend username must be set in order to add a friend"); } // Authenticate the user adding the friend if (!_tokenService.validateUserToken(friendReq.accessToken, (int)userId)) { throw new InvalidParametersException("To add a friend you must use a valid token and a valid username"); } // Datalayer call to create the 2 friends _mapper.addFriend((int)userId, (int)friendId); }
public async Task SendEmailResponsibleService(FriendDTO nameDescription, FriendDTO emailFriends) { var position = nameDescription.Name.IndexOf(","); var viewModel = new { Name = emailFriends.Name, MyDescription = emailFriends.Description, NameChild = nameDescription.Name[(position + 1)..],
public void Constructor_Test() { FriendDTO newUser = new FriendDTO(); Assert.AreEqual(string.Empty, newUser.FirstName, "Should be an empty string"); Assert.AreEqual(string.Empty, newUser.LastName, "Should be an empty string"); Assert.AreEqual(string.Empty, newUser.Street, "Should be an empty string"); Assert.AreEqual(null, newUser.Zip, "Should be an empty string"); }
public string PostFriend(FriendDTO friendDTO) { if (!friendService.Save(friendDTO)) { return("Friendship wasn't created"); } return("Friendship was created"); }
public IActionResult GetFriend(int id) { FriendDTO friend = _friendHandler.GetFriendById(id); if (friend == null) { return(NotFound()); } return(Ok(friend)); }
public IHttpActionResult GetFriendDetail(int userId, int friendId) { var friendshipService = new FriendshipService(); FriendDTO frDTO = friendshipService.GetDetailFriend(userId, friendId); if (frDTO == null) { return(BadRequest("This user does not exist")); } return(Ok(frDTO)); }
public static Friend GetFriend(this FriendDTO item) { if (item == null) { throw new ArgumentNullException(); } return(new Friend { Id = item.Id, FriendId = item.FriendId, IsDeleted = item.IsDeleted }); }
public void DeclineFriendRequest(int friendId) { Db db = new Db(); UserDTO userDTO = db.Users.Where(x => x.Username.Equals(User.Identity.Name)).FirstOrDefault(); int userId = userDTO.Id; FriendDTO friendDTO = db.Friends.Where(x => x.User1 == friendId && x.User2 == userId).FirstOrDefault(); db.Friends.Remove(friendDTO); db.SaveChanges(); }
public void AcceptFriendRequest(int friendId) { Db db = new Db(); UserDTO userDTO = db.Users.Where(x => x.Username.Equals(User.Identity.Name)).FirstOrDefault(); int userId = userDTO.Id; FriendDTO friendDTO = db.Friends.Where(x => x.User1 == friendId && x.User2 == userId).FirstOrDefault(); friendDTO.Active = true; db.SaveChanges(); }
public async Task <FriendDTO> AddFriend(FriendDTO friendDTO) { if (_context.Friends.Any(b => b.Id == friendDTO.Id)) { throw new Exception(USER_ALREADY_IN_FRIENDLIST); } _context.Friends.Add(friendDTO.GetFriend()); await _context.SaveChangesAsync(); return(friendDTO); }
public FriendDTO ToTransfer() { var dto = new FriendDTO(); dto.Id = Id; dto.Contacts = new List <int>(); foreach (var item in Contacts) { dto.Contacts.Add(item); } return(dto); }
public HttpResponseMessage RemoveFriend(FriendDTO postData) { try { var friend = UserController.GetUserById(PortalSettings.PortalId, postData.FriendId); FriendsController.Instance.DeleteFriend(friend); return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" })); } catch (Exception exc) { Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public FriendDTO MapToDTO(Account source) { FriendDTO target = new FriendDTO(); target.Id = source.Id; target.FullName = source.LastName + " " + source.FirstName; target.Email = source.Email; target.UserName = source.UserName; AdressMapper adressMapper = new AdressMapper(); target.Adress = adressMapper.MapToDTO(source.Adress); return(target); }
public IActionResult UpdateFriend([FromBody] FriendDTO friend) { if (friend == null || friend.Id == 0) { return(BadRequest()); } _billManagerRepository.UpdateFriend(new Friend() { Id = friend.Id, FirstName = friend.FirstName, LastName = friend.LastName }); return(NoContent()); }
public IActionResult CreateFriend([FromBody] FriendDTO friend) { if (friend == null || friend.Id != 0) { return(BadRequest()); } Friend friendFromDb = _billManagerRepository.AddFriend(new Friend() { FirstName = friend.FirstName, LastName = friend.LastName }); friend.Id = friendFromDb.Id; return(CreatedAtRoute("GetFriend", new { id = friend.Id }, friend)); }
public static FriendModel ToModel(FriendDTO friendDTO) { if (friendDTO == null) { return(null); } return(new FriendModel() { Id = friendDTO.Id, Name = friendDTO.Name, Age = friendDTO.Age, LibraryName = friendDTO.Library != null ? friendDTO.Library.Name: null, IsFriend = friendDTO.IsFriend }); }
public static FriendMessage ToMessage(FriendDTO friend) { if (friend == null) { return(null); } return(new FriendMessage() { Id = friend.Id.ToString(), Name = friend.Name, Age = friend.Age, LibraryName = friend.LibraryName, IsFriend = friend.IsFriend, }); }
public void AcceptFriendRequest(int friendId) { //Init Db Db db = new Db(); //user id get var userDTO = db.Users.Where(v => v.UserName.Equals(User.Identity.Name)).FirstOrDefault(); var userId = userDTO.Id; //Accept friend request FriendDTO friendDto = db.Friends.Where(v => v.User1 == friendId && v.User2 == userId).FirstOrDefault(); friendDto.Active = true; db.SaveChanges(); }
private async Task CreateFriendAccountIfNotExist(FriendDTO friendDto) { if (friendDto == null) { throw new ValidationException("friendDto was null", ""); } var friend = await _appContext.Friends.FirstOrDefaultAsync(f => f.FriendId == friendDto.FriendId); if (friend != null) { return; } var newFriend = Mapper.Map <FriendDTO, Friend>(friendDto); _appContext.Friends.Add(newFriend); }
public void getFriendsTest() { MockTokenService tokenService = new MockTokenService(); MockUserDataMapper mockMapper = new MockUserDataMapper(); IUserService _service = new UserService(tokenService, mockMapper); string name = "test"; string mailAddition = "@test.is"; string password = "******"; string fullname = "Test Testson The "; List <FriendDTO> DTOfriends = new List <FriendDTO>(); // Fill USER datalist and friendDTO datalist for (int i = 0; i < 8; i++) { User u = new User { id = i, username = name += i.ToString(), email = name += i.ToString() + mailAddition, password = password += i.ToString(), fullName = fullname += i.ToString() }; mockMapper.Users.Add(u); if (i > 0) { var authDTO = new FriendDTO { username = u.username, email = u.email, password = u.password, fullName = u.fullName, accessToken = "asd", friendUsername = mockMapper.Users[i - 1].username }; DTOfriends.Add(authDTO); } } foreach (FriendDTO friend in DTOfriends) { _service.addFriend(friend); } Assert.Equal(mockMapper.Friends.Count(), 7); }
public IActionResult UpdateRelationship([FromBody] FriendDTO friendDTO) { if (friendDTO == null) { return(BadRequest(ModelState)); } if (!_friendRepository.RelationshipExists(friendDTO.User1ID, friendDTO.User2ID)) { ModelState.AddModelError("", "Relationship doesn't exists..."); return(StatusCode(404, ModelState)); } var friendObj = _mapper.Map <Friend>(friendDTO); var obj = _friendRepository.UpdateRelationship(friendObj); if (obj == false) { return(BadRequest(ModelState)); } return(Ok()); }
public ActionResult Unfriend(int Id) { if (Session["loggedUser"] == null) { return(RedirectToAction("Login", "Home")); } UserDTO currentUser = (UserDTO)Session["loggedUser"]; Service1Client service = new Service1Client(); FriendDTO unfriend = service.GetFriendsByUserId(currentUser.Id).Where(u => u.Friend.Id == Id).FirstOrDefault(); service.DeleteFriend(unfriend.Id); FriendDTO unfriend2 = service.GetFriendsByUserId(Id).Where(u => u.User.Id == currentUser.Id).FirstOrDefault(); service.DeleteFriend(unfriend2.Id); return(RedirectToAction("UserProfile", "Home")); }
public void AddFriend(string friend) { Db db = new Db(); //get User id UserDTO userDTO = db.Users.Where(x => x.Username.Equals(User.Identity.Name)).FirstOrDefault(); int userId = userDTO.Id; //friend ID UserDTO userDTO2 = db.Users.Where(x => x.Username.Equals(friend)).FirstOrDefault(); int friendId = userDTO2.Id; //Add DTO FriendDTO friendDTO = new FriendDTO(); friendDTO.User1 = userId; friendDTO.User2 = friendId; db.Friends.Add(friendDTO); db.SaveChanges(); }
public async Task <IActionResult> GetFriend(long id) { Friend friend = await _context.Friend.FindAsync(id); if (friend == null) { return(NotFound()); } FriendDTO friendDTO = new FriendDTO { Name = friend.Name, FamilyName = friend.FamilyName, PatronymicName = friend.PatronymicName, Telephone = friend.Telephone, TextQRcode = friend.TextQRcode, qrCodeImageAsBase64 = friend.ByteQrcode != null?QRcodeServices.BytecodeQRinStringImageAsBase64(friend.ByteQrcode) : null }; return(Ok(friendDTO)); }
public IActionResult addFriend(FriendDTO friendReq) { string accessToken = Request.Headers["Authorization"]; friendReq.accessToken = accessToken; // Basic API -> Service Cals // Receive Object Through Post/Get Request // Pass Object Too Service Layer // Catch Defined Errors Else Return 2xx Message try { _userService.addFriend(friendReq); return(Ok(friendReq)); } catch (InvalidParametersException e) { return(BadRequest(e.Message)); } catch (DuplicateException e) { return(new BadRequestObjectResult(e.Message)); } return(BadRequest("h")); }
public HttpResponseMessage RemoveFriend(FriendDTO postData) { try { var friend = UserController.GetUserById(PortalSettings.PortalId, postData.FriendId); FriendsController.Instance.DeleteFriend(friend); return Request.CreateResponse(HttpStatusCode.OK, new {Result = "success"}); } catch (Exception exc) { Logger.Error(exc); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } }