public async Task <IActionResult> EditPost(int?id) { if (id == null) { return(NotFound()); } var user = await GetCurrentUserAsync(); var model = new ApartmentIndexData(); var amenityToUpdate = await _context.Amenities.SingleOrDefaultAsync(a => a.AmenityId == id && a.User == user); if (await TryUpdateModelAsync <Amenity>( amenityToUpdate, "", a => a.Type )) { try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(TrackedApartments))); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes."); } } return(View(amenityToUpdate)); }
public async Task <IActionResult> DeleteConfirmedAmenity(int id) { var model = new ApartmentIndexData(); var amenity = await _context.Amenities.SingleOrDefaultAsync(m => m.AmenityId == id); _context.Amenities.Remove(amenity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IActionResult Map(DataTable dataTable) { List <ApartmentIndexData> mapList = new List <ApartmentIndexData>(); foreach (DataRow dr in dataTable.Rows) { ApartmentIndexData MapAddress = new ApartmentIndexData(); var point = MapAddress; MapAddress.Apartment.Latitude = point.Apartment.Latitude; MapAddress.Apartment.Longitude = point.Apartment.Longitude; mapList.Add(MapAddress); } return(View()); }
// GET: Amenities/Delete/5 public async Task <IActionResult> DeleteAmenity(int?id) { if (id == null) { return(NotFound()); } var model = new ApartmentIndexData(); var amenity = await _context.Amenities .SingleOrDefaultAsync(m => m.AmenityId == id); if (amenity == null) { return(NotFound()); } return(View(amenity)); }
public async Task <IActionResult> CreateAmenity([Bind("AmenityId,Type")] ApartmentIndexData amenity) { if (ModelState.IsValid) { var user = await GetCurrentUserAsync(); var model = new ApartmentIndexData(); model.Amenity = await _context.Amenities .SingleOrDefaultAsync(a => a.User == user && a.Type == amenity.Amenity.Type); if (model.Amenity != null) { ViewData["Message"] = "You Have Already Added This Amenity."; return(View(amenity.Amenity)); } _context.Add(amenity.Amenity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(TrackedApartments))); } return(View(amenity.Amenity)); }
// GET: Map public async Task <IActionResult> ApartmentMap(int?id, int?amenityId) { var user = await GetCurrentUserAsync(); var model = new ApartmentIndexData(); model.Apartments = await _context.Apartments .Include(aa => aa.ApartmentAmenities) .ThenInclude(a => a.Amenities) .Where(m => m.User == user) .ToListAsync(); if (id != null) { ViewData["ApartmentId"] = id.Value; Apartment apartment = model.Apartments .Where(a => a.ApartmentId == id.Value) .Single(); model.Amenities = apartment.ApartmentAmenities .Select(a => a.Amenities); } return(View(model)); }
private bool AmenityExists(int id) { var model = new ApartmentIndexData(); return(_context.Amenities.Any(e => e.AmenityId == id)); }