Exemplo n.º 1
0
        public static bool updatePostRedis(Post item, bool makeOffer)
        {
            try
            {
                string key = "";
                if (item.BuyFromId.GetValueOrDefault() > 0)
                {
                    key = "Post_" + item.BuyFromId + "_" + item.DeliveryToId;
                }
                else
                {
                    key = "Post_onWeb_" + item.CountryId + "_" + item.DeliveryToId;
                }

                var db = GetDatabase();

                var tmp        = db.HashGet(key, item.Id.ToString());
                var modelRedis = PostViewModel.FromJson(tmp);
                var model      = new PostViewModel()
                {
                    Id          = item.Id,
                    Buy_Address = new Address()
                    {
                        Name         = item.BuyFromAddress,
                        City_name    = modelRedis.Buy_Address == null ? "" : modelRedis.Buy_Address.Name,
                        Country_name = modelRedis.Buy_Address == null ? "" : modelRedis.Buy_Address.Country_name,
                        Country_code = modelRedis.Buy_Address == null ? "" : modelRedis.Buy_Address.Country_code,
                    },
                    Delivery_Address = new Address()
                    {
                        Name         = item.DeliveryToAddress,
                        City_name    = modelRedis.Delivery_Address.Name,
                        Country_name = modelRedis.Delivery_Address.Country_name,
                        Country_code = modelRedis.Delivery_Address.Country_code,
                    },
                    DateCreated  = item.DateCreated.GetValueOrDefault().ToString("yyyyMMdd HHmmss"),
                    DateUpdated  = item.DateUpdated.GetValueOrDefault().ToString("yyyyMMdd HHmmss"),
                    Description  = item.Description,
                    Price        = item.Price,
                    ProductName  = item.ProductName,
                    Quantity     = item.Quantity,
                    ShippingFee  = item.ShippingFee,
                    ImageUrl     = modelRedis.ImageUrl,
                    NumberOffer  = (makeOffer == true ? (item.ListOffer.Count + 1) : item.ListOffer.Count),
                    UserAvartar  = modelRedis.UserAvartar,
                    Username     = modelRedis.Username,
                    Nickname     = modelRedis.Nickname,
                    Deposit      = modelRedis.Deposit,
                    DeliveryDate = item.DeliveryDate.GetValueOrDefault().ToString("yyyyMMdd HHmmss"),
                    Mark         = modelRedis.Mark,
                };
                db.HashSet(key, item.Id.ToString(), model.ToJson());
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public static List <PostViewModel> reloadPostRedis(ICityService cityService, IPostService postService, IDatabase db)
        {
            try
            {
                var posts = postService.GetPosts().Where(p => p.IsActive == true).ToList();
                List <PostViewModel> lisResult = new List <PostViewModel>();
                foreach (var item in posts)
                {
                    var city_BuyFrom    = cityService.GetCity(item.BuyFromId.GetValueOrDefault());
                    var city_DeliveryTo = cityService.GetCity(item.DeliveryToId);
                    var tmp             = db.HashGet("Post_" + item.UserId.ToString(), item.Id.ToString());
                    var modelRedis      = PostViewModel.FromJson(tmp);
                    var model           = new PostViewModel()
                    {
                        Id          = item.Id,
                        Buy_Address = new Address()
                        {
                            Name         = item.BuyFromAddress,
                            City_name    = item.BuyFrom.Name,
                            Country_name = item.BuyFrom.Country.Name,
                            Country_code = item.BuyFrom.Country.Code,
                        },
                        Delivery_Address = new Address()
                        {
                            Name         = item.DeliveryToAddress,
                            City_name    = item.DeliveryTo.Name,
                            Country_name = item.DeliveryTo.Country.Name,
                            Country_code = item.DeliveryTo.Country.Code,
                        },
                        DateCreated = item.DateCreated.GetValueOrDefault().ToString("yyyyMMdd HHmmss"),
                        DateUpdated = item.DateUpdated.GetValueOrDefault().ToString("yyyyMMdd HHmmss"),
                        Description = item.Description,
                        Price       = item.Price,
                        ProductName = item.ProductName,
                        Quantity    = item.Quantity,
                        ShippingFee = item.ShippingFee,
                        ImageUrl    = modelRedis.ImageUrl,
                        UserAvartar = modelRedis.UserAvartar,
                        Username    = modelRedis.Username,
                        NumberOffer = item.ListOffer.Count,
                        Nickname    = modelRedis.Nickname,
                    };
                    lisResult.Add(model);
                    db.HashSet("Post_" + item.UserId.ToString(), item.Id.ToString(), model.ToJson());
                }

                return(lisResult);
            }
            catch
            {
                return(null);
            }
        }