Exemplo n.º 1
0
        public IActionResult Save([FromBody] HttpNotifySettingDetailViewModel notifySettingBase)
        {
            var result = notifySettingBase.Id != 0
                ? _settingStore.GetById <HttpNotifySetting>(notifySettingBase.Id)
                : new HttpNotifySetting();

            result.Url                = notifySettingBase.Url;
            result.SendType           = notifySettingBase.SendType;
            result.Method             = notifySettingBase.Method;
            result.SendContentType    = notifySettingBase.ContentType;
            result.SubmitDataTemplate = notifySettingBase.SubmitDataTemplate;
            result.RawContentTemplate = notifySettingBase.RawContentTemplate;

            result.RetrySpreadSeconds = notifySettingBase.RetrySpreadSeconds;
            result.MaxRetry           = notifySettingBase.MaxRetry;
            result.MessageType        = notifySettingBase.MessageType;
            try
            {
                _settingStore.SaveOrUpdate(result);
                return(Json(new NotifyResult {
                    Id = result.Id, Success = true
                }));
            }
            catch (NotifySettingException ex)
            {
                return(Json(new NotifyResult {
                    Id = notifySettingBase.Id, Success = false, Message = ex.Message
                }));
            }
        }
Exemplo n.º 2
0
        public void TestSave()
        {
            var client    = new HttpMessageSettingClient(_factory.CreateClient());
            var viewModel = new HttpNotifySettingDetailViewModel
            {
                MessageType = Guid.NewGuid().ToString("N"),
                Url         = "http://localhost:5000/WeatherForecast",
                Method      = HttpNotifyMessageMethod.POST
            };

            viewModel.SubmitDataTemplate.Add(new Variable
            {
                Name  = "a1",
                Value = "固定值"
            });

            viewModel.SubmitDataTemplate.Add(new Variable
            {
                Name  = "a2",
                Value = "被修正值"
            });
            var result = client.Save(viewModel);


            Assert.True(result.Success);
        }
        public NotifyResult Save(HttpNotifySettingDetailViewModel setting)
        {
            var str         = JsonConvert.SerializeObject(setting);
            var content     = new StringContent(str, Encoding.UTF8, "application/json");
            var response    = GetClient().PostAsync(Path + "/save", content).Result;
            var responseStr = response.Content.ReadAsStringAsync().Result;

            if (response.IsSuccessStatusCode)
            {
                var result = JsonConvert.DeserializeObject <NotifyResult>(responseStr);

                return(result);
            }
            throw new Exception("Exception from server:" + responseStr);
        }