Пример #1
0
        public async Task <IActionResult> PutRooms([FromRoute] Guid id, [FromBody] Rooms rooms)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != rooms.RoomId)
            {
                return(BadRequest());
            }

            _context.Entry(rooms).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <string> AddReservationAsync(TimeSpan start, TimeSpan end, int id, string userName)
        {
            Time time = new Time(start, end);

            using (RoomsContext dbContext = new RoomsContext())
            {
                var         room = dbContext.MeetingRooms.ToList().Find(c => c.Id == id);
                Reservation res  = new Reservation
                {
                    StartTime = time.Start,
                    EndTime   = time.End,
                    RoomId    = room.Id,
                    Room      = room,
                    UserName  = userName
                };
                if (await CheckReservation(room, res))
                {
                    room.Reservations.Add(res);
                    await dbContext.SaveChangesAsync();

                    return("added");
                }
                return("invalid time value");
            }
        }
Пример #3
0
        public async Task <bool> AddReservationAsync(ReservationViewModel model)
        {
            Time time = new Time(model.Start, model.End);

            using (RoomsContext dbContext = new RoomsContext())
            {
                var         room = dbContext.MeetingRooms.ToList().Find(c => c.Id == model.RoomId);
                Reservation res  = new Reservation
                {
                    StartTime    = time.Start,
                    EndTime      = time.End,
                    RoomId       = room.Id,
                    Room         = room,
                    UserName     = model.UserName,
                    UserStringId = model.UserStringId
                };
                if (await time.CheckReservation(room, res))
                {
                    room.Reservations.Add(res);
                    await dbContext.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
        }
Пример #4
0
        //public async Task<Reservation> ReservationCheckAsync(TimeSpan start, TimeSpan end, int id)
        //{
        //    Time time = new Time(start, end);
        //    using (RoomsContext dbContext = new RoomsContext())
        //    {
        //        var room = dbContext.MeetingRooms.ToList().Find(c => c.Id == id);
        //        var res = await GetReservationsByIdAsync(id);
        //        var list = res.ToList();
        //        for (int i = 0; i <= list.Count; i++)
        //        {
        //            if (list.Count >= 2)
        //            {
        //                if (i == list.Count - 1)
        //                {
        //                    break;
        //                }
        //                if (time.Check(new Time(list[i].StartTime, list[i].EndTime),
        //                    new Time(list[i + 1].StartTime, list[i + 1].EndTime)))
        //                {
        //                    return new Reservation
        //                    {
        //                        StartTime = time.Start,
        //                        EndTime = time.End,
        //                        RoomId = room.Id,
        //                        Room = room
        //                    };
        //                }
        //                if (time.Start >= list.Last().EndTime)
        //                {
        //                    return new Reservation
        //                    {
        //                        StartTime = time.Start,
        //                        EndTime = time.End,
        //                        RoomId = room.Id,
        //                        Room = room
        //                    };
        //                }
        //                if (time.End > list[i + 1].StartTime)
        //                {
        //                    continue;
        //                }
        //                if (time.End < list[i].StartTime)
        //                {
        //                    return new Reservation
        //                    {
        //                        StartTime = time.Start,
        //                        EndTime = time.End,
        //                        RoomId = room.Id,
        //                        Room = room
        //                    };
        //                }
        //                continue;
        //            }
        //            if (list.Count == 0)
        //            {
        //                return new Reservation
        //                {
        //                    StartTime = time.Start,
        //                    EndTime = time.End,
        //                    RoomId = room.Id,
        //                    Room = room
        //                };
        //            }
        //            if (time.Check(new Time(list[i].StartTime, list[i].EndTime)))
        //            {
        //                return new Reservation
        //                {
        //                    StartTime = time.Start,
        //                    EndTime = time.End,
        //                    RoomId = room.Id,
        //                    Room = room
        //                };
        //            }
        //            if (list.Count == 1 && time.Check(new Time(list[0].StartTime, list[0].EndTime)))
        //            {
        //                return new Reservation
        //                {
        //                    StartTime = time.Start,
        //                    EndTime = time.End,
        //                    RoomId = room.Id,
        //                    Room = room
        //                };
        //            }
        //        }
        //    }
        //    return null;
        //}

        public async Task AddAsync(Reservation res)
        {
            using (RoomsContext dbContext = new RoomsContext())
            {
                var list = dbContext.MeetingRooms.First(c => c.Id == res.RoomId);
                list.Reservations.Add(res);
                await dbContext.SaveChangesAsync();
            }
        }
Пример #5
0
        public async Task DeleteReservationAsync(int id)
        {
            using (RoomsContext dbContext = new RoomsContext())
            {
                var res = await dbContext.Reservations.FirstOrDefaultAsync(c => c.Id == id);

                if (res != null)
                {
                    dbContext.Reservations.Remove(res);
                }
                await dbContext.SaveChangesAsync();
            }
        }
Пример #6
0
        public async Task <bool> Add(RoomInfo aggregate)
        {
            await _dbContext.RoomInfos.AddAsync(aggregate);

            return(await _dbContext.SaveChangesAsync() > 0);
        }