Esempio n. 1
0
        public IActionResult Get()
        {
            List <Object> list          = new List <Object>();
            string        usname        = this.HttpContext.Request.Headers["Username"];
            string        isproposition = this.HttpContext.Request.Headers["isProposition"];

            if (usname != null && isproposition == null)
            {
                foreach (var item in _friendsService.GetAllByUser(usname))
                {
                    Entities.User friend = new Entities.User();
                    if (item.username1 != usname)
                    {
                        friend = _userService.GetById(item.User1Id);
                    }
                    else
                    {
                        friend = _userService.GetById(item.User2Id);
                    }

                    list.Add(new UserDto()
                    {
                        CurrentImage = MessageService.GetImgUrlBy(HttpContext.Request.Host.Value, friend.CurrentImage, friend.Username),
                        Username     = friend.Username,
                        FirstName    = friend.FirstName,
                        IsFriend     = true.ToString(),
                        LastName     = friend.LastName
                    });
                }
            }
            else if (isproposition != null)
            {
                foreach (var item in _friendsService.GetAllPropositionByUser(usname))
                {
                    var prop = _userService.GetById(item.OvnUserId);
                    list.Add(new{
                        CurrentImage = MessageService.GetImgUrlBy(HttpContext.Request.Host.Value, prop.CurrentImage, prop.Username),
                        prop.Username,
                        prop.FirstName,
                        prop.LastName,
                        idproposition = item.Id
                    });
                }
            }


            return(Ok(list));
        }