Exemplo n.º 1
0
        public IActionResult Update(long id, [FromBody] DrivingCentre drivingCentre)
        {
            if (drivingCentre == null || drivingCentre.AddressId != id)
            {
                return(BadRequest());
            }

            var _drivingCentre = _drivingRepository.GetById(id);

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

            _drivingCentre.Number   = drivingCentre.Number;
            _drivingCentre.Street1  = drivingCentre.Street1;
            _drivingCentre.Street2  = drivingCentre.Street2;
            _drivingCentre.Country  = drivingCentre.Country;
            _drivingCentre.Province = drivingCentre.Province;
            _drivingCentre.District = drivingCentre.District;
            _drivingCentre.City     = drivingCentre.City;
            _drivingCentre.ZipCode  = drivingCentre.ZipCode;

            _drivingRepository.Update(_drivingCentre);

            return(new NoContentResult());
        }
Exemplo n.º 2
0
        public IActionResult Create([FromBody] DrivingCentre drivingCentre)
        {
            if (drivingCentre == null)
            {
                return(BadRequest());
            }

            _drivingRepository.Add(drivingCentre);

            return(CreatedAtRoute("GetDrivingCentre", new { id = drivingCentre.AddressId }, drivingCentre));
        }
Exemplo n.º 3
0
        public ActionResult Update(DrivingCentre centre)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:5000/api/drivingcentre");

                //HTTP POST
                var putTask = client.PutAsJsonAsync <DrivingCentre>("drivingcentre", centre);
                putTask.Wait();

                var result = putTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(centre));
        }
Exemplo n.º 4
0
        public ActionResult create(DrivingCentre centre)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:5000/api/drivingcentre");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <DrivingCentre>("drivingcentre", centre);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }

            ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");

            return(View(centre));
        }
Exemplo n.º 5
0
        // GET: Driving/Edit/5
        public ActionResult Update(int id)
        {
            DrivingCentre student = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:5000/api/");
                //HTTP GET
                var responseTask = client.GetAsync("drivingcentre?addressid=" + id.ToString()); //Spelling
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <DrivingCentre>();
                    readTask.Wait();

                    student = readTask.Result;
                }
            }

            return(View(student));
        }
 public void Update(DrivingCentre driving)
 {
     _context.DrivingCentres.Update(driving);
     _context.SaveChanges();
 }
 public void Add(DrivingCentre driving)
 {
     _context.DrivingCentres.Add(driving);
     _context.SaveChanges();
 }