public IActionResult Post([FromBody] CountyDTO model) { County county; try { county = _mapper.Map <County>(model); } catch { return(BadRequest("No Mapping")); } try { _repo.Add(county); } catch { return(BadRequest("No Save")); } var newUri = Url.Link("Get", new { id = county.Id }); return(Created(newUri, _mapper.Map <CountyDTO>(county))); }
public IActionResult Counties() { var gcpCounty = new CountyDTO() { CountyList = context.Counties.ToList() }; return(View(gcpCounty)); }
public IActionResult CountyEdit(int id) { var countydata = new CountyDTO() { CountyList = context.Counties.ToList(), CountyData = context.Counties.FirstOrDefault(a => a.CountyID == id) }; return(View("Counties", countydata)); }
public IActionResult Put(int id, [FromBody] CountyDTO model) { try { var beforeObject = _repo.Counties(id); if (beforeObject == null) { return(NotFound()); } _mapper.Map(model, beforeObject); _repo.Update(beforeObject); return(Ok(_mapper.Map <CountyDTO>(beforeObject))); } catch { return(BadRequest()); } }
public IActionResult Counties(CountyDTO County) { if (County.CountyData.CountyID == 0) { context.Counties.Add(County.CountyData); } else { County dbEntry = context.Counties .FirstOrDefault(p => p.CountyID == County.CountyData.CountyID); if (dbEntry != null) { dbEntry.CountyName = County.CountyData.CountyName; dbEntry.CountyState = County.CountyData.CountyState; } } context.SaveChanges(); return(RedirectToAction("Counties")); }