public LocationMove GetById(int id) { LocationMove result = null; using (AppDBContext dbContext = new AppDBContext(_config)) { result = dbContext.LocationMove.Where(a => a.Id == id).AsNoTracking().SingleOrDefault(); } return(result); }
public int Update(LocationMove record) { int result = 0; using (AppDBContext dbContext = new AppDBContext(_config)) { dbContext.Entry(record).State = EntityState.Modified; result = dbContext.SaveChanges(); } return(result); }
public IActionResult Add([FromBody] AddRequestModel requestModel, [FromHeader] string displayLanguage) { var responseModel = new Return <LocationMove>(); responseModel.DisplayLanguage = displayLanguage; try { var record = new LocationMove(); record.CarId = requestModel.CarId; record.LocationId = requestModel.LocationId; record.EntryDate = requestModel.EntryDate; record.ExitDate = requestModel.ExitDate; var dbResult = _locationMoveService.Add(record); if (dbResult > 0) { responseModel.Data = record; // oluşturulan entity bilgisinde id kolonu atanmış olur ve entity geri gönderiliyor responseModel.Status = ResultStatusCodeStatic.Success; responseModel.Message = "Success"; responseModel.Success = true; return(Ok(responseModel)); } else { responseModel.Status = ResultStatusCodeStatic.InternalServerError; responseModel.Message = "Could Not Be Saved"; responseModel.Success = false; ReturnError error = new ReturnError(); error.Key = "500"; error.Message = "Could Not Be Saved"; error.Code = 500; responseModel.Errors = new List <ReturnError>(); responseModel.Errors.Add(error); responseModel.Data = null; //hata oluştugundan dolayı Data null olarak dönülür. return(StatusCode(StatusCodes.Status500InternalServerError, responseModel)); } } catch (Exception ex) { responseModel.Status = ResultStatusCodeStatic.InternalServerError; responseModel.Message = "An error occurred"; responseModel.Success = false; ReturnError error = new ReturnError(); error.Key = "500"; error.Message = ex.Message; error.Code = 500; responseModel.Errors = new List <ReturnError>(); responseModel.Errors.Add(error); responseModel.Data = null; //hata oluştugundan dolayı Data null olarak dönülür. return(StatusCode(StatusCodes.Status500InternalServerError, responseModel)); } }