public FriendshipDto FindFriend(string player_username, string username) { var player = _unitOfWork.PlayerRepository.DbSet.FirstOrDefault(x => x.User.UserName == username); if (player == null) { return(null); } var dto = new FriendshipDto { Id = player.Id, Image = Convert.ToBase64String(player.UserImage), Name = player.Name, Username = player.User.UserName, }; if (!_unitOfWork.FriendshipsRepository.DbSet.Any(x => x.Player.User.UserName == player_username && x.Friend.User.UserName == username) && player_username != username) { dto.ActionType = "add"; } else if (_unitOfWork.FriendshipsRepository.DbSet.Any(x => x.Player.User.UserName == player_username && x.Friend.User.UserName == username) && player_username != username) { dto.ActionType = "remove"; } else { dto.ActionType = "other"; } return(dto); }
public IHttpActionResult PutFriendshipDto(int id, FriendshipDto friendshipDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Friendship friendship = Mapper.Map <FriendshipDto, Friendship>(friendshipDto); if (id != friendshipDto.Id) { return(BadRequest()); } db.Entry(friendship).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FriendshipDtoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task RemoveFriendship(FriendshipDto friendship) { using (var uow = UnitOfWorkProvider.Create()) { friendshipService.Delete(friendship.Id); await uow.Commit(); } }
public async Task ConfirmFriendshipRequest(FriendshipDto friendship) { using (var uow = UnitOfWorkProvider.Create()) { friendship.IsConfirmed = true; await friendshipService.Update(friendship); await uow.Commit(); } }
// PUT: api/Friendships/5 public async Task <string> Put(int id, FriendshipDto entity) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } await FriendshipGenericFacade.UpdateAsync(entity); return($"Updated Friendship with id: {id}"); }
// POST: api/Friendships public async Task <string> Post(FriendshipDto entity) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var postId = await FriendshipGenericFacade.CreateAsync(entity); if (postId.Equals(0)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } return($"Created Friendship with id: {postId}"); }
public async Task <ActionResult> AddFriend(int id) { var user = await BasicUserFacade.GetUserByNickNameAsync(User.Identity.Name); var friendship = new FriendshipDto { User1Id = user.Id, User2Id = id, FriendshipStart = DateTime.Now.ToUniversalTime() }; await FriendshipGenericFacade.CreateAsync(friendship); return(RedirectToAction("Index")); }
public IHttpActionResult PostFriendshipDto(FriendshipDto friendshipDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Friendship friendship = Mapper.Map <FriendshipDto, Friendship>(friendshipDto); db.Friendships.Add(friendship); db.SaveChanges(); Mapper.Map(friendship, friendshipDto); return(CreatedAtRoute("DefaultApi", new { id = friendshipDto.Id }, friendshipDto)); }
public List <FriendshipDto> GetFriendships(List <FriendshipType> friendships) { List <FriendshipDto> friendshipDto = new List <FriendshipDto>(); foreach (FriendshipType friendshipType in friendships) { FriendshipDto dto = new FriendshipDto(); dto.Title = friendshipType.Title; dto.Id = friendshipType.Id; List <UserInfoDto> userInfos = new List <UserInfoDto>(); foreach (Friendship friendship in friendshipType.Friendships) { UserInfoDto userInfo = mapper.FromUserAuthorDto(friendship.Friend); userInfos.Add(userInfo); } dto.Friends = userInfos; friendshipDto.Add(dto); } return(friendshipDto); }
public FriendshipCreatedIntegrationEvent(FriendshipDto friendship) { Friendship = friendship; }
private bool ResolveIsFriendForModel(FriendshipDto friendship) => friendship != null && friendship.IsConfirmed;
private bool ResolveHasPendingFriendRequestForModel(FriendshipDto friendship) => friendship != null && !friendship.IsConfirmed;