Пример #1
0
        public IHttpActionResult GetContacts([FromUri] Guid ownerId)
        {
            if (ownerId == Guid.Empty)
            {
                ModelState.AddModelError($"{nameof(ownerId)}", "Incoming data is null");
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({ownerId})", new ArgumentNullException(nameof(ownerId), "Incoming data is null"));
                return(BadRequest(ModelState));
            }

            var contactInfos = _contactDataProvider.GetAllContactsByOwnerId(ownerId);

            if (contactInfos == null)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({ownerId})", new Exception("Failed to get all contacts"));
                return(NotFound());
            }

            var userInfos = new List <CUserInfo>(contactInfos.Count);

            foreach (var contact in contactInfos)
            {
                var userInfo = _userDataProvider.GetUserData(contact.UserId);
                userInfos.Add(userInfo);
            }

            return(Ok(contactInfos.Select((x, i) => new CContactDto(x.Id, x.OwnerId, x.UserId, x.IsBlocked, new CUserDto(userInfos[i].Login, userInfos[i].LastActiveDate, userInfos[i].ActivityStatus)))));
        }
        public IHttpActionResult GetUserData([FromUri] Guid userId)
        {
            s_log.LogInfo($"{nameof(GetUserData)}({userId}) is called");

            if (userId == default(Guid))
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({userId})", new ArgumentNullException(nameof(userId), "Incoming data is null"));
                ModelState.AddModelError($"{nameof(userId)}", "Incoming data is null");
                return(BadRequest(ModelState));
            }

            var userInfo = _userDataProvider.GetUserData(userId);

            if (userInfo == null)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({userId})", new Exception("Failed to get user data"));
                return(NotFound());
            }

            return(Ok(new CUserDto(userInfo.Login, userInfo.LastActiveDate, userInfo.ActivityStatus)));
        }