Ejemplo n.º 1
0
        public IActionResult AddHotel(HotelViewModel model, int id)
        {
            string userId = _userManagerData.GetLoggedUserId();
            var    user   = _userManagerData.Get(userId);
            var    hotel  = _hotelManager.Get(id);

            if (hotel.OwnerId == null)
            {
                hotel.OwnerId = userId;
                hotel.Name    = model.Name;
                _hotelManager.Commit();
                return(RedirectToAction("Dashboard"));
            }
            else
            {
                var newhotel = new Hotel();

                newhotel.Name    = model.Name;
                newhotel.Status  = 1;
                newhotel.OwnerId = userId;

                _hotelManager.Add(newhotel);
                _hotelManager.Commit();

                return(RedirectToAction("Dashboard"));
            }
        }
        public async Task <IActionResult> Register(RegisterUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                //Creating First Hotel for User
                var hotel = new Hotel();
                hotel.Name   = "Default Hotel";
                hotel.Status = 1;
                _hotelManager.Add(hotel);
                _hotelManager.Commit();

                var user = new User {
                    UserName = model.UserName
                };

                user.Email           = model.Email;
                user.SelectedHotelId = hotel.Id;
                var createResult = await _userManager.CreateAsync(user, model.Password);

                if (createResult.Succeeded)
                {
                    await _signInManager.SignInAsync(user, false);

                    return(RedirectToAction("AddHotel", "Home", new { id = hotel.Id }));
                }
                else
                {
                    foreach (var error in createResult.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }

            return(View());
        }