Beispiel #1
0
        public bool DeleteArticle(int articleId, ISystemResponse error)
        {
            bool deleted = false;

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("articleId", articleId.ToString());
                string request = WebAPIClient.DeleteRequest("Articles", "", error, parameters);

                if (!string.IsNullOrEmpty(request) && !error.Error)
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    BasicResponseModel   response   = serializer.Deserialize <BasicResponseModel>(request);

                    if (response != null && !error.Error)
                    {
                        deleted = response.success;
                    }
                }
            }
            catch (Exception ex)
            {
                error.Error     = true;
                error.Message   = "No fue posible eliminar";
                error.Exception = ex;
            }

            return(deleted);
        }
        /// <summary>
        /// With this you can delete an SMS that has been set with a timestamp to send at some point in the future. The timestamp has to be greater than 10 minutes from delete time. You must have set a reference on the SMS to be able to delete it. Every SMS with the specified reference that meets the criteria will bee deleted</summary>
        /// <param name="reference">The identifier set by you, when you posted the SMS.</param>
        /// <returns></returns>
        public BasicResponseModel DeleteSms(string reference)
        {
            var responseModel = new BasicResponseModel();

            try
            {
                var json =
                    JsonConvert.SerializeObject(
                        _deleteRequestModelFactory.BuildDeleteRequestModel(reference),
                        new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                int httpStatusCode;
                var responseJson   = ExecuteRequest(Encoding.UTF8, json, Endpoints.SmsDeleteUrl, out httpStatusCode, "DELETE");
                var responseObject = JsonConvert.DeserializeObject <BasicResponseModel>(responseJson);
                responseObject.HttpStatusCode = httpStatusCode;
                return(responseObject);
            }
            catch (WebException we)
            {
                responseModel.Exception      = we;
                responseModel.HttpStatusCode = ((HttpWebResponse)we.Response).GetHttpStatusCode();
            }
            catch (Exception e)
            {
                responseModel.Exception = e;
            }
            return(responseModel);
        }
Beispiel #3
0
        public bool CreateArticle(Article article, ISystemResponse error)
        {
            bool created = false;

            try
            {
                string request = WebAPIClient.PostRequest("Articles", "", article, error, new Dictionary <string, string>());

                if (!string.IsNullOrEmpty(request) && !error.Error)
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    BasicResponseModel   response   = serializer.Deserialize <BasicResponseModel>(request);

                    if (response != null && !error.Error)
                    {
                        created = response.success;
                    }
                }
            }
            catch (Exception ex)
            {
                error.Error     = true;
                error.Message   = "No fue posible crear el articulo";
                error.Exception = ex;
            }

            return(created);
        }
Beispiel #4
0
        public BasicResponseModel HandleEvent(string sessionId, string operate, ShipmentEventRequest request)
        {
            var response = new BasicResponseModel();

            if (!AllowOperates.Contains(operate))
            {
                response.Code    = ShipmentErrorCode.InvalidShipmentOperate;
                response.Message = "非法操作";
                return(response);
            }

            var alctResponse = shipmentAgent.HandleShipmentEvent(GetToken(sessionId).AccessToken, operate, request.ToALCTOperation());

            if (alctResponse == null)
            {
                response.Code    = ShipmentErrorCode.ShipmentOperationFailed;
                response.Message = "操作失败,请重试";
            }
            else if (alctResponse.Code == "1")
            {
                response.Code    = ShipmentErrorCode.ShipmentOperationFailed;
                response.Message = "操作失败,请重试";
            }
            else if (alctResponse.Code == "2")
            {
                response.Code    = ShipmentErrorCode.ShipmentOperationFailed;
                response.Message = "操作失败,请刷新后重试";
            }
            else if (alctResponse.Code == "0")
            {
                response.Code    = 0;
                response.Message = "操作成功";
            }
            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// This creates a group for contacts.
        /// </summary>
        /// <param name="groupId">Id of the group the contact is to be placed in.</param>
        /// <param name="phoneNumber">The phone number for the contact starting with country code.</param>
        /// <param name="contactName">Name/ identifier of the contact.</param>
        /// <returns></returns>
        public BasicResponseModel CreateGroup(int groupId, string phoneNumber, string contactName = null)
        {
            var responseModel = new BasicResponseModel();

            try
            {
                var json =
                    JsonConvert.SerializeObject(
                        _contactRequestModelFactory.BuildContactRequestModel(groupId, phoneNumber, contactName),
                        new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                int httpStatusCode;
                var responseJson   = ExecuteRequest(Encoding.UTF8, json, Endpoints.ContactCreate, out httpStatusCode);
                var responseObject = JsonConvert.DeserializeObject <BasicResponseModel>(responseJson);
                responseObject.HttpStatusCode = httpStatusCode;
                return(responseObject);
            }
            catch (WebException we)
            {
                responseModel.Exception      = we;
                responseModel.HttpStatusCode = ((HttpWebResponse)we.Response).GetHttpStatusCode();
            }
            catch (Exception e)
            {
                responseModel.Exception = e;
            }
            return(responseModel);
        }
Beispiel #6
0
        public bool UpdateStore(StoreModel store, ISystemResponse error)
        {
            bool updated = false;

            try
            {
                string request = WebAPIClient.PutRequest("Stores", "", store, error, new Dictionary <string, string>());

                if (!string.IsNullOrEmpty(request) && !error.Error)
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    BasicResponseModel   response   = serializer.Deserialize <BasicResponseModel>(request);

                    if (response != null && !error.Error)
                    {
                        updated = response.success;
                    }
                }
            }
            catch (Exception ex)
            {
                error.Error     = true;
                error.Message   = "No fue posible actualizar la tienda";
                error.Exception = ex;
            }

            return(updated);
        }
        public BasicResponseModel SendVerificationCode(string phoneNumber)
        {
            var response = new BasicResponseModel();

            try
            {
                var alctResponse = authenticationAgent.SendVerificationCode(phoneNumber, GetApiToken().AccessToken);
                if (alctResponse.Code == "0")
                {
                    response.Code    = 0;
                    response.Message = "验证码发送成功";
                }
                else if (alctResponse.Code == AuthenticationErrorCode.AccessTokenInvalid.ToString())
                {
                    response.Code    = AuthenticationErrorCode.AccessTokenInvalid;
                    response.Message = alctResponse.Message;
                }
                else
                {
                    response.Code    = AuthenticationErrorCode.PhoneNumberInvalid;
                    response.Message = "手机号码不存在,请检查后重试";
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Send verification failed");
                response.Code    = AuthenticationErrorCode.SystemUnhandledException;
                response.Message = "验证码发送失败";
            }

            return(response);
        }
        protected bool CheckSessionId()
        {
            var sessionId = GetSessionId();

            if (string.IsNullOrEmpty(sessionId))
            {
                response         = new BasicResponseModel();
                response.Code    = 401;
                response.Message = "请退出小程序后重新进入操作";
                return(false);
            }
            else
            {
                var token = basicBusinessLogic.GetToken(sessionId);
                if (token == null)
                {
                    response         = new BasicResponseModel();
                    response.Code    = 401;
                    response.Message = "请退出小程序后重新进入操作";
                    return(false);
                }
            }
            return(true);
        }