public ActionResult Edit(AccountHotelViewModel model) { //var zh = _dbzh.Hotel.Find(id); //var us = _dbus.Hotel.Find() var ZHmodel = _dbzh.Hotel.Find(model.ID); //var USmodel = _dbus.Hotel.Find(model.ID); var Manager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var u = Manager.FindById(ZHmodel.UserId).UserName; model.Facilies = (model.HotelFacility == null || model.HotelFacility.Count <= 0) ? string.Empty : string.Join(",", model.HotelFacility); //var GameSite = string.Empty; //if (Request["GameSite"] != null) //{ // GameSite = Request["GameSite"].ToString(); //} model.Game = (model.GameSite == null || model.GameSite.Count <= 0) ? string.Empty : string.Join(",", model.GameSite); model.Edit(); //return View("Edit", new {id=model.ID}); //var model = new AccountHotelViewModel(); //model.Account = u; //model.Addressus = USmodel.Address; //model.Addresszh = ZHmodel.Address; //model.Area = ZHmodel.Area; //model.Featureus = USmodel.Features; //model.Featurezh = ZHmodel.Features; //model.Tel = ZHmodel.Tel; //model.Nameus = USmodel.Name; //model.Namezh = ZHmodel.Name; //model.LinkUrl = ZHmodel.LinkUrl; //var sessionkey = Guid.NewGuid().GetHashCode().ToString("x"); //ViewBag.ImgKey = sessionkey; //var Imgs = _basedb.ImageStore.Where(o => o.ReferIdZH == ZHmodel.ID && o.Type == "Hotel").Select(o => new ImageViewModel //{ // ReferIdZH = o.ReferIdZH.Value, // Extension = o.Extension, // Image = o.Image, // Name = o.Name, // SessionKey = sessionkey, // Type = o.Type //}).ToList(); //Session[sessionkey] = Imgs; ////model.Facilies = //var Facilies = ZHmodel.Facilities.Split(',').Select(int.Parse).ToList(); //var GameSite = ZHmodel.Game.Split(',').Select(int.Parse).ToList(); //ViewBag.HotelFacility = new Facilities().Facility("zh",Facilies); //ViewBag.GameSites = new GameSiteModel().SelectList(GameSite); //ViewBag.City = new GameSiteModel().Citys(ZHmodel.City); return(RedirectToAction("Edit", new { id = model.ID })); }
public ActionResult MyHotel(int id) { var ZHmodel = _dbzh.Hotel.Find(id); if (ZHmodel == null) { return(RedirectToAction("", "Hotel")); } if (CurrentUser.Id != ZHmodel.UserId) { return(RedirectToAction("", "Hotel")); } var USmodel = _dbus.Hotel.Where(o => o.ParentId == ZHmodel.ID).FirstOrDefault(); var Manager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var u = Manager.FindById(ZHmodel.UserId).UserName; var model = new AccountHotelViewModel(); model.Account = u; model.Addressus = USmodel.Address; model.Addresszh = ZHmodel.Address; model.Area = ZHmodel.Area; model.Featureus = USmodel.Features; model.Featurezh = ZHmodel.Features; model.Tel = ZHmodel.Tel; model.Nameus = USmodel.Name; model.Namezh = ZHmodel.Name; model.LinkUrl = ZHmodel.LinkUrl; model.City = ZHmodel.City; var sessionkey = Guid.NewGuid().GetHashCode().ToString("x"); ViewBag.ImgKey = sessionkey; var Imgs = _basedb.ImageStore.Where(o => o.ReferIdZH == ZHmodel.ID && o.Type == "Hotel").Select(o => new ImageViewModel { ReferIdZH = o.ReferIdZH.Value, Extension = o.Extension, Image = o.Image, Name = o.Name, SessionKey = sessionkey, Type = o.Type }).ToList(); Session[sessionkey] = Imgs; //model.Facilies = var Facilies = ZHmodel.Facilities.Split(',').Select(int.Parse).ToList(); var GameSite = ZHmodel.Game.Split(',').Select(int.Parse).ToList(); ViewBag.HotelFacility = new Facilities().Facility("zh", Facilies); ViewBag.GameSites = new GameSiteModel().SelectList(GameSite); ViewBag.City = new GameSiteModel().Citys(ZHmodel.City); return(View(model)); }
public ActionResult Edit(int id) { //var zh = _dbzh.Hotel.Find(id); //var us = _dbus.Hotel.Find() var HotelZH = _db.HotelZH.Find(id); var HotelEN = _db.HotelEN.Where(o => o.ParentId == HotelZH.ID).FirstOrDefault(); if (HotelZH == null || HotelEN == null) { return(View("Index")); } var Manager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var UserName = Manager.FindById(HotelZH.UserId).UserName; var model = new AccountHotelViewModel(); model.Account = UserName; model.Addressus = HotelEN.Address; model.Addresszh = HotelZH.Address; model.Area = HotelZH.Area; model.Featureus = HotelEN.Features; model.Featurezh = HotelZH.Features; model.Tel = HotelZH.Tel; model.Nameus = HotelEN.Name; model.Namezh = HotelZH.Name; model.LinkUrl = HotelZH.LinkUrl; model.Certificate = HotelZH.Certificate; var sessionkey = Guid.NewGuid().GetHashCode().ToString("x"); ViewBag.ImgKey = sessionkey; var Imgs = _db.ImageStore.Where(o => o.ReferIdZH == HotelZH.ID && o.Type == "Hotel").Select(o => new ImageViewModel { ReferIdZH = o.ReferIdZH.Value, Extension = o.Extension, Image = o.Image, Name = o.Name, SessionKey = sessionkey, Type = o.Type }).ToList(); Session[sessionkey] = Imgs; //model.Facilies = var Facilies = string.IsNullOrEmpty(HotelZH.Facilities) ? null : HotelZH.Facilities.Split(',').Select(int.Parse).ToList(); var GameSite = string.IsNullOrEmpty(HotelZH.Game)?null : HotelZH.Game.Split(',').Select(int.Parse).ToList(); ViewBag.HotelFacility = new Facilities().Facility(Facilies); ViewBag.GameSites = new VenueModel().SelectList(GameSite); ViewBag.City = new GameSiteModel().Citys(HotelZH.City); var Language = string.IsNullOrEmpty(HotelZH.Language) ? null : HotelZH.Language.Split(',').Select(int.Parse).ToList(); ViewBag.Language = new LanguageModel().SelectListItem(Language); return(View(model)); }
// // POST: /Account/Register //[HttpPost] //[AllowAnonymous] //[ValidateAntiForgeryToken] //public async Task<ActionResult> Register(RegisterViewModel model) //{ // if (ModelState.IsValid) // { // var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; // //var user = new ApplicationUser { UserName = model.UserName }; // var result = await UserManager.CreateAsync(user, model.Password); // if (result.Succeeded) // { // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // // 如需如何啟用帳戶確認和密碼重設的詳細資訊,請造訪 http://go.microsoft.com/fwlink/?LinkID=320771 // // 傳送包含此連結的電子郵件 // // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // // await UserManager.SendEmailAsync(user.Id, "確認您的帳戶", "請按一下此連結確認您的帳戶 <a href=\"" + callbackUrl + "\">這裏</a>"); // return RedirectToAction("Index", "Home"); // } // AddErrors(result); // } // // 如果執行到這裡,發生某項失敗,則重新顯示表單 // return View(model); //} public int Create(AccountHotelViewModel model) { var user = new ApplicationUser { UserName = model.Account.ToLower() }; var Manager = UserManager == null?HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>() : UserManager; var result = Manager.Create(user, model.Password.ToLower()); var id = UserManager.FindByName(user.UserName).Id; //var user = new ApplicationUser { UserName = model.UserName }; //var result = await UserManager.CreateAsync(user, model.Password.ToLower()); return(id); }
public ActionResult Create(int?id) { var model = new AccountHotelViewModel(); var AccountAndImgKey = Guid.NewGuid().GetHashCode().ToString("x"); model.Account = AccountAndImgKey.ToUpper(); model.Password = Guid.NewGuid().GetHashCode().ToString("x"); ViewBag.HotelFacility = new Facilities().Facility(); ViewBag.ImgKey = AccountAndImgKey; Session[AccountAndImgKey] = new List <ImageViewModel>(); //model.ImgKey = AccountAndImgKey; ViewBag.GameSites = new GameSiteModel().SelectList(); ViewBag.City = new GameSiteModel().Citys(); return(View(model)); }
public ActionResult Create(AccountHotelViewModel model) { //var Facility = string.Empty; //if (Request["HotelFacility"] != null) //{ // Facility = Request["HotelFacility"].ToString(); //} //model.Facilies = Facility; model.Facilies = (model.HotelFacility == null || model.HotelFacility.Count <= 0) ? string.Empty : string.Join(",", model.HotelFacility); //var GameSite = string.Empty; //if (Request["GameSite"] != null) //{ // GameSite = Request["GameSite"].ToString(); //} model.Game = (model.GameSite == null || model.GameSite.Count <= 0) ? string.Empty : string.Join(",", model.GameSite); if (ModelState.IsValid) { var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var user = new ApplicationUser { UserName = model.Account, Email = model.Password }; ApplicationRoleManager _roleManager = HttpContext.GetOwinContext().Get <ApplicationRoleManager>(); var CurrentRole = "Hotel"; UserManager.Create(user, model.Password); UserManager.AddToRole(user.Id, CurrentRole); var id = UserManager.FindByName(model.Account).Id; model.UserId = id; model.Create(); return(RedirectToAction("Index")); } ViewBag.HotelFacility = new Facilities().Facility(); ViewBag.ImgKey = model.ImgKey; Session[model.ImgKey] = new List <ImageViewModel>(); //model.ImgKey = AccountAndImgKey; ViewBag.GameSites = new GameSiteModel().SelectList(); ViewBag.City = new GameSiteModel().Citys(); ModelState.AddModelError("", "錯誤!請檢查資料"); return(View()); }
public ActionResult Edit(AccountHotelViewModel model) { var HotelZH = _db.HotelZH.Find(model.ID); var HotelEN = _db.HotelEN.Where(o => o.ParentId == HotelZH.ID).FirstOrDefault(); var Manager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var u = Manager.FindById(HotelZH.UserId).UserName; model.Facilies = (model.HotelFacility == null || model.HotelFacility.Count <= 0) ? string.Empty : string.Join(",", model.HotelFacility); model.Game = (model.GameSite == null || model.GameSite.Count <= 0) ? string.Empty : string.Join(",", model.GameSite); model.Languages = (model.Language == null || model.Language.Count <= 0) ? string.Empty : string.Join(",", model.Language); model.Edit(); return(RedirectToAction("Edit", new { id = model.ID })); }
public async Task <ActionResult> RegisterAndCreateHotel(AccountHotelViewModel model) { if (!ModelState.IsValid) { TempData["HotelModel"] = model; return(RedirectToAction("Create", "Hotel", new { area = "Backend" })); } var Facility = string.Empty; if (Request["HotelFacility"] != null) { Facility = Request["HotelFacility"].ToString(); } model.Facilies = Facility; var user = new ApplicationUser { UserName = model.Account.ToLower() }; //var user = new ApplicationUser { UserName = model.UserName }; var result = await UserManager.CreateAsync(user, model.Password.ToLower()); TempData["HotelModel"] = model; if (result.Succeeded) { //model.Create(user.Id); //return Redirect("~/Backend/Hotel"); return(RedirectToAction("Create", "Hotel", new { area = "Backend" })); } else { return(RedirectToAction("Create", "Hotel", new { area = "Backend", model = model })); } //AddErrors(result); // 如果執行到這裡,發生某項失敗,則重新顯示表單 // return View(); }