public Reserversions FindById(int id)
 {
     using (var dbContext = new RezerwacjeDatabaseEntities())
     {
         Reserversions reserversions = (from u in getWithDependences(dbContext) where u.Id == id select u).FirstOrDefault();
         return(reserversions);
     }
 }
        private Reserversions getEntityToSave(RezerwacjeDatabaseEntities dbContext, Reserversions reserversion)
        {
            if (reserversion.Id == 0)
            {
                return(reserversion);
            }

            return(dbContext.Reserversions.Single(r => r.Id == reserversion.Id));
        }
Exemple #3
0
        public bool isRoomVacant(string sessionId, ReserversionWraper reserversions)
        {
            if (!UserAuthFactory.Instance.isAuth(sessionId))
            {
                return(false);
            }
            Reserversions reserversionEntity = reconvert(reserversions);

            return(RoomsFactory.Instance.IsRoomVacant(reserversionEntity));
        }
Exemple #4
0
        public ReserversionWraper FindById(string sessionId, int id)
        {
            if (!UserAuthFactory.Instance.isAuth(sessionId))
            {
                return(null);
            }
            Reserversions reserversionEntity = ReserversionsFactory.Instance.FindById(id);

            return(convert(reserversionEntity));
        }
Exemple #5
0
        public int Save(string sessionId, ReserversionWraper reserversions)
        {
            if (!UserAuthFactory.Instance.isAuth(sessionId))
            {
                return(0);
            }
            Reserversions reserversionEntity = reconvert(reserversions);

            reserversionEntity.Users = UserAuthFactory.Instance.getUser(sessionId);
            return(ReserversionsFactory.Instance.Save(reserversionEntity));
        }
 public bool IsRoomVacant(Reserversions reserversion)
 {
     using (var dbContext = new RezerwacjeDatabaseEntities())
     {
         bool vacant = !(from reserv in dbContext.Reserversions
                         where reserv.Id != reserversion.Id &&
                         reserv.Rooms.Id == reserversion.Rooms.Id &&
                         (reserv.From <reserversion.To && reserv.To> reserversion.From)
                         select reserv.Id).Any();
         return(vacant);
     }
 }
        public int Save(Reserversions reserversion)
        {
            using (var dbContext = new RezerwacjeDatabaseEntities())
            {
                Reserversions toSave = getEntityToSave(dbContext, reserversion);
                toSave.From      = reserversion.From;
                toSave.To        = reserversion.To;
                toSave.Rooms     = dbContext.Rooms.Single(r => r.Id == reserversion.Rooms.Id);
                toSave.Customers = dbContext.Customers.Single(c => c.Id == reserversion.Customers.Id);
                toSave.Users     = dbContext.Users.Single(u => u.Id == reserversion.Users.Id);

                dbContext.Entry(toSave).State = toSave.Id == 0 ? EntityState.Added : EntityState.Modified;
                return(dbContext.SaveChanges());
            }
        }