public async Task <IActionResult> AddHouse(USAHomeListing Input, IFormCollection form) { if (!ModelState.IsValid) { return(RedirectToAction("AddHomes")); } var successful = false; Input.TypeOfSale = form["SaleType"]; successful = await _realEstateSalesService.AddHouseAsync(Input); Debug.Write(successful); if (!successful) { return(BadRequest("Could not add House.")); } return(RedirectToAction("AddHomes")); }
public async Task <string> getGroceryAsync(USAHomeListing newItem) { //We will make a GET request to a really cool website... string baseUrl = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=mongolian%20grill&inputtype=textquery&fields=photos,formatted_address,name,opening_hours,rating&locationbias=circle:[email protected],-122.2226413&key=YOUR_API_KEY"; //The 'using' will help to prevent memory leaks. //Create a new instance of HttpClient using (HttpClient client = new HttpClient()) //Setting up the response... using (HttpResponseMessage res = await client.GetAsync(baseUrl)) using (HttpContent content = res.Content) { string data = await content.ReadAsStringAsync(); if (data != null) { return(data); } else { return(null); } // newItem.insertionDate = DateTime.Now; } }
public async Task <int> postjson([FromBody] jsonlistingDTO newListingsPost) {//group add for new listings in a JSON format. code duplication with new sales, investingate merging. if (newListingsPost is null) { throw new ArgumentNullException(nameof(newListingsPost)); } foreach (newlistingDTO newthing in newListingsPost.yup) { USAHomeListing thisListing = new USAHomeListing { Address = newthing.Address, ZipCode = newthing.ZipCode, City = newthing.City, State = newthing.State, Bedrooms = newthing.Bedrooms ?? null, Bathrooms = newthing.Bathrooms ?? null, SquareFootage = newthing.SquareFootage ?? null, initialPrice = newthing.initialPrice ?? null, placedOnMarketDate = String.IsNullOrEmpty(newthing.placedOnMarketDate) ? (DateTimeOffset?)null : DateTimeOffset.Parse(newthing.placedOnMarketDate), insertionDate = DateTimeOffset.Now, Active = true }; _context.USAHomeListings.Add(thisListing); } ; int result = await _context.SaveChangesAsync(); Console.WriteLine(result); return(result); }
public async Task <bool> AddHouseAsync(USAHomeListing newItem) { newItem.insertionDate = DateTime.Now; _context.USAHomeListings.Add(newItem); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }