Example #1
0
        /// <summary>
        /// ����ǰ����ת��Ϊ JSON �ַ�����
        /// </summary>
        /// <param name="value">��Ҫ���� JSON ���л��Ķ���</param>
        /// <returns>���л��� JSON �ַ�����</returns>
        public static string SerializeToJson(this object value)
        {
            JsonSerializer serializer = new JsonSerializer()
            {
                DateTimeFormat = JsonHelper.DateTimeFormat,
                EnumFormat = JsonHelper.EnumFormat,
                RegexFormat = JsonHelper.RegexFormat,
                MaxStackLevel = JsonHelper.MaxStackLevel
            };

            string json;

            // �����
            json = serializer.SerializeObject(value);

            // ��ʽ����
            json = FormatJson(json);

            return json;
        }
Example #2
0
 ///<inheritdoc/>
 public void Handle(GetProductsResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
     PageMetadata             = response.Products?.PageMetadata;
 }
 public void Handle(ResetPasswordResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 public void Handle(GetBookByIdResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.NotFound);
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
Example #5
0
        public void Handler(UseCaseResponseMessage response)
        {
            var isValid = response.IsValid();

            ContentResult.StatusCode = (int)(isValid ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
            ContentResult.Content    = isValid ? JsonSerializer.SerializeObject(response) : JsonSerializer.SerializeObject(response.Errors);
        }
        public async Task <ActionResult> UpdateProfileInfo(UpdateProfileInfoRequest request)
        {
            _updateProfileInfoPresenter.HandleResource = r =>
            {
                return(r.Success ? JsonSerializer.SerializeObject(new { r.UpdatedFields }) : JsonSerializer.SerializeObject(new { r.Errors }));
            };
            var user = _authService.GetCurrentUser();
            await _updateProfileInfoUseCase.Handle(
                new UpdateProfileInfoRequest(user, request.FirstName, request.LastName),
                _updateProfileInfoPresenter);

            return(_updateProfileInfoPresenter.ContentResult);
        }
 public static string SerializeObject <T>(this T obj)
 {
     return(JsonSerializer <T> .SerializeObject(obj, Encoding.Default));
 }
 public void Handle(SearchResponse response)
 {
     ContentResult.StatusCode = 200;
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
        public static void AddContent <T>(this HttpRequestMessage message, T item, JsonSerializer serializer)
        {
            var json = serializer.SerializeObject(item);

            message.Content = new StringContent(json, Encoding.UTF8, "application/json");
        }
Example #10
0
 public void Handle(int response)
 {
     ContentResult.StatusCode = (int)HttpStatusCode.OK;
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
 public override void Handle(FindUserResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = JsonSerializer.SerializeObject(new Models.Response.FindUserResponse(response.Id, response.Message, response.User, response.Success, response.Errors));
 }
 public void Handle(DistrictsCoordinatesResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 public void Handle(RemoveBookSubscriptionResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.NotFound);
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
 public override string ToString()
 {
     return(JsonSerializer.SerializeObject(this));
 }
Example #15
0
 public void Handle(AddUserImagesResponse response)
 {
     ContentResult.StatusCode = (int)(response.Errors == null? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = JsonSerializer.SerializeObject(new AddUserImagesResponseDto(response));
 }
        //[AllowAnonymous]
        public ActionResult ProcessCart(string accion, ShippingInformationViewModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            int customerId = !User.Identity.IsAuthenticated ? 0 : Convert.ToInt32((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier.ToString()).Value);
            //var lstItemsSerialized = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()).Value;

            Order order = new Order()
            {
                CustomerId          = customerId,
                ShippingInformation = new ShippingInformation
                {
                    CrediCardType       = model.CrediCardType,
                    CreditCardHolder    = model.CreditCardHolder,
                    CreditCardNumber    = model.CreditCardNumber,
                    CrediCardExpiration = model.CrediCardExpiration,
                    Names           = model.Names,
                    LastNames       = model.LastNames,
                    ShippingAddress = model.ShippingAddress,
                    City            = model.City,
                    State           = model.State,
                    Zip             = model.Zip,
                    Country         = model.Country
                }
            };

            var answerOrder = IoCFactoryBusiness.Resolve <IOrdersService>().ProcessOrder(order);

            if (answerOrder)
            {
                var lstItemsSerialized = JsonSerializer.SerializeObject(new List <Item>());

                //Guardar en memoria
                var claims = new List <Claim>();

                var thumbClaim = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString());
                if (thumbClaim != null)
                {
                    (User.Identity as ClaimsIdentity).RemoveClaim(thumbClaim);
                }
                (User.Identity as ClaimsIdentity).AddClaim(new Claim(ClaimTypes.UserData, lstItemsSerialized));

                claims = (User.Identity as ClaimsIdentity).Claims.ToList();
                var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

                if (User.Identity.IsAuthenticated)
                {
                    AuthenticationManager.SignIn(new AuthenticationProperties()
                    {
                        IsPersistent = false
                    }, id);
                }

                ModelState.AddModelError("mensajeError", "Orden procesada correctamente");
            }
            else
            {
                ModelState.AddModelError("mensajeError", "No se pudo procesar la orden");
            }

            return(View("ShoppingCarts"));
        }
Example #17
0
 public static string ConvertSyncMessageToString(TaskMessage message)
 {
     return(JsonSerializer.SerializeObject <TaskMessage>(message));
 }
Example #18
0
        public static T Post <T>(string command, object postData)
        {
            var jsonString = SendRequest(HttpMethod.Post, command, JsonSerializer.SerializeObject(postData));

            return(JsonSerializer.DeserializeObject <T>(jsonString));
        }
Example #19
0
 public void Response(BlogPostCommentResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.Unauthorized);
     ContentResult.Content = response.Success ? JsonSerializer.SerializeObject(response.Success) : JsonSerializer.SerializeObject(response.Errors);
 }
Example #20
0
 public void Handle(AddCompanyResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = response.Success ? JsonSerializer.SerializeObject(response.Id) : JsonSerializer.SerializeObject(response.Errors);
 }
Example #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 public void Handle(CreateBookSubscriptionReponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
Example #22
0
        /// <summary>
        /// Insert an entity into table
        /// </summary>
        /// <param name="tableName">Table name</param>
        /// <param name="entity">Entity object</param>
        /// <param name="noscript">NoScript flag </param>
        /// <returns>The Id string which was returned by the mobile service</returns>
        public string Insert(string tableName, IMobileServiceEntityData entity, bool noscript = false)
        {
            // build URI
            _finalUri = _mobileServicesUri.AbsoluteUri + "tables/" + tableName;
            if (noscript)
            {
                if (_masterKey == null)
                {
                    throw new ArgumentException("For noscript you must also supply the Master Key");
                }
                _finalUri = _finalUri + "?noscript=true";
            }

            using (var request = (HttpWebRequest)WebRequest.Create(_finalUri))
            {
                //set-up headers
                var headers = new WebHeaderCollection();
                if (_applicationKey != null)
                {
                    headers.Add("X-ZUMO-APPLICATION", _applicationKey);
                }
                if (_masterKey != null)
                {
                    headers.Add("X-ZUMO-MASTER", _masterKey);
                }
                request.Method  = "POST";
                request.Headers = headers;
                request.Accept  = JsonHeader;

                if (entity != null)
                {
                    //serialize the data to upload
                    string serialization = JsonSerializer.SerializeObject(entity);

                    //prepare request
                    byte[] byteData = Encoding.UTF8.GetBytes(serialization);
                    request.ContentLength = byteData.Length;
                    request.ContentType   = JsonHeader;
                    request.UserAgent     = "Micro Framework";

                    using (Stream postStream = request.GetRequestStream())
                    {
                        postStream.Write(
                            byteData,
                            0,
                            byteData.Length
                            );
                    }
                }

                //wait for the response
                using (var response = (HttpWebResponse)request.GetResponse())
                    using (var stream = response.GetResponseStream())
                        using (var reader = new StreamReader(stream))
                        {
                            //Check if you are authorized correctly
                            if (response.StatusCode == HttpStatusCode.Unauthorized)
                            {
                                return("Please check your Application Key");
                            }

                            //Check if the item was successfully created
                            if (response.StatusCode == HttpStatusCode.Created)
                            {
                                //deserialize the received data and return the Id
                                var hashtable = JsonSerializer.DeserializeString(reader.ReadToEnd()) as Hashtable;
                                if (hashtable != null)
                                {
                                    if (hashtable.Contains("id"))
                                    {
                                        return(hashtable["id"].ToString());
                                    }
                                }
                            }

                            //Else return the StatusCode and Description
                            return(response.StatusCode + " " + response.StatusDescription);
                        }
            }
        }
 public override void Handle(LoginResponse response)
 {
     Response = response.Success ? new Models.Response.LoginResponse(response.AccessToken, response.RefreshToken, true, null) : new Models.Response.LoginResponse(null, null, false, response.Errors);
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.Unauthorized);
     ContentResult.Content    = JsonSerializer.SerializeObject(Response);
 }
Example #24
0
 public void Handler(IEnumerable <UseCaseResponseMessage> response)
 {
     ContentResult.StatusCode = (int)HttpStatusCode.OK;
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
 public void Handle(LoginResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.Unauthorized);
     ContentResult.Content    = response.Success ? JsonSerializer.SerializeObject(new Core.Dto.ViewModels.LoginResponse(response.AccessToken, response.RefreshToken)) : JsonSerializer.SerializeObject(response.Errors);
 }
 void IOutputPort <CurrentUserResponse> .Handle(CurrentUserResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
 private async Task Send <T>(T @object, CancellationToken cancellationToken = default)
 {
     var json = JsonSerializer.SerializeObject(@object);
     await webSocketConnector.SendAsync(json, cancellationToken);
 }
Example #28
0
 public void Handle(LoginResponse response)
 {
     ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.Unauthorized);
     ContentResult.Content    = response.Success ? JsonSerializer.SerializeObject(response.Token) : JsonSerializer.SerializeObject(response.Errors);
 }
 public void Handle(LoginResponse response)
 {
     ContentResult.StatusCode = response.Success ? 200 : response.Errors.First().Code;
     ContentResult.Content    = JsonSerializer.SerializeObject(response);
 }
        public ActionResult ShoppingCarts(string action, Customer model)
        {
            //1 validar si no esta autenticado
            //2 Pedir Datos TC y envio
            //3 borrar items de BD

            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (action.Equals("process"))
            {
                Order order = GetOrder();

                if (order.Items.Count() == 0)
                {
                    ModelState.AddModelError("mensajeError", "La orden no tiene productos para procesar");
                    return(View());
                }
                return(RedirectToAction("ProcessCart"));
            }

            if (action.Equals("cancelOrder"))
            {
                Order order = GetOrder();
                if (order.Items.Count() == 0)
                {
                    ModelState.AddModelError("mensajeError", "La orden no tiene productos para cancelar");
                    return(View());
                }

                int customerId = !User.Identity.IsAuthenticated ? 0 : Convert.ToInt32((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier.ToString()).Value);

                var result = IoCFactoryBusiness.Resolve <IItemsService>().DeleteItemsByCustomerId(customerId);

                if (result)
                {
                    var lstItemsSerialized = JsonSerializer.SerializeObject(new List <Item>());

                    //Guardar en memoria
                    var claims = new List <Claim>();

                    var thumbClaim = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString());
                    if (thumbClaim != null)
                    {
                        (User.Identity as ClaimsIdentity).RemoveClaim(thumbClaim);
                    }
                    (User.Identity as ClaimsIdentity).AddClaim(new Claim(ClaimTypes.UserData, lstItemsSerialized));

                    claims = (User.Identity as ClaimsIdentity).Claims.ToList();
                    var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

                    if (User.Identity.IsAuthenticated)
                    {
                        AuthenticationManager.SignIn(new AuthenticationProperties()
                        {
                            IsPersistent = false
                        }, id);
                    }

                    return(RedirectToAction("ShoppingCarts"));
                }
                else
                {
                    ViewData["subtotal"] = order == null ? 0 : order.Items.Sum(itm => itm.Product.ListPrice * itm.Quantity);

                    ModelState.AddModelError("mensajeError", "No se pudo cancelar la orden");
                }
            }

            return(View());
        }
Example #31
0
 public void Handle(Error response)
 {
     ContentResult.StatusCode = response.Code;
     ContentResult.Content    = JsonSerializer.SerializeObject(response.Description);
 }