Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhoneNumber,CreditCard")] Client client)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (ModelState.IsValid)
                {
                    if (!ClientExists(client.Id))
                    {
                        _context.Add(client);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ViewData["ErrClient"] = "Client with id: " + client.Id + " already exists!";
                    }
                }
                return(View(client));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ClientId,HotelId,RoomId,CheckOutDate")] Reservation reservation)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                reservation.CheckInDate = DateTime.Now;
                reservation.CheckInDate = reservation.CheckInDate.AddMilliseconds(-1 * reservation.CheckInDate.Millisecond);

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Reservation parameters are not valid"));
                }
                else
                {
                    RoomsController roomsController = new RoomsController(_context);
                    await roomsController.EditFreeByIdAsync(reservation.RoomId, reservation.HotelId, reservation.CheckOutDate);

                    _context.Add(reservation);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,PriceForNight")] RoomType roomType)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(roomType);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(roomType));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("UserName,Password")] User user)
        {
            if (checkSession().isLogin)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(user));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,HotelId,RoomTypeId,IsFree")] Room room)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(room);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["HotelId"]    = new SelectList(_context.Hotel, "Id", "Id", room.HotelId);
                ViewData["RoomTypeId"] = new SelectList(_context.RoomType, "Id", "Id", room.RoomTypeId);
                return(View(room));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,State,City,Address,StarsRate,Description,CordX,CordY")] Hotel hotel)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                // Get hotel last seq id.
                hotel.Id = this.GetLastHotelIdSeq() + 1;

                if (ModelState.IsValid)
                {
                    _context.Add(hotel);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(hotel));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }