public async Task <IActionResult> Create(CompanyCreateInputModel input)
        {
            var userId = this.userManager.GetUserId(this.User);

            var user = await this.userManager.Users
                       .Include(u => u.Hotel)
                       .FirstOrDefaultAsync(u => u.Id == userId);

            if (user.HotelId == null || user.Hotel.CompanyId != null)
            {
                return(this.NotFound());
            }

            if (!this.ModelState.IsValid)
            {
                var cities = this.citiesService.GetAll <CityDropDownViewModel>();
                input.Cities = cities;

                return(this.View(input));
            }

            await this.companiesService.CreateAsync(
                input.Name,
                input.Bulstat,
                input.PhoneNumber,
                input.Email,
                input.CityId,
                input.Address,
                (int)user.HotelId);

            return(this.RedirectToAction("Manager", "Hotels"));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(CompanyCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            await this.userManager.AddToRoleAsync(user, GlobalConstants.CompanyOwnerRole);

            await this.companyService.CreateAsync(input.Name, input.Address, user.Id);

            await this.signInManager.SignOutAsync();

            await this.signInManager.SignInAsync(user, false);

            return(this.RedirectToAction(nameof(this.Index)));
        }
        public async Task <IActionResult> Create()
        {
            var userId = this.userManager.GetUserId(this.User);

            var user = await this.userManager.Users
                       .Include(u => u.Hotel)
                       .FirstOrDefaultAsync(u => u.Id == userId);

            if (user.HotelId == null || user.Hotel.CompanyId != null)
            {
                return(this.NotFound());
            }

            var cities = this.citiesService.GetAll <CityDropDownViewModel>();

            var viewModel = new CompanyCreateInputModel
            {
                Cities = cities,
            };

            return(this.View(viewModel));
        }