public async Task <IActionResult> UpdateCarBrandAsync(CarBrandInfo carBrandInfo) { try { //判断传过来的值是否存在 if (await dbContext.carBrandInfoRepository.IsExistAsync(carBrandInfo.CarBrandID)) { //找到这条数据 CarBrandInfo brandInfo = await dbContext.carBrandInfoRepository.GetFirstInfo(carBrandInfo.CarBrandID); //修改数据 brandInfo.CarBrandCode = carBrandInfo.CarBrandCode; brandInfo.CarBrandName = carBrandInfo.CarBrandName; brandInfo.CarBrandDescription = carBrandInfo.CarBrandDescription; brandInfo.CreateDate = DateTime.Now; dbContext.carBrandInfoRepository.UpdateInfo(brandInfo); if (await dbContext.carBrandInfoRepository.SaveAsync()) { return(Ok(1)); } } //如果不存在返回错误信息 return(NotFound()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> DeleteCarBrandAsync(int carbrandId) { try { //判断传过来的值是否存在 if (await dbContext.carBrandInfoRepository.IsExistAsync(carbrandId)) { //找到这条数据 CarBrandInfo carBrandInfo = await dbContext.carBrandInfoRepository.GetFirstInfo(carbrandId); //删除找到的这条数据 dbContext.carBrandInfoRepository.DeleteInfo(carBrandInfo); if (await dbContext.carBrandInfoRepository.SaveAsync()) { return(Ok(1)); } } //如果不存在返回错误信息 return(NotFound()); } catch (Exception ex) { throw new Exception(ex.Message); } }
private void LoadData() { int id = GetInt("id"); if (id > 0) { CurrentCarBrand = Cars.Instance.GetCarBrandModel(id, true); txtName.Value = CurrentCarBrand.Name; txtNameIndex.Value = CurrentCarBrand.NameIndex; } }
public async Task <IActionResult> InsertCarBrandAsync(CarBrandInfo carBrandInfo) { try { dbContext.carBrandInfoRepository.CreateInfo(carBrandInfo); if (await dbContext.carBrandInfoRepository.SaveAsync()) { return(Ok(1)); } return(Ok("添加失败")); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> GetFirstCarBrandAsync(int carbrandId) { try { //判断传过来的值是否存在 if (await dbContext.carBrandInfoRepository.IsExistAsync(carbrandId)) { //找到这条数据 CarBrandInfo carBrandInfo = await dbContext.carBrandInfoRepository.GetFirstInfo(carbrandId); return(Ok(carBrandInfo)); } _logger.LogInformation($"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}获取一条车辆品牌信息"); //如果不存在返回错误信息 return(NotFound()); } catch (Exception ex) { throw new Exception(ex.Message); } }
protected void btnSubmit_Click(object sender, EventArgs e) { CarBrandInfo entity = new CarBrandInfo(); int id = GetInt("id"); if (id > 0) { entity = Cars.Instance.GetCarBrandModel(id, true); } FillData(entity); if (id > 0) { Cars.Instance.UpdateCarBrand(entity); } else { Cars.Instance.AddCarBrand(entity); } Cars.Instance.ReloadCarBrandListCache(); Response.Redirect("carbrandmg.aspx"); }
private void FillData(CarBrandInfo entity) { entity.Name = txtName.Value; entity.NameIndex = txtNameIndex.Value; }