Пример #1
0
        public async Task <IActionResult> PutFarmZone(int id, FarmZone farmZone)
        {
            if (id != farmZone.ZoneId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #2
0
        public async Task <ActionResult <FarmZone> > PostFarmZone(FarmZone farmZone)
        {
            _context.FarmZone.Add(farmZone);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFarmZone", new { id = farmZone.ZoneId }, farmZone));
        }
Пример #3
0
        public async Task <ActionResult> Create(FarmZone zone)
        {
            string json = JsonConvert.SerializeObject(zone);

            using (var content = new StringContent
                                     (json, Encoding.UTF8, "application/json"))
            {
                HttpResponseMessage result =
                    await _httpClient.PostAsync("http://localhost:5005/api/farmzones/", content);

                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }

            ModelState.AddModelError("", "Error while creating data.");
            return(View());
        }