public async Task <IActionResult> Edit(int id, [Bind("Id,DateOfEviction,EvictionNotice,Lease,Verified,Notes,TenantId,AddressId,PreparerId")] EvictionInfo evictionInfo) { if (id != evictionInfo.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(evictionInfo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EvictionInfoExists(evictionInfo.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(evictionInfo)); }
public async Task <IActionResult> Create([Bind("Id,DateOfEviction,EvictionNotice,Lease,Verified,Notes,TenantId,AddressId,PreparerId")] EvictionInfo evictionInfo) { if (ModelState.IsValid) { _context.Add(evictionInfo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(evictionInfo)); }
public async Task NewTenantAsync([FromBody] CompleteTenantEvictionInfo info) { TenantInfo tenantInfo = info.TenantInfo; AddressInfo addressInfo = info.AddressInfo; EvictionInfo evictionInfo = info.EvictionInfo; PreparerInfo preparerInfo = info.PreparerInfo; // Null-check for all required fields if (tenantInfo == null || addressInfo == null || evictionInfo == null) { // don't insert anything } if (tenantInfo.Name == null || tenantInfo.Email == null || addressInfo.StreetAddress == null || addressInfo.City == null || addressInfo.County == null || addressInfo.ZipCode == 0 || evictionInfo.DateOfEviction == null) { // don't insert anything } try { _dbContext.DBTenantInfo.Add(tenantInfo); await _dbContext.SaveChangesAsync(); } // the only exception we should be getting here is the duplicate insertion - on which we just swallow the exception // we take care of the nulls above // rest we assume that the data is in correct format catch (Exception) { // swallow it } try { if (addressInfo.Latitude != 0.0D && addressInfo.Longitude != 0.0D) { string key = "keygoeshere"; string address = addressInfo.StreetAddress + addressInfo.City + addressInfo.ZipCode; Uri geoReqUri = new Uri(string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}", address, key)); var client = new HttpClient(); var responseTask = await client.GetAsync(geoReqUri); string responseString = await responseTask.Content.ReadAsStringAsync(); var coordinates = JObject.Parse(responseString)["resourceSets"][0]["resources"][0]["point"]["coordinates"].Children().ToList(); addressInfo.Latitude = coordinates[0].ToObject <double>(); addressInfo.Longitude = coordinates[1].ToObject <double>(); } _dbContext.DBAddressInfo.Add(addressInfo); await _dbContext.SaveChangesAsync(); } catch (Exception) { } // Get TenantId and AddressId var tenantId = _dbContext.DBTenantInfo .Where(t => t.Name == tenantInfo.Name && t.Email == tenantInfo.Email) .Select(t => t.Id) .FirstOrDefault(); var addressId = _dbContext.DBAddressInfo .Where(a => a.StreetAddress == addressInfo.StreetAddress && a.ZipCode == addressInfo.ZipCode) .Select(a => a.Id) .FirstOrDefault(); evictionInfo.AddressId = addressId; evictionInfo.TenantId = tenantId; if (preparerInfo != null && preparerInfo.Name != null && preparerInfo.Organization != null) { try { _dbContext.DBPreparerInfo.Add(preparerInfo); await _dbContext.SaveChangesAsync(); var preparerId = _dbContext.DBPreparerInfo .Where(p => p.Name == preparerInfo.Name && p.Organization == preparerInfo.Organization) .Select(p => p.Id) .FirstOrDefault(); evictionInfo.PreparerId = preparerInfo.Id; } catch (Exception) { } } try { _dbContext.DBEvictionInfo.Add(evictionInfo); await _dbContext.SaveChangesAsync(); } catch (Exception) { } }
public async Task UpdateEviction([FromBody] EvictionInfo info) { _dbContext.DBEvictionInfo.Update(info); await _dbContext.SaveChangesAsync(); }