Exemple #1
0
        public async Task <IActionResult> Add(Guid friendId)
        {
            try
            {
                _friendService.Add(friendId);

                var message = new CatMessage
                {
                    Type = MessageType.AddFriend,
                    Base = new Base
                    {
                        Sender   = _workContext.CurrentUser.Id.ToString(),
                        Receiver = friendId.ToString(),
                        SendOn   = DateTime.Now.ToString(),
                    }
                };

                var router = await _cacheManager.GetStringAsync($"{CacheKeys.ROUTER}{friendId}");

                _rabbitManager.SendMsg(router, message);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
        public async Task <ActionResult <Result> > Add(FriendDto friendDto)
        {
            var loginId = await GetLoginId();

            var result = await _friendService.Add(friendDto, loginId);

            return(Ok(result));
        }
Exemple #3
0
 public ActionResult AddFriend([FromBody] FriendModel friend)
 {
     try
     {
         _locationService.Add(_mapper.Map <Friend>(friend));
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex));
     }
 }
Exemple #4
0
        public IHttpActionResult Post(FriendViewModel friendVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            friendVM.Id = Guid.NewGuid().ToString();
            _friendService.Add(friendVM);

            return(Ok());
        }
Exemple #5
0
        public IActionResult AcceptFriendRequest(int id)
        {
            string userId;

            try
            {
                userId = User.Claims.First(c => c.Type == "UserID").Value;
            }
            catch
            {
                return(Unauthorized());
            }
            var receiver      = _userService.GetSingleByCondition(s => s.Id == userId, null);
            var friendRequest = _friendRequestService.GetSingleByCondition(s => s.FriendRequestId == id, new string[] { "Sender" });
            var friend        = new Friend()
            {
                ApplicationUser1 = friendRequest.Sender,
                ApplicationUser2 = receiver,
                CreateDate       = DateTime.Now
            };

            if (friendRequest == null)
            {
                return(NotFound());
            }
            if (receiver.Id != userId)
            {
                return(NotFound());
            }
            var notification = new Notification()
            {
                Type       = NotificationType.FriendRequest,
                Sender     = receiver,
                Receiver   = friendRequest.Sender,
                CreateDate = DateTime.Now,
            };

            _notificationService.Add(notification);
            friendRequest.IsAccepted = true;
            _friendService.Add(friend);
            _friendRequestService.SaveChanges();
            return(Ok(friendRequest));
        }
        public void Run()
        {
            string quantityOfFriends = null;
            var    isValidNumber     = false;

            while (isValidNumber == false)
            {
                GetTotalFriends(out quantityOfFriends, out isValidNumber);
            }

            var totalOfFriends = Convert.ToInt32(quantityOfFriends);

            var cont = 0;

            while (totalOfFriends > cont)
            {
                Console.WriteLine($"INFORME O NOME DO SEU AMIGO {cont + 1}:");
                var friend = new Friend {
                    Name = Console.ReadLine()
                };

                var latitude = GetLocation("LATITUDE");
                friend.Location.Latitude = latitude;

                var longitude = GetLocation("LONGITUDE");
                friend.Location.Longitude = longitude;

                var serviceResult = FriendService.Add(friend);
                if (serviceResult.Succeeded == false)
                {
                    Console.WriteLine("ATENÇÃO: DADOS INFORMADOS ESTÃO INCORRETOS. " +
                                      $"ERROS: [{string.Join(", ", serviceResult.Errors.Select(e => e))}] \n");
                    Console.WriteLine("ATENÇÃO: POR FAVOR, INFORME NOVAMENTE \n");
                }
                else
                {
                    cont++;
                }

                Console.WriteLine("\n");
            }
        }
 public IActionResult Add(FriendFormViewModel model)
 {
     _logger.LogInformation("Started method Add");
     _friendService.Add(model);
     return(Ok());
 }
Exemple #8
0
 public Friend Add(Friend friend, Location location)
 {
     location = _locationService.GetByCoordinate(location.X, location.Y);
     return(_friendService.Add(friend, location));
 }
 public void Post([FromBody] Friend friend)
 {
     _friendService.Add(friend);
 }
Exemple #10
0
        public async Task <ActionResult <string> > Post([FromBody] Friend friend)
        {
            DataAccessResponse <string> response = await _service.Add(friend);

            return(HandleResponse(response));
        }