public CarServiceType InsertServiceType(CarServiceType carServicetype) { var insertCar = _sparkDbContext.CarServiceTypes.Add(carServicetype); _sparkDbContext.SaveChanges(); return(carServicetype); }
public CarServiceType EditServiceType(int id, CarServiceType carServiceType) { var servicetype = _sparkDbContext.CarServiceTypes.Where(e => e.Id == carServiceType.Id).FirstOrDefault(); servicetype.Name = carServiceType.Name; servicetype.Price = carServiceType.Price; _sparkDbContext.SaveChanges(); return(servicetype); }
public async Task <IActionResult> DeleteServiceType(int id) { var results = new CarServiceType(); using (HttpClient client = new HttpClient()) { using (var response = await client.DeleteAsync($"{apiUrl}/{id}")) { var apiResponse = await response.Content.ReadAsStringAsync(); results = JsonConvert.DeserializeObject <CarServiceType>(apiResponse); } } return(RedirectToAction("GetServiceType")); }
public async Task <IActionResult> Create(CarServiceType carServiceType) { var resService = new CarServiceType(); using (var client = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(carServiceType), Encoding.UTF8, "application/json"); using (var response = await client.PostAsync(apiUrl, content)) { var apiResponse = await response.Content.ReadAsStringAsync(); resService = JsonConvert.DeserializeObject <CarServiceType>(apiResponse); } } return(RedirectToAction("GetServiceType")); }
public async Task <IActionResult> EditServiceType(int id) { var carService = new CarServiceType(); using (HttpClient client = new HttpClient()) { //using (var response = await client.GetAsync("https://localhost:44330/api/Character")) using (var response = await client.GetAsync($"{apiUrl}/{id}")) { var apiResponse = await response.Content.ReadAsStringAsync(); carService = JsonConvert.DeserializeObject <CarServiceType>(apiResponse); } } return(View(carService)); }
public async Task <IActionResult> EditServiceType(int id, CarServiceType carServ) { var rescharacter = new CarServiceType(); using (var client = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(carServ), Encoding.UTF8, "application/json"); using (var response = await client.PutAsync($"{apiUrl}/{id}", content)) { var apiResponse = await response.Content.ReadAsStringAsync(); rescharacter = JsonConvert.DeserializeObject <CarServiceType>(apiResponse); } } return(RedirectToAction("GetServiceType")); }
public async Task <IActionResult> GetServiceTypeById(int id) { var results = new CarServiceType(); using (HttpClient client = new HttpClient()) { using (var response = await client.GetAsync($"{apiUrl}/{id}")) { if (response.StatusCode == HttpStatusCode.OK) { var apiResponse = await response.Content.ReadAsStringAsync(); results = JsonConvert.DeserializeObject <CarServiceType>(apiResponse); } else { var noResponse = response.StatusCode.ToString(); return(View(noResponse)); } } } return(View(results)); }
public IActionResult InsertServiceType(CarServiceType carServiceType) { var insert = _serviceTypeRepository.InsertServiceType(carServiceType); return(Ok(insert)); }
public IActionResult UpdateServiceType(int id, CarServiceType carServiceType) { var resUpdate = _serviceTypeRepository.EditServiceType(id, carServiceType); return(Ok(resUpdate)); }