public IActionResult Create([FromBody] USAHomeSale homeinfo) { //post to create home from external source if necessary if (homeinfo == null) { return(BadRequest()); } _realEstateContext.USAHomeSales.Add(homeinfo); _realEstateContext.SaveChanges(); return(CreatedAtRoute("GetHome", new { id = homeinfo.id }, homeinfo)); }
public async Task <int> postjson([FromBody] jsonDTO newSalesPost) {///group add for new sales in a JSON format. code duplication with new sales, investigate merging, //jscript in the view template to validate the fields, if every single thing does not match it the body data will show up as null,check //field spelling, whether or not field is nullable,data types etc. if (newSalesPost is null) { throw new ArgumentNullException(nameof(newSalesPost)); } foreach (newsalesDTO newthing in newSalesPost.yup) { USAHomeSale thisSale = new USAHomeSale { address = newthing.address, zipcode = newthing.zipCode, city = newthing.city, state = newthing.state, bedrooms = newthing.bedrooms ?? null, bathrooms = newthing.bathrooms ?? null, squareFootage = newthing.squareFootage ?? null, salesDate = DateTimeOffset.Parse(newthing.salesDate), listingPrice = newthing.listingPrice ?? null, transitScore = newthing.transitScore, finalSalesPrice = newthing.finalSalesPrice, neighborhood = newthing.neighborhood, walk_score = newthing.walk_score, initialPrice = newthing.initialPrice ?? null, placedOnMarketDate = String.IsNullOrEmpty(newthing.placedOnMarketDate) ? (DateTimeOffset?)null : DateTimeOffset.Parse(newthing.placedOnMarketDate) }; _context.USAHomeSales.Add(thisSale); } ; int result = await _context.SaveChangesAsync(); Console.WriteLine(result); return(result); }
public IActionResult Update(string id, [FromBody] USAHomeSale homeinfo) { //update an existing sale if (homeinfo == null || homeinfo.id != id) { return(BadRequest()); } var homesalesinfo = _realEstateContext.USAHomeSales.Find(id); if (homeinfo == null) { return(NotFound()); } homesalesinfo.finalSalesPrice = homeinfo.finalSalesPrice; homesalesinfo.insertionDate = homeinfo.insertionDate; homesalesinfo.listingPrice = homeinfo.listingPrice; homesalesinfo.salesDate = homeinfo.salesDate; _realEstateContext.USAHomeSales.Update(homesalesinfo); _realEstateContext.SaveChanges(); return(NoContent()); }