コード例 #1
0
        public IActionResult Delete(int id)
        {
            using (var data = new ServicoData())
                data.Delete(id);

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public IActionResult Create(Servico servico)
        {
            if (!ModelState.IsValid)
            {
                return(View(servico));
            }
            using (var data = new ServicoData())
                data.Create(servico);

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int Id)
        {
            ServicoData         Servico = new ServicoData();
            HttpClient          client  = _api.ListServico();
            HttpResponseMessage res     = await client.GetAsync($"Servico/{Id}");

            if (res.IsSuccessStatusCode)
            {
                var resutlado = res.Content.ReadAsStringAsync().Result;
                Servico = JsonConvert.DeserializeObject <ServicoData>(resutlado);
            }

            return(View(Servico));
        }
コード例 #4
0
        public ActionResult Edit(ServicoData servico)
        {
            HttpClient client = _api.ListServico();
            //http post

            var jsonContent   = JsonConvert.SerializeObject(servico);
            var contentString = new StringContent(jsonContent, Encoding.UTF8, "application/json");

            contentString.Headers.ContentType = new
                                                MediaTypeHeaderValue("application/json");
            // contentString.Headers.Add("Session-Token", session_token);


            var postBack = client.PutAsync($"Servico/{servico.ServicoId}", contentString);

            var resultado = postBack.Result;

            if (resultado.IsSuccessStatusCode)
            {
                return(RedirectToAction("index"));
            }

            return(View());
        }
コード例 #5
0
 public IActionResult Update(int id)
 {
     using (var data = new ServicoData())
         return(View(data.Read(id)));
 }
コード例 #6
0
 public IActionResult Index()
 {
     using (var data = new ServicoData())
         return(View(data.Read()));
 }