public IActionResult postSeed([FromBody] SeedDto seedDto) { if (seedDto == null) { return(BadRequest()); } var model = new Seed { SellerID = seedDto.SellerID, Species = seedDto.Species, Brand = seedDto.Brand, Details = seedDto.Details, SeedClass = seedDto.SeedClass, Exhibitions = seedDto.Exhibitions, Name = seedDto.Name, Price = seedDto.Price }; _productRepository.AddSeed(model); if (!_productRepository.Save()) { return(StatusCode(500, "存储失败")); } return(Ok()); }
public IActionResult PatchSeed(int seedid, [FromBody] JsonPatchDocument <SeedDto> jsonPatch) { if (jsonPatch == null) { return(BadRequest()); } var model = _productRepository.GetSeed(seedid); if (model == null) { return(NotFound()); } SeedDto patch = new SeedDto { SellerID = model.SellerID, Species = model.Species, Brand = model.Brand, Details = model.Details, SeedClass = model.SeedClass, Exhibitions = model.Exhibitions, Name = model.Name, Price = model.Price }; jsonPatch.ApplyTo(patch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TryValidateModel(patch); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //SeedID= //SellerID, //species, //Brand, //Details, //Class, //Exhibitions, //Name, //Price model.Species = patch.Species; model.Brand = patch.Brand; model.Details = patch.Details; model.SeedClass = patch.SeedClass; model.Name = patch.Name; model.Price = patch.Price; if (!_productRepository.Save()) { return(StatusCode(500, "更新出错")); } return(NoContent()); }
public void CreateSeed(SeedDto seed) { SeedEntity entity = new SeedEntity() { }; repo.Create(entity); uow.SaveChanges(); }
public IActionResult getSeed(int seedid) { try { if (seedid < 0) { return(BadRequest()); } var model = _productRepository.GetSeed(seedid); if (model == null) { return(StatusCode(500, "获取失败")); } //var list = new List<SeedDto>(); SeedDto seedDto = new SeedDto { SellerID = model.SellerID, Species = model.Species, Brand = model.Brand, Details = model.Details, SeedClass = model.SeedClass, Exhibitions = model.Exhibitions, MakertID = model.MakertID, MakertName = _productRepository.GetSeller(model.SellerID).MarkerName, Name = model.Name, Price = model.Price }; return(Ok(seedDto)); } catch (Exception e) { string s = e + ""; throw; } return(NoContent()); }
public IActionResult PutSeed(int seedid, [FromBody] SeedDto seedDto) { var model = _productRepository.GetSeed(seedid); if (model == null) { return(BadRequest("无数据")); } var modelput = new Seed { SeedID = seedDto.SeedID, SellerID = seedDto.SellerID, Species = seedDto.Species, Brand = seedDto.Brand, Details = seedDto.Details, SeedClass = seedDto.SeedClass, Exhibitions = seedDto.Exhibitions, Name = seedDto.Name, Price = seedDto.Price }; model.Name = modelput.Name; model.Price = modelput.Price; model.SellerID = modelput.SellerID; model.Species = modelput.Species; model.Exhibitions = modelput.Exhibitions; model.Details = modelput.Details; model.Brand = modelput.Brand; model.SeedClass = modelput.SeedClass; if (!_productRepository.Save()) { return(StatusCode(500, "存储失败")); } return(NoContent()); }
public IHttpActionResult Post(SeedDto dto) { manager.CreateSeed(dto); return(Ok()); }