public IHttpActionResult GetChatsOfUser(int id, int?page = null, int pageSize = 10)
        {
            Logger.log.Debug("at ChatController.GetChatsOfUser");
            IQueryable <UserServiceReference.ChatDTO> chats = null;

            if (!this.CheckUserIdAcces(id))
            {
                Logger.log.Error("at ChatController.GetChatsOfUser - User request denied");
                return(new Forbidden("User cannot look at other chats!"));
            }

            using (var client = SoapProvider.GetUserServiceClient())
            {
                chats = client.GetChatsOfUser(id).AsQueryable();
            }

            if (chats == null)
            {
                Logger.log.Error("at ChatController.GetChatsOfUser - Error at database");
                return(InternalServerError());
            }

            var data = this.ApplyPaging(chats, page.Value, pageSize, "GetChatsOfUser");

            return(Ok(chats));
        }
示例#2
0
        public IHttpActionResult UpdateProfile(int id, [FromBody] UserInfoDTO dto)
        {
            Logger.log.Debug("at UserController.UpdateProfile");
            dto.Id = id;

            if (!this.CheckUserIdAcces(id))
            {
                Logger.log.Error("at UserController.UpdateProfile - User request denied");
                return(new Forbidden("User cannot modify other profile!"));
            }

            using (var client = SoapProvider.GetUserServiceClient())
            {
                try
                {
                    var result = client.UpdateUser(dto);
                    if (!result.Result)
                    {
                        Logger.log.Error("at UserController.UpdateProfile - " + result.Info);
                        return(BadRequest((string)result.Info));
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.ToString()));
                }
            }

            return(Ok());
        }
示例#3
0
        public IHttpActionResult GetWayBetweenUsers(int id1, int id2, int?page = null, int pageSize = 10)
        {
            Logger.log.Debug("at UserController.GetWayBetweenUsers");
            IQueryable <UserInfoDTO> friends = null;

            if (!this.CheckUserIdAcces(id1))
            {
                Logger.log.Error("at UserController.GetWayBetweenUsers - User request denied");
                return(new Forbidden("User cannot look at other friens way!"));
            }

            using (var client = SoapProvider.GetUserServiceClient())
            {
                friends = SoapProvider.GetUserServiceClient().GetWayBetweenUsers(id1, id2).AsQueryable();
            }

            if (friends == null)
            {
                Logger.log.Error("at UserController.GetWayBetweenUsers - Error at database");
                return(InternalServerError());
            }

            var data = this.ApplyPaging(friends, page.Value, pageSize, "GetWayBetweenUsers");

            return(Ok(data));
        }
示例#4
0
        public IHttpActionResult DeleteAccount(int id)
        {
            Logger.log.Debug("at AccountController.DeleteAccount");

            if (!this.CheckUserIdAcces(id))
            {
                Logger.log.Error("at AccountController.DeleteAccount - User request denied");
                return(new Forbidden("User cannot modify other profile!"));
            }

            using (var client = SoapProvider.GetUserServiceClient())
            {
                try
                {
                    var result = client.DeleteUser(id);
                    if (!result.Result)
                    {
                        Logger.log.Error("at AccountController.DeleteAccount - " + result.Info);
                        return(BadRequest((string)result.Info));
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.ToString()));
                }
            }

            return(Ok());
        }
示例#5
0
        public IHttpActionResult GetUserById(int id)
        {
            Logger.log.Debug("at UserController.GetUserById");
            UserInfoDTO user = null;

            using (var client = SoapProvider.GetUserServiceClient())
            {
                user = client.GetUserById(id);
            }

            if (user == null)
            {
                Logger.log.Error("at UserController.GetUserById - Error at database");
                return(InternalServerError());
            }

            return(Ok(user));
        }
示例#6
0
        public IHttpActionResult GetUserFriends(int id, int?page = null, int pageSize = 10)
        {
            Logger.log.Debug("at UserController.GetUserFriends");
            IQueryable <UserInfoDTO> friends = null;

            using (var client = SoapProvider.GetUserServiceClient())
            {
                friends = SoapProvider.GetUserServiceClient().GetUserFriends(id).AsQueryable();
            }

            if (friends == null)
            {
                Logger.log.Error("at UserController.GetUserFriends - Error at database");
                return(InternalServerError());
            }
            var data = this.ApplyPaging(friends, page.Value, pageSize, "GetUserFriends");

            return(Ok(data));
        }
示例#7
0
        public IHttpActionResult GetUserByAccountName(string name)
        {
            Logger.log.Debug("at AccountController.GetUserByAccountName");
            UserInfoDTO user = null;

            using (var client = SoapProvider.GetUserServiceClient())
            {
                user = client.GetAllUsers()
                       .AsQueryable()
                       .Where(item => item.UserName == name)
                       .ToList()
                       .Single();
            }

            if (user == null)
            {
                Logger.log.Error("at AccountController.GetUserByAccountName - Error at database");
                return(BadRequest("User not found"));
            }

            return(Ok(user));
        }
示例#8
0
        public IHttpActionResult Register(AccountDTO dto)
        {
            Logger.log.Debug("at AccountController.Register");

            if (!ModelState.IsValid)
            {
                Logger.log.Error("at AccountController.Register - Bad model state");
                return(BadRequest(ModelState));
            }

            OperationResultDTO result = null;

            using (var client = SoapProvider.GetUserServiceClient())
            {
                try
                {
                    if (client.FindUserByUserName(dto.UserName) != null)
                    {
                        return(BadRequest("User with this name is loginned"));
                    }

                    result = client.AddAccount(dto);
                    if (!result.Result)
                    {
                        Logger.log.Error("at AccountController.Register - " + result.Info);
                        return(BadRequest((string)result.Info));
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.ToString()));
                }
            }

            return(Ok((int)result.Info));
        }