Exemplo n.º 1
0
 public async Task <IActionResult> Post([FromBody] ShortFriend friend)
 {
     try
     {
         return(Ok(await _friendService.Create(friend)));
     }
     catch (Exception e)
     {
         return(BadRequest(new { message = e.Message }));
     }
 }
Exemplo n.º 2
0
 public Friends FindByAssociation(ShortFriend friend)
 {
     try
     {
         return(_wargameContext.Friends.SingleOrDefault(x => x.UserId1 == friend.Id1 && x.UserId2 == friend.Id2 || x.UserId1 == friend.Id2 && x.UserId2 == friend.Id1));
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Delete([FromBody] ShortFriend shortFriend)
        {
            Friends friend = _friendService.FindByAssociation(shortFriend);

            if (friend == null)
            {
                return(NotFound());
            }

            if (await _friendService.Delete(friend))
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Put([FromBody] ShortFriend shortFriend)
        {
            Friends friend = _friendService.FindByAssociation(shortFriend);

            if (friend == null)
            {
                return(NotFound());
            }

            try
            {
                FriendsView friendsView = await _friendService.Update(friend);

                return(Ok(friendsView));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("error", e.Message);
                return(new BadRequestObjectResult(ModelState));
            }
        }
Exemplo n.º 5
0
        public async Task <FriendsView> Create(ShortFriend friend)
        {
            try
            {
                Friends friendShip = new Friends()
                {
                    UserId1  = friend.Id1,
                    UserId2  = friend.Id2,
                    Indemand = true
                };
                await _wargameContext.AddAsync(friendShip);

                await _wargameContext.SaveChangesAsync();

                return(_wargameContext.FriendsView.SingleOrDefault(x => x.Id1 == friend.Id1 && x.Id2 == friend.Id2));
            }
            catch (Exception e)
            {
                throw new Exception("Erreur lors de la création de la demande : " + e.Message);
            }
        }