public async Task <IActionResult> Create([Bind("ID,Name,Product,Quantity,SellDate,Price,ProductID")] Clients clients) { if (ModelState.IsValid) { _context.Add(clients); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(clients)); }
public async Task <IActionResult> AddOrEdit([Bind("KlijentID,Vlasnik,Ljubimac,Vrsta,Adresa")] Clients clients) { if (ModelState.IsValid) { if (clients.KlijentID == 0) { _context.Add(clients); } else { _context.Update(clients); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(clients)); }
public async Task <IActionResult> PostClientAsync([FromBody] Client client) { var response = new SingleResponse <Client>(); try { _context.Clients.Add(client); await _context.SaveChangesAsync(); response.Model = CreatedAtAction(nameof(GetClientByIdAsync), new { id = client.Id }, client).Value as Client; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.ToString(); } return(response.ToHttpResponse()); }
public async Task <IActionResult> PostServiceAsync([FromBody] Service service) { var response = new SingleResponse <Service>(); try { _context.Services.Add(service); await _context.SaveChangesAsync(); response.Model = CreatedAtAction(nameof(GetServiceByIdAsync), new { id = service.Id }, service).Value as Service; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.ToString(); } return(response.ToHttpResponse()); }
public async Task <IActionResult> PostServiceCountryAsync([FromBody] ServiceCountry serviceCountry) { var response = new Response(); try { _context.ServiceCountries.Add(serviceCountry); await _context.SaveChangesAsync(); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.ToString(); } return(response.ToHttpResponse()); }
public async Task <IActionResult> PostCountryAsync([FromBody] Country country) { var response = new SingleResponse <Country>(); try { _context.Countries.Add(country); await _context.SaveChangesAsync(); response.Model = CreatedAtAction(nameof(GetCountryByIdAsync), new { id = country.Id }, country).Value as Country; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.ToString(); } return(response.ToHttpResponse()); }
public async Task <IActionResult> RestoreDatabaseAsync() { var response = new Response(); try { _context.Database.ExecuteSqlCommand("delete from clients;" + "delete from services;" + "delete from countries;" + "delete from ServiceCountries;"); await _context.SaveChangesAsync(); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.ToString(); } return(response.ToHttpResponse()); }
public async Task SaveChangesAsync() { await _clientsContext.SaveChangesAsync().ConfigureAwait(false); }