public async Task <RentalShop> UpdateRentalShop(RentalShop ShopChanges) { var Shop = context.Shops.Attach(ShopChanges); Shop.State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.SaveChanges(); return(await context.Shops.FindAsync(ShopChanges.ID)); }
//Rental Shops public async Task <RentalShop> AddRentalShop(RentalShop rentalShop) { context.Shops.Add(rentalShop); await context.SaveChangesAsync(); var RentalShop = await context.Shops.OrderByDescending(s => s.ID).FirstOrDefaultAsync(); return(RentalShop); }
public async Task <bool> AddRentalShop(RentalShop rentalShop) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseURL); HttpResponseMessage res = await client.PostAsJsonAsync("api/RentalShops", rentalShop); return(res.IsSuccessStatusCode); } }
public async Task <bool> UpdateRentalShop(RentalShop ShopChanges) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseURL); HttpResponseMessage res = await client.PutAsJsonAsync($"api/RentalShops/UpdateRentalShop/{ShopChanges.ID}", ShopChanges); return(res.IsSuccessStatusCode); } }
public async Task <ActionResult> Create(RentalShop rentalShop) { bool added = await Repository.AddRentalShop(rentalShop); if (added == false) { return(View()); } return(RedirectToAction("Index")); }
public async Task <ActionResult <RentalShop> > PutRentalShop(int id, RentalShop rentalShop) { if (id != rentalShop.ID) { return(BadRequest()); } if (!Repository.RentalShopExists(id)) { return(NoContent()); } return(await Repository.UpdateRentalShop(rentalShop)); }
public async Task <RentalShop> GetRentalShopByID(int id) { RentalShop rentalShop = new RentalShop(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseURL); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage res = await client.GetAsync($"api/RentalShops/GetRentalShopByID/{id}"); if (res.IsSuccessStatusCode) { var response = res.Content.ReadAsStringAsync().Result; rentalShop = JsonConvert.DeserializeObject <RentalShop>(response); } } return(rentalShop); }
public async Task <ActionResult <RentalShop> > PostRentalShop(RentalShop rentalShop) { return(await Repository.AddRentalShop(rentalShop)); }
public async Task <ActionResult> Details(int id) { RentalShop rentalShop = await Repository.GetRentalShopByID(id); return(View(rentalShop)); }
public async Task <ActionResult> Edit(RentalShop rentalShop) { await Repository.UpdateRentalShop(rentalShop); return(RedirectToAction("Index")); }
public IActionResult Create() { RentalShop rentalShop = new RentalShop(); return(View(rentalShop)); }