コード例 #1
0
        public IHttpActionResult PuttaxItems(int id, taxItems taxItems)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != taxItems.Id)
            {
                return(BadRequest());
            }

            db.Entry(taxItems).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!taxItemsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public ActionResult TaxItem()
        {
            taxItems taxItem = new taxItems();

            taxItem.activeFrom = DateTime.Today;

            using (var client = new HttpClient())
            {
                setClientSettings(client);

                //Get list of Unions
                var Res = client.GetAsync("api/taxItems").Result;
                taxItem.taxItemList = new List <taxItems>();

                //Checking the response is successful or not which is sent using HttpClient
                if (Res.IsSuccessStatusCode)
                {
                    //Storing the response details recieved from web api
                    var UnionResponse = Res.Content.ReadAsStringAsync().Result;

                    //Deserializing the response recieved from web api and storing into the Employee list
                    taxItem.taxItemList = JsonConvert.DeserializeObject <List <taxItems> >(UnionResponse);
                }
            }

            return(View(taxItem));
        }
コード例 #3
0
        public async Task <ActionResult> TaxItem(taxItems tax)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var client = new HttpClient())
                    {
                        setClientSettings(client);
                        //serialize object to Json and create the HttpContent
                        tax.active = true;
                        HttpContent content = new StringContent(JsonConvert.SerializeObject(tax));
                        content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                        //Sending request to find web api REST service resource GetAllEmployees using HttpClient
                        HttpResponseMessage Res = await client.PostAsync("api/taxItems/", content);

                        //Checking the response is successful or not which is sent using HttpClient
                        if (Res.IsSuccessStatusCode)
                        {
                            //Storing the response details recieved from web api
                            var UnionResponse = Res.Content.ReadAsStringAsync().Result;
                        }

                        ModelState.Clear();
                    }

                    return(RedirectToAction("TaxItem"));
                }

                using (var client = new HttpClient())
                {
                    setClientSettings(client);

                    //Get list of Unions
                    HttpResponseMessage Res = await client.GetAsync("api/taxItems");

                    tax.taxItemList = new List <taxItems>();

                    //Checking the response is successful or not which is sent using HttpClient
                    if (Res.IsSuccessStatusCode)
                    {
                        //Storing the response details recieved from web api
                        var taxResponse = Res.Content.ReadAsStringAsync().Result;

                        //Deserializing the response recieved from web api and storing into the Employee list
                        tax.taxItemList = JsonConvert.DeserializeObject <List <taxItems> >(taxResponse);
                    }
                }

                return(View(tax));
            }

            catch
            {
                return(View(tax));
            }
        }
コード例 #4
0
        public IHttpActionResult GettaxItems(int id)
        {
            taxItems taxItems = db.taxItems.Find(id);

            if (taxItems == null)
            {
                return(NotFound());
            }

            return(Ok(taxItems));
        }
コード例 #5
0
        public IHttpActionResult PosttaxItems(taxItems taxItems)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.taxItems.Add(taxItems);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = taxItems.Id }, taxItems));
        }
コード例 #6
0
        public IHttpActionResult DeletetaxItems(int id)
        {
            taxItems taxItems = db.taxItems.Find(id);

            if (taxItems == null)
            {
                return(NotFound());
            }

            db.taxItems.Remove(taxItems);
            db.SaveChanges();

            return(Ok(taxItems));
        }
コード例 #7
0
        public async Task <ActionResult> TaxItemEdit(int id, taxItems tax)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var client = new HttpClient())
                    {
                        setClientSettings(client);
                        //serialize object to Json and create the HttpContent
                        HttpContent content = new StringContent(JsonConvert.SerializeObject(tax));
                        content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                        //Sending request to find web api REST service resource GetAllEmployees using HttpClient
                        HttpResponseMessage Res = await client.PutAsync("api/taxItems/" + id, content);

                        //Checking the response is successful or not which is sent using HttpClient
                        if (Res.IsSuccessStatusCode)
                        {
                            //Storing the response details recieved from web api
                            var UnionResponse = Res.Content.ReadAsStringAsync().Result;
                        }
                    }

                    ModelState.Clear();
                    return(RedirectToAction("TaxItem"));
                }
                else
                {
                    return(View(tax));
                }
            }

            catch
            {
                return(RedirectToAction("Index"));
            }
        }
コード例 #8
0
        public async Task <ActionResult> TaxItemEdit(int id)
        {
            taxItems tax = new taxItems();

            using (var client = new HttpClient())
            {
                setClientSettings(client);
                //Sending request to find web api REST service resource GetAllEmployees using HttpClient
                HttpResponseMessage Res = await client.GetAsync("api/taxItems/" + id);

                //Checking the response is successful or not which is sent using HttpClient
                if (Res.IsSuccessStatusCode)
                {
                    //Storing the response details recieved from web api
                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;

                    //Deserializing the response recieved from web api and storing into the Employee list
                    tax = JsonConvert.DeserializeObject <taxItems>(EmpResponse);
                }

                return(View(tax));
            }
        }