public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] HousingCooperative housingCooperative) { if (id != housingCooperative.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(housingCooperative); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HousingCooperativeExists(housingCooperative.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(housingCooperative)); }
public IActionResult Seed() { _context.Apartments.RemoveRange(_context.Apartments); _context.HousingCooperatives.RemoveRange(_context.HousingCooperatives); var hc1 = new HousingCooperative { Name = "HSB Brf-Karlavagnen", Description = "Vi är en aktiv Bostadsrätt förening med god ekonomi. Vi finns i området Molnvädersgatan – Önskevädersgatan" }; var hc2 = new HousingCooperative { Name = "Brf Skanstorget", Description = "Bostadsrättsföreningen Skanstorget i Göteborg är belägen i centrala Göteborg med Linné, Haga och Vasastan som grannar." }; _context.Apartments.Add(new Apartment { ApartmentNumber = 3, HousingCooperative = hc2, OperatingCost = 2300, Price = 2200000, Rent = 1800, Size = 75, Rooms = 3 }); _context.Apartments.Add(new Apartment { ApartmentNumber = 1, HousingCooperative = hc1, OperatingCost = 1800, Price = 2000000, Rent = 3400, Size = 47, Rooms = 2.5M }); _context.Apartments.Add(new Apartment { ApartmentNumber = 2, HousingCooperative = hc1, OperatingCost = 1975, Price = 2500000, Rent = 3800, Size = 53, Rooms = 3 }); _context.SaveChanges(); ViewData["Message"] = "Seeding done"; return(View("Index")); }
public async Task <IActionResult> Create([Bind("Id,Name,Description")] HousingCooperative housingCooperative) { if (ModelState.IsValid) { _context.Add(housingCooperative); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(housingCooperative)); }
private async Task <ResponseObject> HousingCooperativesLookupAsync(HousingCooperativesJsonResponseModel housingCooperativesData) { var housingCooperatives = new List <HousingCooperative>(); foreach (var item in housingCooperativesData.Items) { if (string.IsNullOrEmpty(item.Uuid)) { Query housingCooperativesQuery = collection .WhereEqualTo("streetName", item.Vejnavn) .WhereEqualTo("streetBuildingIdentifier", item.Husnummer) .WhereEqualTo("postCodeIdentifier", item.Postnummer) .WhereEqualTo("floorIdentifier", item.Etage) .WhereEqualTo("sideDoor", item.Side); QuerySnapshot housingCooperativesSnapshot = await housingCooperativesQuery.GetSnapshotAsync(); if (housingCooperativesSnapshot.Count > 0) { foreach (var i in housingCooperativesSnapshot.Documents) { housingCooperatives.Add(i.ConvertTo <HousingCooperative>()); } } else { var newHousingCooperative = new HousingCooperative() { MunicipalityCode = item.Kommunenummer, StreetName = item.Vejnavn, StreetCode = item.Vejkode, StreetBuildingIdentifier = item.Husnummer, PostCodeIdentifier = item.Postnummer, DistrictName = item.Kommunenavn, FloorIdentifier = item.Etage, SuiteIdentifier = item.Side }; housingCooperatives.Add(newHousingCooperative); await collection.Document().SetAsync(newHousingCooperative); } } else { var newHousingCooperativeUuid = item.Uuid; var document = await collection.Document(newHousingCooperativeUuid).GetSnapshotAsync(); if (document.Exists) { housingCooperatives.Add(document.ConvertTo <HousingCooperative>()); } else { string bulletinUri = $"https://www.tinglysning.dk/tinglysning/ssl/andelsbolig/andelsbolig/{newHousingCooperativeUuid}"; string newHousingCooperativeDataXml = HttpWebHandler.DoSSLGet(bulletinUri); var newHousingCooperativeData = XmlSerializerHelper <AndelSummariskHentResultat> .Deserialaize(newHousingCooperativeDataXml); if (newHousingCooperativeData != null) { var newHousingCooperative = new HousingCooperative() { Uuid = newHousingCooperativeUuid, MunicipalityCode = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AndelIdentifikator.MunicipalityCode, StreetName = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AdresseStruktur.StreetName, StreetCode = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AndelIdentifikator.StreetCode, StreetBuildingIdentifier = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AndelIdentifikator.StreetBuildingIdentifier, PostCodeIdentifier = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AdresseStruktur.PostCodeIdentifier, DistrictName = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AdresseStruktur.DistrictName, FloorIdentifier = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AndelIdentifikator.FloorIdentifier, SuiteIdentifier = newHousingCooperativeData.AndelSummarisk.AndelStamoplysninger.AndelIdentifikator.SideDoerTekst }; await collection.Document(newHousingCooperativeUuid).SetAsync(newHousingCooperative); housingCooperatives.Add(newHousingCooperative); } } } } return(new ResponseObject() { ResponseStatus = housingCooperatives.Count > 0 ? ResponseStatus.OK : ResponseStatus.NOT_FOUND, Content = JsonConvert.SerializeObject(housingCooperatives) }); }