Ejemplo n.º 1
0
        public async Task CreateAsync(GetHotelsViewModel model)
        {
            model.Hotels = await this.hotelRepo.GetAllAsync();

            var request = new Request()
            {
                Role   = model.Role,
                Hotel  = model.Hotels.Where(h => h.Id == model.HotelId).FirstOrDefault(),
                UserId = this.httpContextAccessor.HttpContext.User.FindFirst("Id").Value,
            };

            await this.requestRepo.AddAsync(request);

            await this.requestRepo.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            if (this.User.Identity.IsAuthenticated)
            {
                var userId = this.User.FindFirst("Id").Value;

                var currentUser = (await this.userRepo.GetAllAsync()).FirstOrDefault(user => user.Id == userId);

                var list = new GetHotelsViewModel();

                list.Hotels = await this.hotelRepo.GetAllAsync();

                foreach (var item in currentUser.UserHotelRoles)
                {
                    var action = string.Empty;

                    if (item.HotelRole.Role.Name == "Manager")
                    {
                        action = "Dashboard";
                    }

                    list.RenderedHotels.Add(new HotelRenderViewModel
                    {
                        Hotel  = item.HotelRole.Hotel,
                        Role   = item.HotelRole.Role.Name,
                        Action = action,
                    });
                }

                if (bool.Parse(this.User.FindFirst("IsAdministrator").Value))
                {
                    this.ViewBag.Users = await this.adminService.GetUsersAsync();

                    this.ViewBag.Hotels = await this.adminService.GetHotelsAsync();

                    return(this.View("~/Areas/Administrator/Views/Home/Dashboard.cshtml"));
                }

                return(this.View("Dashboard", list));
            }
            else
            {
                return(this.View());
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateRequest(GetHotelsViewModel model)
        {
            await this.requestService.CreateAsync(model);

            return(this.Redirect("/Home/Index"));
        }