Esempio n. 1
0
        public LoginResponse LoginUser(LoginRequest request)
        {
            string sqlStr = "";
            LoginResponse userResponse = new LoginResponse();
            List<SqlParameter> sqlParam = new List<SqlParameter>();
            DBUtility.AddSqlParam(sqlParam, "@Name", SqlDbType.NVarChar, request.UserName);
            DBUtility.AddSqlParam(sqlParam, "@Password", SqlDbType.NVarChar, request.Password);
            DBUtility.AddSqlParam(sqlParam, "@Route", SqlDbType.NVarChar, request.Route);

            // Identify the route and corresponding credential.
            // If there is a match, then the user is authenticated, return user info.
            switch (request.Route)
            {
                case "0":
                    {
                        sqlStr = "SELECT * FROM USERINFO where Name = @Name and Password = @Password;";
                        break;
                    }
                case "1":
                case "2":
                    {
                        sqlStr = "SELECT USERINFO.* FROM USERINFO, CREDENTIALS " +
                                    "where USERINFO.usr_id = CREDENTIALS.usr_id " +
                                    "and CREDENTIALS.credential_type = @Route and CREDENTIALS.credential_id = @Route;";
                        break;
                    }
                default:
                    {    // Route error
                        throw new ServiceException(ResponseMessages.RES_REG_FAIL_WRONG_ROUTE);
                    }
            }

            try
            {
                DataSet ds = DBUtility.ExecuteDataset(sqlStr, sqlParam);
                if (DBUtility.hasResult(ds))
                {
                    // Serialize the first user returned([0]) from database and send it back.
                    UserInfo user = new UserInfo();

                    // Get user's favorite List
                    List<FavoriteInfo> favList = new List<FavoriteInfo>();
                    user.FavoriteList = favList;

                    DataRow dataRow = ds.Tables[0].Rows[0];
                    user.UserId = dataRow["Id"].ToString();
                    user.UserName = dataRow["Name"].ToString();
                    user.Password = dataRow["Password"].ToString();
                    user.Email = dataRow["Email"].ToString();
                    user.ActivationStatus = dataRow["ActivationStatus"].ToString();
                    user.Level = dataRow["Level"].ToString();
                    user.Coin = dataRow["Coin"].ToString();
                    user.CreatedOn = ((DateTime)dataRow["LastLoginDate"]).ToString(ConfigurationManager.AppSettings["DateFormat"]);
                    user.LastLoginDate = ((DateTime)dataRow["LastLoginDate"]).ToString(ConfigurationManager.AppSettings["DateFormat"]);
                    userResponse.user = user;
                }
                else
                {
                    throw new ServiceException(ResponseMessages.RES_LOGIN_FAIL_NO_USER);
                }
                return userResponse;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 2
0
        public RegistrationResponse RegisterUser(RegistrationRequest request)
        {
            RegistrationResponse resp = new RegistrationResponse();

            // Check repeated users
            List<SqlParameter> sqlParam = new List<SqlParameter>();
            DBUtility.AddSqlParam(sqlParam, "@Name", SqlDbType.NVarChar, request.UserName);

            DataSet ds = DBUtility.ExecuteDataset("Select * from USERINFO where Name = @Name", sqlParam);
            if (DBUtility.hasResult(ds))
            {
                // If a user with the same name provided in the request already exists.
                throw new ServiceException(ResponseMessages.RES_REG_FAIL_USER_EXISTS);
            }
            log.Debug("Creating new user now...");

            sqlParam.Clear();
            DBUtility.AddSqlParam(sqlParam, "@Name", SqlDbType.NVarChar, request.UserName);
            DBUtility.AddSqlParam(sqlParam, "@Password", SqlDbType.NVarChar, request.password);
            DBUtility.AddSqlParam(sqlParam, "@Email", SqlDbType.NVarChar, "");
            DBUtility.AddSqlParam(sqlParam, "@ActivationStatus", SqlDbType.SmallInt, 1);
            DBUtility.AddSqlParam(sqlParam, "@Level", SqlDbType.SmallInt, 1);
            DBUtility.AddSqlParam(sqlParam, "@Coin", SqlDbType.BigInt, 0);
            DBUtility.AddSqlParam(sqlParam, "@CreatedOn", SqlDbType.DateTime, DateTime.Now.ToString(ConfigurationManager.AppSettings["DateFormat"]));
            DBUtility.AddSqlParam(sqlParam, "@LastLoginDate", SqlDbType.DateTime, DateTime.Now.ToString(ConfigurationManager.AppSettings["DateFormat"]));
            DBUtility.AddSqlParam(sqlParam, "@LastModifiedBy", SqlDbType.NVarChar, "System");

            sqlStr = "INSERT INTO USERINFO (Name, Password, Email, ActivationStatus, Level, Coin, CreatedOn, LastLoginDate, LastModifiedBy) VALUES (" +
                "@Name, @Password, @Email, @ActivationStatus, @Level, @Coin, @CreatedOn, @LastLoginDate, @LastModifiedBy);";

            try
            {
                // Send a command to create a user.
                // If this step is done, a user will be created in the database regardless of method the user chose for the registration process.
                log.Debug("Sending command to create user. SQL:" + sqlStr);
                if (DBUtility.ExecuteNonQuery(sqlStr, sqlParam) != 1)
                {
                    throw new ServiceException("Registration failed. Reason: User creation failed.");
                }

                // If registration is successful, get the newest UserInfo.
                UserInfo userInfo = new UserInfo();
                LoginRequest userInfoReq = new LoginRequest();
                userInfoReq.UserName = request.UserName;
                userInfoReq.Password = request.password;
                userInfoReq.Route = request.Route;
                LoginResponse userInfoRes = new LoginResponse();
                userInfoRes = LoginUser(userInfoReq);

                // Takes care of the credentials
                switch (request.Route)
                {
                    case "0":
                        {   // If user is created with a native credential, user registration is done. Return the result and an UserInfo object.
                            // Create a UserInfo Object
                            resp.Result = true;
                            resp.Message = "User successfully created with a native account.";
                            resp.User = userInfoRes.user;
                            return resp;
                        }
                    case "1":   // If user is created with a third party credential, contiune to update the credential in the table CREDENTIALS.
                    case "2":
                        break;
                    default:
                        {    // If the route is unrecognized
                            throw new ServiceException("Registration failed. Reason: Unrecognized route. (b)");
                        }
                }

                sqlParam.Clear();

                // If user is created with a third party credential, update the credential in the table CREDENTIALS.
                string lastest_id = DBUtility.ExecuteDataset("SELECT TOP 1 Id FROM USERINFO ORDER BY Id DESC", new List<SqlParameter>()).Tables[0].Rows[0]["Id"].ToString();
                DBUtility.AddSqlParam(sqlParam, "@UserInfo", SqlDbType.NVarChar, lastest_id);
                DBUtility.AddSqlParam(sqlParam, "@SocialNetwork", SqlDbType.NVarChar, request.Route);
                DBUtility.AddSqlParam(sqlParam, "@Name", SqlDbType.NVarChar, request.UserName);
                string updateCredStr = "INSERT INTO CREDENTIALS (UserInfo, SocialNetwork, Name) VALUES (@UserInfo, @SocialNetwork, @Name);";

                // Send a command to update user's third party credential.
                if (DBUtility.ExecuteNonQuery(updateCredStr, sqlParam) != 1)
                {
                    throw new ServiceException(ResponseMessages.RES_LOGIN_FAIL_TO_UPDATE);
                }

                resp.Result = true;
                resp.Message = ResponseMessages.RES_REG_SUCC_THIRD_PARTY;
                resp.User = userInfoRes.user;
                return resp;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public Response PostRequest(Stream input)
        {
            String postedValue = retrievePostValue(input);
            Request request = new JavaScriptSerializer().Deserialize<Request>(postedValue);
            Response response = new Response();

            String serializedRequestData = new JavaScriptSerializer().Serialize(request.RequestData);
            log.Debug("EnglishRemix2: PostRequest, MethodName:" + request.MethodName + ", TimeStamp:" + request.PostTime + ", RequestData: " + serializedRequestData);

            try
            {
                if (request.MethodName.ToLower().Equals("activation"))
                {
                    DeviceActivationRequest deviceActivationRequest = new JavaScriptSerializer().Deserialize<DeviceActivationRequest>(serializedRequestData);
                    DeviceActivationResponse deviceActivationResponse = new DeviceActivationResponse();
                    deviceActivationResponse = deviceFacade.ActivateDevice(deviceActivationRequest);
                    response.ResponseData = new JavaScriptSerializer().Serialize(deviceActivationResponse);
                    response.HasError = false;
                    systemFacade.Log("0", "1", "1", "activation", 1);
                    return response;
                }

                //use DUID and UID to do the request authantication here
                if (!DeviceValidator.Instance.isValid(request.UserId, request.Udid))
                {
                    response.HasError = true;
                    response.ErrorMsg = ResponseMessages.DEVICE_VALIDATION_FAILED_MESSAGE;
                    response.ResponseData = new JavaScriptSerializer().Serialize(new DeviceValidationResponse());
                    systemFacade.Log("0", "1", "1", "Request authentication failed.", 1);
                    return response;
                }

                // Request Device is activated. Request is authenticated.
                switch (request.MethodName.ToLower())
                {
                    case "register":
                        log.Debug("EnglishRemix2, Action: Register");
                        RegistrationRequest registrationRequest = new JavaScriptSerializer().Deserialize<RegistrationRequest>(serializedRequestData);
                        RegistrationResponse resgitrationResponse = new RegistrationResponse();
                        resgitrationResponse = userFacade.RegisterUser(registrationRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(resgitrationResponse);
                        systemFacade.AddUserAction("0", request.MethodName.ToLower(), registrationRequest.UserName, registrationRequest.password, "0");
                        systemFacade.Log("0", "1", "1", resgitrationResponse.Message, 1);
                        break;
                    case "login":
                        log.Debug("EnglishRemix2, Action: Login");
                        LoginRequest loginRequest = new JavaScriptSerializer().Deserialize<LoginRequest>(serializedRequestData);
                        LoginResponse loginResponse = new LoginResponse();
                        loginResponse = userFacade.LoginUser(loginRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(loginResponse);
                        systemFacade.AddUserAction("0", request.MethodName.ToLower(), loginRequest.UserName, loginRequest.Password, "0");
                        systemFacade.Log("0", "1", "1", "", 1);
                        break;
                    case "getuserachievement":
                        log.Debug("EnglishRemix2, Action: getuserachievement");
                        AchievementRequest achievementRequest = new JavaScriptSerializer().Deserialize<AchievementRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), "0", "0", "0");
                        AchievementResponse achievementResp = userFacade.GetUserAchievement(achievementRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(achievementResp);
                        systemFacade.Log("0", "1", "1", "userachievements", 1);
                        break;
                    case "getallachievements":
                        log.Debug("EnglishRemix2, Action: getallachievement");
                        AchievementResponse achievementResps = userFacade.GetAllAchievements();
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), "0", "0", "0");
                        response.ResponseData = new JavaScriptSerializer().Serialize(achievementResps);
                        systemFacade.Log("0", "1", "1", "allachievements", 1);
                        break;
                    case "getchapter":
                        log.Debug("EnglishRemix2, Action: getChapter, serializedRequestData:" + serializedRequestData);
                        ChapterRequest chapterRequest = new JavaScriptSerializer().Deserialize<ChapterRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), chapterRequest.ChapterNumber.ToString(), "0", "0");
                        ChapterResponse chapterResp = contentFacade.GetChapterByNumber(chapterRequest.ChapterNumber);
                        response.ResponseData = new JavaScriptSerializer().Serialize(chapterResp);
                        systemFacade.Log("0", "1", "1", "getchapter", 1);
                        break;
                    case "getchapterlist":
                        log.Debug("EnglishRemix2, Action: getChapter, serializedRequestData:" + serializedRequestData);
                        ChapterListRequest chapterListRequest = new JavaScriptSerializer().Deserialize<ChapterListRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), "0", "0", "0");
                        ChapterListResponse chapterListResponse = contentFacade.GetChapterList();
                        response.ResponseData = new JavaScriptSerializer().Serialize(chapterListResponse);
                        systemFacade.Log("0", "1", "1", "getchapterlist", 1);
                        break;
                    case "updateactivitystatusbyuser":
                        log.Debug("EnglishRemix2, Action:updateactivitystatusbyuser");
                        UpdateActivityStatusRequest updateActivityStatusRequest = new JavaScriptSerializer().Deserialize<UpdateActivityStatusRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), updateActivityStatusRequest.ActivityId.ToString(), updateActivityStatusRequest.ActivityStatusName, "0");
                        UpdateActivityStatusResponse updateActivityStatusResponse = userFacade.UpdateActivityStatusByUser(updateActivityStatusRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(updateActivityStatusResponse);
                        systemFacade.Log("0", "1", "1", updateActivityStatusResponse.Message, 1);
                        break;
                    case "getuseractivitystatsus":
                        log.Debug("EnglishRemix2, Action: getuseractivitystatus");
                        UserActivityStatusRequest userActivityStatusRequest = new JavaScriptSerializer().Deserialize<UserActivityStatusRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), userActivityStatusRequest.ChapterNumber.ToString(), "0", "0");
                        UserActivityStatusResponse userActivityStatusResp = new UserActivityStatusResponse();
                        userActivityStatusResp = userFacade.GetUserActivityStatus(userActivityStatusRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(userActivityStatusResp);
                        systemFacade.Log("0", "1", "1", "getuseractivitystatus", 1);
                        break;
                    case "allusers":
                        log.Debug("EnglishRemix2, Action: allusers");
                        response.ResponseData = new JavaScriptSerializer().Serialize(userFacade.GetAllUserInfo());
                        systemFacade.Log("0", "1", "1", "allusers", 1);
                        break;
                    case "getuser":
                        log.Debug("EnglishRemix2, Action: getuser");
                        UserRequest userRequest = new JavaScriptSerializer().Deserialize<UserRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), "0", "0", "0");
                        UserResponse userResp = new UserResponse();
                        userResp = userFacade.GetUserInfo(userRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(userResp);
                        systemFacade.Log("0", "1", "1", "getuser", 1);
                        break;
                    case "updateuser":
                        log.Debug("EnglishRemix2, Action: updateUser");
                        UpdateUserRequest updateUserRequest = new JavaScriptSerializer().Deserialize<UpdateUserRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), updateUserRequest.Coin.ToString(), updateUserRequest.Level.ToString(), updateUserRequest.ActivationStatus.ToString());
                        UpdateUserResponse updatedUserResp = new UpdateUserResponse();
                        updatedUserResp = userFacade.UpdateUser(updateUserRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(updatedUserResp);
                        systemFacade.Log("0", "1", "1", updatedUserResp.Message, 1);
                        break;
                    case "updatepassword":
                        log.Debug("EnglishRemix2, Action: updatePassword");
                        UpdatePasswordRequest changePwdRequest = new JavaScriptSerializer().Deserialize<UpdatePasswordRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), "0", "0", "0");
                        UpdatePasswordResponse changePwdResp = new UpdatePasswordResponse();
                        changePwdResp = userFacade.UpdatePassword(changePwdRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(changePwdResp);
                        systemFacade.Log("0", "1", "1", changePwdResp.Message, 1);
                        break;
                    case "purchaseactivity":
                        log.Debug("EnglishRemix2, Action: purchaseactivity");
                        UserActivityRequest purchaseActivityRequest = new JavaScriptSerializer().Deserialize<UserActivityRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), purchaseActivityRequest.ActivityId.ToString(), "0", "0");
                        UserActivityResponse purchaseActivityResp = new UserActivityResponse();
                        purchaseActivityResp = userFacade.PurchaseActivity(purchaseActivityRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(purchaseActivityResp);
                        systemFacade.Log("0", "1", "1", purchaseActivityResp.Message, 1);
                        break;
                    case "adduserfavorite":
                        log.Debug("EnglishRemix2, Action: adduserFavorite");
                        AddFavoriteRequest addFavoriteRequest = new JavaScriptSerializer().Deserialize<AddFavoriteRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), addFavoriteRequest.ChapterNumber.ToString(), addFavoriteRequest.PageNumber.ToString(), "0");
                        AddFavoriteResponse addFavoriteResp = new AddFavoriteResponse();
                        addFavoriteResp = userFacade.AddUserFavourite(addFavoriteRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(addFavoriteResp);
                        systemFacade.Log("0", "1", "1", addFavoriteResp.Message, 1);
                        break;
                    case "getuserfavorite":
                        log.Debug("EnglishRemix2, Action: getuserFavorite");
                        GetFavoriteRequest getUserFavoriteRequest = new JavaScriptSerializer().Deserialize<GetFavoriteRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), "0", "0", "0");
                        GetFavoriteResponse getUserFavoriteResp = new GetFavoriteResponse();
                        getUserFavoriteResp = userFacade.GetUserFavorite(getUserFavoriteRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(getUserFavoriteResp);
                        systemFacade.Log("0", "1", "1", "getuserfavourite", 1);
                        break;
                    case "deleteuserfavorite":
                        log.Debug("EnglishRemix2, Action: deleteUserFavorite, serializeRequesetData: " + serializedRequestData);
                        DeleteFavoriteRequest deleteUserFavoriteRequest = new JavaScriptSerializer().Deserialize<DeleteFavoriteRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), deleteUserFavoriteRequest.ChapterNumber.ToString(), deleteUserFavoriteRequest.PageNumber.ToString(), "0");
                        DeleteFavoriteResponse deleteUserFavoriteResponse = new DeleteFavoriteResponse();
                        deleteUserFavoriteResponse = userFacade.DeleteUserFavorite(deleteUserFavoriteRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(deleteUserFavoriteResponse);
                        systemFacade.Log("0", "1", "1", deleteUserFavoriteResponse.Message, 1);
                        break;
                    case "uploadvideo":
                        log.Debug("EnglishRemix2, Action: uploadvideo");
                        UploadVideoRequest uploadVideoRequest = new JavaScriptSerializer().Deserialize<UploadVideoRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), uploadVideoRequest.ActivityId.ToString(), uploadVideoRequest.ChapterNumber.ToString(), uploadVideoRequest.SelfScore.ToString());
                        UploadVideoResponse uploadVideoResp = new UploadVideoResponse();
                        uploadVideoResp = videoFacade.UploadVideo(uploadVideoRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(uploadVideoResp);
                        systemFacade.Log("0", "1", "1", "uploadvideo", 1);
                        break;
                    case "getuploadedvideolist":
                        log.Debug("EnglishRemix2, Action: getUploadedVideo, serializedRequestData:" + serializedRequestData);
                        VideoListRequest videoListRequest = new JavaScriptSerializer().Deserialize<VideoListRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), videoListRequest.ActivityId.ToString(), videoListRequest.SentenceNumber.ToString(), "0");
                        VideoListResponse videoListResponse = new VideoListResponse();
                        videoListResponse = videoFacade.GetUploadedVideoList(videoListRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(videoListResponse);
                        systemFacade.Log("0", "1", "1", "getloadvideolist", 1);
                        break;
                    case "getuploadedvideobyid":
                        log.Debug("EnglishRemix2, Action: getuploadedvideobyid");
                        GetUploadedVideoRequest getUploadedVideoRequest = new JavaScriptSerializer().Deserialize<GetUploadedVideoRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), getUploadedVideoRequest.VideoId.ToString(), "0", "0");
                        GetUploadedVideoResponse getUploadedVideoResponse = new GetUploadedVideoResponse();
                        getUploadedVideoResponse = videoFacade.GetUploadedVideoById(getUploadedVideoRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(getUploadedVideoResponse);
                        systemFacade.Log("0", "1", "1", "getuploadedvideobyid", 1);
                        break;
                    case "postcomment":
                        log.Debug("EnglishRemix2, Action:postcomment");
                        PostCommentRequest postCommentRequest = new JavaScriptSerializer().Deserialize<PostCommentRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), postCommentRequest.CreatorId.ToString(), postCommentRequest.ToCommentId.ToString(), postCommentRequest.UserVideoId.ToString());
                        PostCommentResponse postCommentResponse = videoFacade.PostComment(postCommentRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(postCommentResponse);
                        systemFacade.Log("0", "1", "1", postCommentResponse.Message, 1);
                        break;
                    case "getcommentbyuploadedvideoid":
                        log.Debug("EnglishRemix2, Action:getcommentbyuploadedvideoid");
                        CommentRequest commentRequest = new JavaScriptSerializer().Deserialize<CommentRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), commentRequest.UploadedVideoId.ToString(), "0", "0");
                        CommentResponse commentResponse = videoFacade.GetCommentByUploadedVideoId(commentRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(commentResponse);
                        systemFacade.Log("0", "1", "1", "allcomments", 1);
                        break;
                    case "rateuploadedvideo":
                        log.Debug("EnglishRemix2, Action:rateuploadedvideo");
                        RateUploadedVideoRequest rateRequest = new JavaScriptSerializer().Deserialize<RateUploadedVideoRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), rateRequest.CreatorId.ToString(), rateRequest.VideoId.ToString(), rateRequest.Score.ToString());
                        RateUploadedVideoResponse rateResponse = videoFacade.RateUploadedVideo(rateRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(rateResponse);
                        systemFacade.Log("0", "1", "1", rateResponse.Message, 1);
                        break;
                    case "getrankingvideo":
                        log.Debug("EnglishRemix2, Action:getrankingvideo");
                        GetRankingVideoRequest getrankingvideorequest = new JavaScriptSerializer().Deserialize<GetRankingVideoRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), getrankingvideorequest.Score.ToString(), getrankingvideorequest.Ranking.ToString(), "0");
                        GetRankingVideoResponse getrankingvideoresponse = videoFacade.GetRankingVideo(getrankingvideorequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(getrankingvideoresponse);
                        systemFacade.Log("0", "1", "1", "rankingvideos", 1);
                        break;
                    case "purchasecoin":
                        log.Debug("EnglishRemix2, Action: purchaseCoin, serializeRequestData: " + serializedRequestData);
                        PurchaseCoinsRequest purchaseCoinRequest = new JavaScriptSerializer().Deserialize<PurchaseCoinsRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), purchaseCoinRequest.PurchasedCoin.ToString(), "0", "0");
                        PurchaseCoinsResponse purhcaseCoinResp = new PurchaseCoinsResponse();
                        purhcaseCoinResp = userFacade.PurchaseCoin(purchaseCoinRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(purhcaseCoinResp);
                        systemFacade.Log("0", "1", "1", "purchasecoin", 1);
                        break;
                    case "getpurchaseproduct":
                        log.Debug("EnglishRemix2, Action: getPurhcaseProduct");
                        PurchaseProductRequest purchaseRequest = new JavaScriptSerializer().Deserialize<PurchaseProductRequest>(serializedRequestData);
                        systemFacade.AddUserAction(request.UserId, request.MethodName.ToLower(), "0", "0", "0");
                        PurchaseProductResponse purchaseResp = new PurchaseProductResponse();
                        purchaseResp = systemFacade.GetPurchaseProduct(purchaseRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(purchaseResp);
                        systemFacade.Log("0", "1", "1", "gerpurchaseproduct", 1);
                        break;
                    case "getuseractionbyid":
                        //for debugging purpose
                        log.Debug("EnglishRemix2, Action: getUserActionById-debugging");
                        GetUserActionRequest getUserActionRequest = new JavaScriptSerializer().Deserialize<GetUserActionRequest>(serializedRequestData);
                        GetUserActionResponse getUserActionResp = new GetUserActionResponse();
                        getUserActionResp = userFacade.GetUserActionById(getUserActionRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(getUserActionResp);
                        systemFacade.Log("0", "1", "1", "getuseractionbyid", 1);
                        break;
                    case "getactiontype":
                        //for debugging purpose
                        log.Debug("EnglishRemix1, Action: getActionType-debugging");
                        ActionTypeRequest actionTypeRequest = new JavaScriptSerializer().Deserialize<ActionTypeRequest>(serializedRequestData);
                        ActionTypeResponse actionTypeResp = new ActionTypeResponse();
                        actionTypeResp = systemFacade.GetActionType(actionTypeRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(actionTypeResp);
                        systemFacade.Log("0", "1", "1", "getactiontype", 1);
                        break;
                    case "adduserachievement":
                        //Add User Achievement
                        log.Debug("EnglishRemix2, Action: addUserAchievement-debugging");
                        AddAchievementRequest addAchievementRequest = new JavaScriptSerializer().Deserialize<AddAchievementRequest>(serializedRequestData);
                        AddAchievementResponse addAchievementResp = new AddAchievementResponse();
                        addAchievementResp = systemFacade.AddUserAchievement(addAchievementRequest);
                        response.ResponseData = new JavaScriptSerializer().Serialize(addAchievementResp);
                        systemFacade.Log("0", "1", "1", "addAchievement", 1);
                        break;
                    default:
                        //To catch the method name wrong input
                        throw new ServiceException("Method name is wrong. Current method name is " + request.MethodName);
                }
            }
            catch (ServiceException e)
            {
                // Catch service exception and return its response to the user.
                response = e.response;

                if (!request.UserId.Equals(""))
                    systemFacade.Log(request.UserId, "1", "1", e.response.ErrorMsg, 1);
                else
                    systemFacade.Log("0", "1", "1", e.response.ErrorMsg, 1);

                return response;
            }
            catch (Exception e)
            {
                // Catch unknown/sql exception
                response.HasError = true;
                response.ErrorMsg = e.ToString();
                if (!request.UserId.Equals(""))
                    systemFacade.Log("0", "1", "1", e.Message, 1);
                else
                    systemFacade.Log("0", "1", "1", e.Message, 1);
                return response;
            }

            response.HasError = false;
            return response;
        }