Example #1
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");
            }
        }
Example #2
0
 public IReadOnlyCollection <Room> GetAll()
 {
     using (var ctx = new RoomsContext())
     {
         return(ctx.Rooms.AsNoTracking().ToList());
     }
 }
Example #3
0
 public IReadOnlyCollection <Human> GetHumanByRoomId(int id)
 {
     using (var ctx = new RoomsContext())
     {
         return(ctx.Humans.AsNoTracking().Where(x => x.RoomId == id).ToList());
     }
 }
Example #4
0
        public formular VerificareFormular(int idUser, int idCamin, int idCamera)
        {
            using (RoomsContext context = new RoomsContext())
            {
                var verificare = context.Formular
                                 .Where(formular => (formular.caminID == idCamin) &&
                                        formular.cameraID == idCamera && formular.studentID == idUser)
                                 .Select(formular => formular)

                                 .Cast <formular>();

                int nr_verificari = verificare.Count();

                if (nr_verificari == 0)
                {
                    context.Formular.Add(new formular()
                    {
                        studentID     = idUser,
                        caminID       = idCamin,
                        cameraID      = idCamera,
                        StareFormular = 0
                    });
                    context.SaveChanges();
                    var newId            = context.Formular.Max(x => x.id);
                    var returnedFormular = context.Formular.Where(x => x.id == newId).ToList().FirstOrDefault();
                    return(returnedFormular);
                }
                else
                {
                    throw new Exception("Ai selectat aceasta varianta");
                }
            }
        }
Example #5
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);
            }
        }
Example #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              RoomsContext roomCntxt)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseMvc();
        }
Example #7
0
        static void Main(string[] args)
        {
            RoomsContext context = new RoomsContext();

            foreach (var c in context.Rooms)
            {
                Console.WriteLine(c.Name);
            }
        }
Example #8
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();
            }
        }
Example #9
0
        public void Create(Room model)
        {
            using (var ctx = new RoomsContext())
            {
                ctx.Rooms.Add(model);

                ctx.SaveChanges();
            }
        }
Example #10
0
        public async Task <Reservation> GetReservationByIdAsync(int id)
        {
            Reservation result = null;

            using (RoomsContext dbContext = new RoomsContext())
            {
                result = await dbContext.Reservations.FirstOrDefaultAsync(c => c.Id == id);
            }
            return(result);
        }
Example #11
0
        public async Task <MeetingRoom> GetMeetingRoomByIdAsync(int id)
        {
            MeetingRoom res = null;

            using (RoomsContext dbContext = new RoomsContext())
            {
                res = await dbContext.MeetingRooms.FirstOrDefaultAsync(c => c.Id == id);
            }
            return(res);
        }
Example #12
0
        public async Task <IEnumerable <MeetingRoom> > GetMeetingRoomsAsync()
        {
            IEnumerable <MeetingRoom> result = null;

            using (RoomsContext dbContext = new RoomsContext())
            {
                result = await dbContext.MeetingRooms.ToListAsync();
            }
            return(result);
        }
Example #13
0
        public List <camin> GetCamin()
        {
            using (RoomsContext context = new RoomsContext())
            {
                var camine = (from camin in context.Camin
                              select camin).ToList();

                return(camine);
            }
        }
Example #14
0
        public void AddHumanToRoom(int roomId, int humanId)
        {
            using (var ctx = new RoomsContext())
            {
                var human = ctx.Humans.First(x => x.Id == humanId);

                human.RoomId = roomId;

                ctx.SaveChanges();
            }
        }
Example #15
0
        public List <camera> GetCamere(int idCamin)
        {
            using (RoomsContext context = new RoomsContext())
            {
                var camere = (from camera in context.Camera
                              where camera.caminID == idCamin
                              select camera).ToList();

                return(camere);
            }
        }
Example #16
0
 public void UpdateFormular(formular formular)
 {
     using (RoomsContext context = new RoomsContext())
     {
         formular updateFormular = context.Formular.Where(x => x.id == formular.id).ToList().FirstOrDefault();
         updateFormular.cameraID      = formular.studentID;
         updateFormular.caminID       = formular.caminID;
         updateFormular.cameraID      = formular.cameraID;
         updateFormular.StareFormular = formular.StareFormular;
         context.SaveChanges();
     }
 }
        public RoomsController(RoomsContext context)
        {
            _context = context;

            if (_context.Rooms.Count() == 0)
            {
                _context.Rooms.Add(new Room {
                    Owner = "Kowalski", Capacity = 20
                });
                _context.SaveChanges();
            }
        }
Example #18
0
 public bool CheckIfUserExists(string username)
 {
     using (RoomsContext elearningContext = new RoomsContext())
     {
         var users = elearningContext.Utilizator.Where(x => x.username == username).ToList();
         if (users.Count() > 0)
         {
             return(true);
         }
         return(false);
     }
 }
Example #19
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();
            }
        }
Example #20
0
        public async Task <List <Reservation> > GetReservAsync(MeetingRoom room)
        {
            List <Reservation> res = null;

            using (RoomsContext dbContext = new RoomsContext())
            {
                var r = await dbContext.MeetingRooms.ToListAsync();

                res = r.Find(c => c.Id == room.Id).Reservations.ToList();
                res.Sort();
            }
            return(res);
        }
Example #21
0
        public async Task <IEnumerable <Reservation> > GetReservationsByIdAsync(int id)
        {
            List <Reservation> res = null;

            using (RoomsContext dbContext = new RoomsContext())
            {
                var room = await dbContext.MeetingRooms.FirstOrDefaultAsync(c => c.Id == id);

                if (room != null)
                {
                    res = room.Reservations.ToList();
                }
                res?.Sort();
            }
            return(res);
        }
Example #22
0
        public utilizator Verificare_User(string email, string password)
        {
            using (RoomsContext context = new RoomsContext())
            {
                var verificare = context.Utilizator.Where(utilizator =>
                                                          (utilizator.email == email) && utilizator.password == password).Select(utilizator => utilizator)
                                 .Cast <utilizator>();

                int nr_verificari = verificare.Count();

                if (nr_verificari != 1)
                {
                    throw new Exception("Email sau Parola Invalide ! Reincercati !");
                }

                return(verificare.FirstOrDefault());
            }
        }
Example #23
0
        public student Valideaza_Date(float medie, string nr_telefon, string facultate, string nume, string prenume)
        {
            using (RoomsContext date_context = new RoomsContext())
            {
                date_context.Student.Add(new student()
                {
                    nume       = nume,
                    prenume    = prenume,
                    medie      = medie,
                    nr_telefon = nr_telefon,
                    facultate  = facultate,
                });
                date_context.SaveChanges();
                var newId = date_context.Student.Max(x => x.id);

                var returnedUser = date_context.Student.Where(x => x.id == newId).ToList().FirstOrDefault();
                return(returnedUser);
            }
        }
Example #24
0
        private static void RegisterTypes(ContainerBuilder builder)
        {
            var mapperConfig = new MapperConfiguration(cfg => {
                cfg.AddProfile <MapperProflile>();
            });
            IMapper mapper = new Mapper(mapperConfig);

            DbContext context = new RoomsContext();
            IGenericRepository <City>      cityGenericRepository      = new EFGenericRepository <City>(context);
            IGenericRepository <QuestRoom> questRoomGenericRepository = new EFGenericRepository <QuestRoom>(context);
            ICityService      cityService      = new CityServise(cityGenericRepository, mapper);
            IQuestRoomService questRoomService = new QuestRoomServise(questRoomGenericRepository, mapper);

            builder.RegisterInstance(mapper).As <IMapper>();
            builder.RegisterInstance(context).As <DbContext>();
            builder.RegisterInstance(cityGenericRepository).As <IGenericRepository <City> >();
            builder.RegisterInstance(questRoomGenericRepository).As <IGenericRepository <QuestRoom> >();
            builder.RegisterInstance(cityService).As <ICityService>();
            builder.RegisterInstance(questRoomService).As <IQuestRoomService>();
        }
Example #25
0
        public utilizator Valideaza_Inregistrare(string username, string password, string firstname, string lastname, string confirmPassword, bool checkInstructor, string email)
        {
            Rol_Utilizator rol = Rol_Utilizator.Membru;

            if (!CheckIfUserExists(username))
            {
                if (checkInstructor)
                {
                    rol = Rol_Utilizator.Administrator;
                }
                if (CheckPassword(password, confirmPassword) && IsValidEmail(email))
                {
                    using (RoomsContext elearningContext = new RoomsContext())
                    {
                        elearningContext.Utilizator.Add(new utilizator()
                        {
                            firstname = firstname,
                            lastname  = lastname,
                            username  = username,
                            password  = password,
                            Role      = rol,
                            email     = email
                        });
                        elearningContext.SaveChanges();
                        var newId = elearningContext.Utilizator.Max(x => x.id);

                        var returnedUser = elearningContext.Utilizator.Where(x => x.id == newId).ToList().FirstOrDefault();
                        return(returnedUser);
                    }
                }
                else
                {
                    throw new System.Exception("Parola sau Email invalid");
                }
            }
            else
            {
                throw new System.Exception("Utilizator deja existent");
            }
        }
Example #26
0
        public ActionResult Index()
        {
            RoomsContext dbContext = new RoomsContext();

            return(View());
        }
Example #27
0
 public RoomInfoRepository(RoomsContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #28
0
 public TypeRepository(RoomsContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #29
0
 public Commands(RoomsContext context)
 {
     this._context = context;
 }
Example #30
0
 public Validation(RoomsContext context)
 {
     this._context = context;
 }