コード例 #1
0
        public async Task <IActionResult> Edit([Bind("ClientId,HotelId,RoomId,CheckInDate,CheckOutDate")] Reservation reservation)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                reservation.CheckOutDate = DateTime.Now;
                RoomsController room = new RoomsController(_context);

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(reservation);
                        await room.EditFreeByIdAsync(reservation.RoomId, reservation.HotelId, null);

                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ReservationExists(reservation.ClientId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    TempData["ErrMessageReservation"] = "There is an open reservation for this client on this date!";
                }

                ViewData["ClientId"]    = new SelectList(_context.Client, "Id", "Id", reservation.ClientId);
                ViewData["HotelId"]     = new SelectList(_context.Hotel, "Id", "Name", reservation.HotelId);
                ViewData["RoomId"]      = new SelectList(_context.Room, "Id", "Id", reservation.RoomId);
                ViewData["CheckInDate"] = reservation.CheckInDate;
                return(View(reservation));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #2
0
ファイル: RoomsController.cs プロジェクト: nivhojberg/Lowtel
        public async Task <IActionResult> Edit(int id, [Bind("Id,HotelId,RoomTypeId,IsFree")] Room room)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (id != room.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(room);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!RoomExists(room.Id, room.HotelId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    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"));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,State,City,Address,StarsRate,Description,CordX,CordY")] Hotel hotel)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (id != hotel.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(hotel);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!HotelExists(hotel.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(hotel));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,PriceForNight")] RoomType roomType)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (id != roomType.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(roomType);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!RoomTypeExists(roomType.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(roomType));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #5
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,FirstName,LastName,PhoneNumber,CreditCard")] Client client)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (id != client.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(client);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ClientExists(client.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(client));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #6
0
ファイル: UsersController.cs プロジェクト: nivhojberg/Lowtel
        public async Task <IActionResult> Edit(string id, [Bind("UserName,Password")] User user)
        {
            if (checkSession().isLogin)
            {
                if (id != user.UserName)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(user);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!UserExists(user))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(user));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }