Ejemplo n.º 1
0
        // GET: PlantationsStates/Delete/5
        public async Task <IActionResult> Delete(int?id,
                                                 string SortOrder,
                                                 int?KATOIdFilter,
                                                 int?PlantationsStateTypeIdFilter,
                                                 int?PageSize,
                                                 int?PageNumber)
        {
            ViewBag.SortOrder    = SortOrder;
            ViewBag.PageSize     = PageSize;
            ViewBag.PageNumber   = PageNumber;
            ViewBag.KATOIdFilter = KATOIdFilter;
            ViewBag.PlantationsStateTypeIdFilter = PlantationsStateTypeIdFilter;
            if (id == null)
            {
                return(NotFound());
            }

            PlantationsState    plantationsState = null;
            HttpResponseMessage response         = await _HttpApiClient.GetAsync($"api/PlantationsStates/{id.ToString()}");

            if (response.IsSuccessStatusCode)
            {
                plantationsState = await response.Content.ReadAsAsync <PlantationsState>();
            }
            if (plantationsState == null)
            {
                return(NotFound());
            }

            return(View(plantationsState));
        }
        public async Task <IActionResult> PutPlantationsState(int id, PlantationsState plantationsState)
        {
            if (id != plantationsState.Id)
            {
                return(BadRequest());
            }

            _context.Entry(plantationsState).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlantationsStateExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <PlantationsState> > PostPlantationsState(PlantationsState plantationsState)
        {
            _context.PlantationsState.Add(plantationsState);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPlantationsState", new { id = plantationsState.Id }, plantationsState));
        }
Ejemplo n.º 4
0
        // GET: PlantationsStates/Edit/5
        public async Task <IActionResult> Edit(int?id,
                                               string SortOrder,
                                               int?KATOIdFilter,
                                               int?PlantationsStateTypeIdFilter,
                                               int?PageSize,
                                               int?PageNumber)
        {
            ViewBag.SortOrder    = SortOrder;
            ViewBag.PageSize     = PageSize;
            ViewBag.PageNumber   = PageNumber;
            ViewBag.KATOIdFilter = KATOIdFilter;
            ViewBag.PlantationsStateTypeIdFilter = PlantationsStateTypeIdFilter;
            PlantationsState    plantationsState = null;
            HttpResponseMessage response         = await _HttpApiClient.GetAsync($"api/PlantationsStates/{id.ToString()}");

            if (response.IsSuccessStatusCode)
            {
                plantationsState = await response.Content.ReadAsAsync <PlantationsState>();
            }

            List <KATO> KATOes      = new List <KATO>();
            string      urlKATOes   = "api/KATOes",
                        routeKATOes = "";
            HttpResponseMessage responseKATOes = await _HttpApiClient.GetAsync(urlKATOes + routeKATOes);

            if (responseKATOes.IsSuccessStatusCode)
            {
                KATOes = await responseKATOes.Content.ReadAsAsync <List <KATO> >();
            }
            ViewBag.KATOes = new SelectList(KATOes.Where(k => k.ParentEgovId == 17112).OrderBy(m => m.Name), "Id", "Name", plantationsState.KATOId);

            List <PlantationsStateType> plantationsStateTypes = new List <PlantationsStateType>();
            string urlPlantationsStateTypes   = "api/PlantationsStateTypes",
                   routePlantationsStateTypes = "";
            HttpResponseMessage responsePlantationsStateTypes = await _HttpApiClient.GetAsync(urlPlantationsStateTypes + routePlantationsStateTypes);

            if (responsePlantationsStateTypes.IsSuccessStatusCode)
            {
                plantationsStateTypes = await responsePlantationsStateTypes.Content.ReadAsAsync <List <PlantationsStateType> >();
            }
            ViewBag.PlantationsStateTypes = new SelectList(plantationsStateTypes.OrderBy(m => m.Name), "Id", "Name", plantationsState.PlantationsStateTypeId);

            return(View(plantationsState));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,KATOId,PlantationsStateTypeId,TreesNumber")] PlantationsState plantationsState,
                                               string SortOrder,
                                               int?KATOIdFilter,
                                               int?PlantationsStateTypeIdFilter,
                                               int?PageSize,
                                               int?PageNumber)
        {
            ViewBag.SortOrder    = SortOrder;
            ViewBag.PageSize     = PageSize;
            ViewBag.PageNumber   = PageNumber;
            ViewBag.KATOIdFilter = KATOIdFilter;
            ViewBag.PlantationsStateTypeIdFilter = PlantationsStateTypeIdFilter;
            if (id != plantationsState.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                HttpResponseMessage response = await _HttpApiClient.PutAsJsonAsync(
                    $"api/PlantationsStates/{plantationsState.Id}", plantationsState);

                string OutputViewText = await response.Content.ReadAsStringAsync();

                OutputViewText = OutputViewText.Replace("<br>", Environment.NewLine);
                try
                {
                    response.EnsureSuccessStatusCode();
                }
                catch
                {
                    dynamic errors = JsonConvert.DeserializeObject <dynamic>(OutputViewText);
                    foreach (Newtonsoft.Json.Linq.JProperty property in errors.Children())
                    {
                        ModelState.AddModelError(property.Name, property.Value[0].ToString());
                    }
                    return(View(plantationsState));
                }

                plantationsState = await response.Content.ReadAsAsync <PlantationsState>();

                return(RedirectToAction(nameof(Index),
                                        new
                {
                    SortOrder = ViewBag.SortOrder,
                    PageSize = ViewBag.PageSize,
                    PageNumber = ViewBag.PageNumber,
                    KATOIdFilter = ViewBag.KATOIdFilter,
                    PlantationsStateTypeIdFilter = ViewBag.PlantationsStateTypeIdFilter
                }));
            }

            List <KATO> KATOes      = new List <KATO>();
            string      urlKATOes   = "api/KATOes",
                        routeKATOes = "";
            HttpResponseMessage responseKATOes = await _HttpApiClient.GetAsync(urlKATOes + routeKATOes);

            if (responseKATOes.IsSuccessStatusCode)
            {
                KATOes = await responseKATOes.Content.ReadAsAsync <List <KATO> >();
            }
            ViewBag.KATOes = new SelectList(KATOes.Where(k => k.ParentEgovId == 17112).OrderBy(m => m.Name), "Id", "Name", plantationsState.KATOId);

            List <PlantationsStateType> plantationsStateTypes = new List <PlantationsStateType>();
            string urlPlantationsStateTypes   = "api/PlantationsStateTypes",
                   routePlantationsStateTypes = "";
            HttpResponseMessage responsePlantationsStateTypes = await _HttpApiClient.GetAsync(urlPlantationsStateTypes + routePlantationsStateTypes);

            if (responsePlantationsStateTypes.IsSuccessStatusCode)
            {
                plantationsStateTypes = await responsePlantationsStateTypes.Content.ReadAsAsync <List <PlantationsStateType> >();
            }
            ViewBag.PlantationsStateTypes = new SelectList(plantationsStateTypes.OrderBy(m => m.Name), "Id", "Name", plantationsState.PlantationsStateTypeId);

            return(View(plantationsState));
        }