public async Task <ActionResult> DeleteConfirmed(int id)
        {
            FacilityInFlat facilityInFlat = await db.FacilityInFlats.FindAsync(id);

            db.FacilityInFlats.Remove(facilityInFlat);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ID,FlatId,FacilityId")] FacilityInFlat facilityInFlat)
        {
            if (ModelState.IsValid)
            {
                db.Entry(facilityInFlat).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.FacilityId = new SelectList(db.Facilities, "ID", "Type", facilityInFlat.FacilityId);
            ViewBag.FlatId     = new SelectList(db.Flats, "ID", "Country", facilityInFlat.FlatId);
            return(View(facilityInFlat));
        }
        // GET: FacilityInFlats/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FacilityInFlat facilityInFlat = await db.FacilityInFlats.FindAsync(id);

            if (facilityInFlat == null)
            {
                return(HttpNotFound());
            }
            return(View(facilityInFlat));
        }
        // GET: FacilityInFlats/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FacilityInFlat facilityInFlat = await db.FacilityInFlats.FindAsync(id);

            if (facilityInFlat == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FacilityId = new SelectList(db.Facilities, "ID", "Type", facilityInFlat.FacilityId);
            ViewBag.FlatId     = new SelectList(db.Flats, "ID", "Country", facilityInFlat.FlatId);
            return(View(facilityInFlat));
        }
        // GET: FacilityInFlats/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            string userId = User.Identity.GetUserId();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FacilityInFlat facilityInFlat = await db.FacilityInFlats.FindAsync(id);

            if (facilityInFlat == null)
            {
                return(HttpNotFound());
            }
            return(View(facilityInFlat));
        }
        public async Task <ActionResult> Create([Bind(Include = "ID,FlatId,FacilityId")] FacilityInFlat facilityInFlat)
        {
            string userId = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                db.FacilityInFlats.Add(facilityInFlat);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.FacilityId = new SelectList(db.Facilities, "ID", "Type", facilityInFlat.FacilityId);

            var flats = db.Flats.Where(id => id.OwnerId == userId).ToList();

            ViewBag.FlatId = new SelectList(flats, "ID", "FlatName", facilityInFlat.FlatId);
            return(View(facilityInFlat));
        }