Example #1
0
        public async Task <ActionResult> Index(unionModel union)
        {
            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(union));
                        content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                        //create union

                        union.active = true;

                        //Sending request to find web api REST service resource GetAllEmployees using HttpClient
                        HttpResponseMessage Res = await client.PostAsync("api/unionModels/", 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("Index"));
                }

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

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

                    union.unionList = new List <unionModel>();

                    //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
                        union.unionList = JsonConvert.DeserializeObject <List <unionModel> >(UnionResponse);
                    }
                }
                return(View(union));
            }

            catch
            {
                return(View(union));
            }
        }
        public IHttpActionResult PutunionsModel(int id, unionModel unionsModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
0
        // GET: Unions
        public async Task <ActionResult> Index()
        {
            unionModel union = new unionModel();


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

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

                union.unionList = new List <unionModel>();

                //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
                    union.unionList = JsonConvert.DeserializeObject <List <unionModel> >(UnionResponse);
                }
            }

            return(View(union));
        }
        public IHttpActionResult GetunionsModel(int id)
        {
            unionModel unionsModel = db.unionsModels.Find(id);

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

            return(Ok(unionsModel));
        }
        public IHttpActionResult PostunionsModel(unionModel unionsModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.unionsModels.Add(unionsModel);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = unionsModel.Id }, unionsModel));
        }
        public IHttpActionResult DeleteunionsModel(int id)
        {
            unionModel unionsModel = db.unionsModels.Find(id);

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

            db.unionsModels.Remove(unionsModel);
            db.SaveChanges();

            return(Ok(unionsModel));
        }
Example #7
0
        public async Task <ActionResult> Edit(int id, unionModel union)
        {
            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(union));
                        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/unionModels/" + 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("Index"));
                }
                else
                {
                    return(View(union));
                }
            }

            catch
            {
                return(RedirectToAction("Index"));
            }
        }
Example #8
0
        public async Task <ActionResult> Edit(int id)
        {
            unionModel UnionInfo = new unionModel();

            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/unionModels/" + 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
                    UnionInfo = JsonConvert.DeserializeObject <unionModel>(EmpResponse);
                }

                return(View(UnionInfo));
            }
        }