public ActionResult Create([Bind(Include = "Id,Title,OwnerId,Address,Description,LocationId,MaxOccupancy,PriceperNight")] House house) { ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); var UserManagers = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var AuthManager = HttpContext.GetOwinContext().Authentication; if (User.IsInRole("Renter")) { UserManagers.RemoveFromRole(user.Id, "Renter"); UserManagers.AddToRole(user.Id, "Owner"); AuthManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie); } // house.Owner = user; // house.OwnerId = user.Id; if (ModelState.IsValid) { db.Houses.Add(house); db.SaveChanges(); return(RedirectToAction("MyTrip", "Home")); } List <House> list = new List <House> { }; list.Add(house); ViewBag.LocationId = new SelectList(db.Locations, "Id", "NameCity", house.LocationId); UserHousesViewModel ViewModel = new UserHousesViewModel { User = user, Houses = list }; return(View(ViewModel)); }
// GET: Houses/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } House house = db.Houses.Find(id); if (house == null) { return(HttpNotFound()); } ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); List <House> list = new List <House> { }; var Images = db.HouseImages.ToList(); list.Add(house); UserHousesViewModel ViewModel = new UserHousesViewModel { User = user, Houses = list, HouseImages = Images }; return(View(ViewModel)); }
// GET: Houses/Create public ActionResult Create() { ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); House ase = new House(); List <House> list = new List <House> { }; list.Add(ase) ; UserHousesViewModel ViewModel = new UserHousesViewModel { User = user, Houses = list }; ViewBag.LocationId = new SelectList(db.Locations, "Id", "NameCity"); return(View(ViewModel)); }
public ActionResult MyTrip() { ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); var MyHouses = db.Houses.Where(v => v.Owner.Id == user.Id); var Images = db.HouseImages.ToList(); //List<string> paths = new List<string>(); //foreach(House item in MyHouses) {paths.Add(Images.) } //var Reservations = db.Reservations.Where(b=>b.) UserHousesViewModel Myall = new UserHousesViewModel() { User = user, Houses = MyHouses.ToList(), HouseImages = Images }; return(View(Myall)); }
public ActionResult Create([Bind(Include = "Id,Title,Owner,OwnerId,Address,Description,LocationId,MaxOccupancy,PriceperNight")] House house) { ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); if (ModelState.IsValid) { db.Houses.Add(house); db.SaveChanges(); return(RedirectToAction("Index")); } List <House> list = new List <House> { }; list.Add(house); ViewBag.LocationId = new SelectList(db.Locations, "Id", "NameCity", house.LocationId); UserHousesViewModel ViewModel = new UserHousesViewModel { User = user, Houses = list }; return(View(ViewModel)); }