public static (KuhmunityResponse response, string sessionTicket, UserDetailDTO userDetail) Login(
            string ApiUrl,
            string campaignID,
            string email,
            string password,
            string isPersistentCookie,
            string sessionTicket,
            UserDetailDTO userDetail)
        {
            KuhmunityResponse response = new KuhmunityResponse
            {
                IsSuccessful = false
            };

            var KuhmunityViewModel = new
            {
                campaignID,
                email,
                password,
                isPersistentCookie
            };

            using (var client = new WebClient())
            {
                try
                {
                    var data = JsonConvert.SerializeObject(KuhmunityViewModel);
                    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                    var apiResponse = client.UploadString(new Uri(ApiUrl + "Login?output=json"), "POST", data);

                    if (!string.IsNullOrWhiteSpace(apiResponse))
                    {
                        var receivedData = JsonConvert.DeserializeObject <UserLoginResultDTO>(apiResponse);
                        if (receivedData.Status.Equals("OK"))
                        {
                            response.IsSuccessful = true;
                            response.Body         = receivedData.UserDetailDTO;
                            userDetail            = receivedData.UserDetailDTO;
                            sessionTicket         = receivedData.SessionTicket;
                        }
                        else
                        {
                            response.Message = receivedData.Status;
                        }
                    }

                    return(response, sessionTicket, userDetail);
                }
                catch (Exception ex)
                {
                    response.Message      = ResponseMessages.SERVER_ERROR;
                    response.ErrorMessage = ex.Message;

                    return(response, sessionTicket, userDetail);
                }
            }
        }
Ejemplo n.º 2
0
        public static KuhmunityResponse Register(
            string apiUrl,
            UserRegisterInput kuhmunityProfileData)
        {
            KuhmunityResponse response = new KuhmunityResponse
            {
                IsSuccessful = false
            };

            using (var client = new WebClient())
            {
                try
                {
                    var data = JsonConvert.SerializeObject(kuhmunityProfileData);
                    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                    var apiResponse = client.UploadString(new Uri(apiUrl + "Register?output=json"), "POST", data);

                    if (!string.IsNullOrWhiteSpace(apiResponse))
                    {
                        var receivedData = JsonConvert.DeserializeObject <UserResultDTO>(apiResponse);
                        if (receivedData.Status.Equals("OK"))
                        {
                            response.IsSuccessful = true;
                            response.Body         = receivedData.UserId;
                        }
                        else
                        {
                            response.Message = receivedData.Status;
                        }
                    }

                    return(response);
                }
                catch (Exception ex)
                {
                    response.Message      = ResponseMessages.SERVER_ERROR;
                    response.ErrorMessage = ex.Message;

                    return(response);
                }
            }
        }