public async Task <IActionResult> Index()
        {
            var user = await GetCurrentUserAsync();

            var userId = user?.Id;

            List <ShopViewModel> shops;
            WebRequest           request = WebRequest.Create(_configuration.GetValue <string>("BackendUrl") + "api/shop/" + userId);

            request.Method = "Get";

            using (var s = request.GetResponse().GetResponseStream())
            {
                using (var sr = new StreamReader(s))
                {
                    var contributorsAsJson = sr.ReadToEnd();
                    shops = JsonConvert.DeserializeObject <List <ShopViewModel> >(contributorsAsJson);
                }
            }

            ShopInfoViewModel model = new ShopInfoViewModel {
                userId = userId, shops = shops
            };

            return(View(model));
        }
        public IActionResult ShopInfo()
        {
            ShopInfoViewModel model = new ShopInfoViewModel();
            string            id    = getID();

            if (id == null)
            {
                return(Redirect("/Login/Login"));
            }
            Shop myshop = ShopManager.myShop(id)[0];

            model.shopID        = myshop.shopID;
            model.name          = myshop.shopName;
            model.intro         = myshop.shopIntroduction;
            model.items         = ShopManager.getItems(myshop.shopID);
            model.Icon          = myshop.shopIcon;
            model.IconPath      = ImageManager.saveShopIcon(model.Icon);
            model.itemImagePath = ImageManager.saveItemImage(model.items);
            return(View(model));
        }
Example #3
0
        public MessageViewModel Update([FromBody] ShopInfoViewModel shopInfo)
        {
            if (shopInfo == null)
            {
                return new MessageViewModel {
                           Code = MessageCode.ParamsError, Message = "店铺信息为空!"
                }
            }
            ;

            ShopInfo shopInfoEntity = shopInfoBusiness.GetById(this.CurrentAuthShopId());

            if (shopInfoEntity == null)
            {
                return new MessageViewModel {
                           Code = MessageCode.ParamsError, Message = "找不到指定店铺!"
                }
            }
            ;

            if (!string.IsNullOrEmpty(shopInfo.Name))
            {
                if (shopInfo.Name.Length > 50)
                {
                    return new MessageViewModel {
                               Code = MessageCode.ParamsError, Message = "店铺名称最多允许50个字!"
                    }
                }
                ;
                else
                {
                    shopInfoEntity.Name = shopInfo.Name;
                }
            }

            if (!string.IsNullOrEmpty(shopInfo.ShopDesc))
            {
                if (shopInfo.ShopDesc.Length > 250)
                {
                    return new MessageViewModel {
                               Code = MessageCode.ParamsError, Message = "店铺描述最多允许250个字!"
                    }
                }
                ;
                else
                {
                    shopInfoEntity.ShopDesc = shopInfo.ShopDesc;
                }
            }

            if (!string.IsNullOrEmpty(shopInfo.OpeningHours))
            {
                if (shopInfo.OpeningHours.Length > 50)
                {
                    return new MessageViewModel {
                               Code = MessageCode.ParamsError, Message = "营业时间描述最多允许50个字!"
                    }
                }
                ;
                else
                {
                    shopInfoEntity.OpeningHours = shopInfo.OpeningHours;
                }
            }

            if (!string.IsNullOrEmpty(shopInfo.Address))
            {
                if (shopInfo.Address.Length > 100)
                {
                    return new MessageViewModel {
                               Code = MessageCode.ParamsError, Message = "店铺地址最多允许100个字!"
                    }
                }
                ;
                else
                {
                    shopInfoEntity.Address = shopInfo.Address;
                }
            }

            if (!string.IsNullOrEmpty(shopInfo.LinkPhone))
            {
                if (shopInfo.LinkPhone.Length > 30)
                {
                    return new MessageViewModel {
                               Code = MessageCode.ParamsError, Message = "联系电话最多允许30个字!"
                    }
                }
                ;
                else
                {
                    shopInfoEntity.LinkPhone = shopInfo.LinkPhone;
                }
            }

            if (!string.IsNullOrEmpty(shopInfo.QQ))
            {
                if (shopInfo.QQ.Length > 30)
                {
                    return new MessageViewModel {
                               Code = MessageCode.ParamsError, Message = "QQ最多允许30个字!"
                    }
                }
                ;
                else
                {
                    shopInfoEntity.QQ = shopInfo.LinkPhone;
                }
            }

            if (!string.IsNullOrEmpty(shopInfo.WeChat))
            {
                if (shopInfo.WeChat.Length > 30)
                {
                    return new MessageViewModel {
                               Code = MessageCode.ParamsError, Message = "微信最多允许30个字!"
                    }
                }
                ;
                else
                {
                    shopInfoEntity.WeChat = shopInfo.LinkPhone;
                }
            }

            shopInfoBusiness.Update(shopInfoEntity);
            return(new MessageViewModel {
                Code = MessageCode.Success, Message = "修改成功!"
            });
        }
    }
}