public async Task <ApiResponse> UpdateYard(TblYard tblYard) { _context.Entry(tblYard).State = EntityState.Modified; try { await _context.SaveChangesAsync(); var tblYardlocation = await _context.TblYardLocation.Where(i => i.YardId == tblYard.Id).ToListAsync(); _context.TblYardLocation.RemoveRange(tblYardlocation); await _context.SaveChangesAsync(); TblYardLocation objYardLocation = new TblYardLocation(); objYardLocation.YardId = tblYard.Id; objYardLocation.CountryId = tblYard.CountryId; objYardLocation.LocationDiscription = tblYard.LocationDescription; _context.TblYardLocation.Add(objYardLocation); await _context.SaveChangesAsync(); var ApiResponse = await response.ApiResult("OK", tblYard, "Data Found"); return(ApiResponse); } catch (DbUpdateConcurrencyException ex) { var ApiResponse = await response.ApiResult("FAILED", ex, "Error in update"); return(ApiResponse); } }
public async Task <ApiResponse> AddYard(TblYard tblYard) { _context.TblYard.Add(tblYard); await _context.SaveChangesAsync(); TblYardLocation objYardLocation = new TblYardLocation(); objYardLocation.YardId = tblYard.Id; objYardLocation.CountryId = tblYard.CountryId; objYardLocation.LocationDiscription = tblYard.LocationDescription; _context.TblYardLocation.Add(objYardLocation); await _context.SaveChangesAsync(); var ApiResponse = await response.ApiResult("OK", new { id = tblYard.Id }, "Add Yard"); return(ApiResponse); }