Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(string?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Reservation reservation = await _context.Reservations
                                      .Include(room => room.Room)
                                      .Include(user => user.User)
                                      .SingleOrDefaultAsync(rese => rese.Id == id);

            if (reservation == null)
            {
                return(NotFound());
            }

            List <ReservationCreateRoomViewModel> rooms = _context.Rooms.Select(x => new ReservationCreateRoomViewModel(x.Id, x.number, x.type, x.PriceForAdult, x.PriceForKid, x.IsFree)).ToList();

            List <ReservationCreateRoomViewModel> freeRooms = new List <ReservationCreateRoomViewModel>();

            freeRooms.Add(new ReservationCreateRoomViewModel(reservation.Room.Id, reservation.Room.number, reservation.Room.type, reservation.Room.PriceForAdult, reservation.Room.PriceForKid, reservation.Room.IsFree));
            foreach (var room in rooms)
            {
                if (room.IsFree)
                {
                    freeRooms.Add(room);
                }
            }
            ReservationsEditViewModel model = new ReservationsEditViewModel
            {
                Id   = reservation.Id,
                User = reservation.User,
                Room = reservation.Room,
                AccommodationDate = reservation.AccommodationDate,
                ReleaseDate       = reservation.ReleaseDate,
                HaveBreakFast     = reservation.HaveBreakFast,
                IsAllInclusive    = reservation.IsAllInclusive
            };

            model.RoomsAdded = freeRooms;

            Room r = await _context.Rooms.SingleOrDefaultAsync(x => x.Id == reservation.Room.Id);

            r.IsFree = true;
            _context.Update(r);
            await _context.SaveChangesAsync();

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(string id)
        {
            Client client = await _context.Clients.FindAsync(id);

            _context.Clients.Remove(client);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(All)));
        }
        public async Task <IActionResult> Edit(UsersEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await this._context.Users
                            .SingleOrDefaultAsync(user => user.Id == model.Id);

                user.UserName        = model.Username;
                user.FirstName       = model.FirstName;
                user.SecondName      = model.SecondName;
                user.LastName        = model.LastName;
                user.UCN             = model.UCN;
                user.PhoneNumber     = model.PhoneNumber;
                user.Email           = model.Email;
                user.AppointmentDate = model.AppointmentDate;
                user.IsActive        = model.IsActive;
                user.DateOfDismissal = model.DateOfDismissal;

                try
                {
                    _context.Users.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(All)));
            }

            return(View(model));
        }
        public async Task <IActionResult> Create(RoomsCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Room room = new Room
                {
                    Capasity      = model.Capasity,
                    number        = model.number,
                    type          = model.type,
                    PriceForAdult = model.PriceForAdult,
                    PriceForKid   = model.PriceForKid,
                    IsFree        = model.IsFree,
                };
                room.Id = Guid.NewGuid().ToString();
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(All)));
            }

            return(View(model));
        }