コード例 #1
0
        public IActionResult SaveStore(CreateStoreModel storeModel)
        {
            var sourceStore = storeModel.SourceStoreId > 0 ? _storeService.Get(storeModel.SourceStoreId) : null;

            if (sourceStore == null)
            {
                return(R.Fail.With("error", T("The source store was not found")).Result);
            }

            //get all the saved stores
            //is there any saved store with same domain?
            if (!storeModel.Domain.StartsWith("//"))
            {
                storeModel.Domain = $"//{storeModel.Domain}";
            }

            var savedStore = _storeService.GetByDomain(storeModel.Domain);

            if (savedStore != null)
            {
                return(R.Fail.With("error", T("Another store with same domain already exist")).Result);
            }

            _storeService.CloneStore(sourceStore, storeModel.Name, storeModel.Domain);
            return(R.Success.Result);
        }
コード例 #2
0
ファイル: StoreService.cs プロジェクト: YouenZeng/WeiXinSDK
        /// <summary>
        /// 创建门店。
        /// </summary>
        /// <param name="model">门店模型。</param>
        public void Create(CreateStoreModel model)
        {
            var url  = "http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=" + _accountModel.GetAccessToken();
            var json = JsonConvert.SerializeObject(new
            {
                business = new
                {
                    base_info = model
                }
            });
            var obj     = JObject.Parse(json);
            var baseObj = obj["business"]["base_info"];

            baseObj["photo_list"]  = JArray.Parse(JsonConvert.SerializeObject(model.PhotoList.Select(i => new { photo_url = i })));
            baseObj["offset_type"] = 1;

            WeiXinHttpHelper.PostString(url, Encoding.UTF8.GetBytes(obj.ToString()));
        }
コード例 #3
0
        public async Task <IActionResult> Add([FromBody] CreateStoreModel createStoreModel)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(createStoreModel.Name) ||
                    string.IsNullOrWhiteSpace(createStoreModel.Address))
                {
                    return(BadRequest("Store Name and Address is required!"));
                }

                var getRes = Uow.StoreRepository.Find(x =>
                                                      x.Name == createStoreModel.Name && x.Address == createStoreModel.Address);

                if (getRes != null)
                {
                    return(Conflict("Store with given name nad address already exists!"));
                }

                var addResponse = Uow.StoreRepository.Add(Mapper.Map <Store>(createStoreModel));

                await Uow.CompleteAsync();

                if (addResponse != null)
                {
                    return(Created(Mapper.Map <StoreModel>(addResponse)));
                }


                return(InternalServerError());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(InternalServerError());
            }
        }
コード例 #4
0
ファイル: StoreService.cs プロジェクト: coderen/WeiXinSDK
        /// <summary>
        /// 创建门店。
        /// </summary>
        /// <param name="model">门店模型。</param>
        public void Create(CreateStoreModel model)
        {
            var url = "http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=" + _accountModel.GetAccessToken();
            var json = JsonConvert.SerializeObject(new
            {
                business = new
                {
                    base_info = model
                }
            });
            var obj = JObject.Parse(json);
            var baseObj = obj["business"]["base_info"];
            baseObj["photo_list"] = JArray.Parse(JsonConvert.SerializeObject(model.PhotoList.Select(i => new { photo_url = i })));
            baseObj["offset_type"] = 1;

            WeiXinHttpHelper.PostString(url, Encoding.UTF8.GetBytes(obj.ToString()));
        }