Exemplo n.º 1
0
 public List<ParticularityIdentifier> GetAllParticularities()
 {
     List<ParticularityIdentifier> val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from parts in ctx.Particularities
                     select parts.ParticularityID;
         val = query.ToList().ConvertAll(id => new ParticularityIdentifier(id.ToString()));
     }
     return val;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the name of the particularity.
 /// </summary>
 /// <returns>The particularity name.</returns>
 /// <param name="partId">Part identifier.</param>
 public string GetParticularityName(ParticularityIdentifier partId)
 {
     string val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from particularity in ctx.Particularities
                     where particularity.ParticularityID.ToString().Equals(partId.Value)
                     select particularity.Name;
         val = query.First();
     }
     return val;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns true if the profile exists.
 /// </summary>
 /// <returns><c>true</c>, if the profile exists for the given username, <c>false</c> otherwise.</returns>
 /// <param name="username">Username.</param>
 public bool ProfileExists(UserIdentifier username)
 {
     bool exists = false;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from profile in ctx.UsersProfile
                     where profile.Username.Equals(username.Value)
                     select profile;
         exists = query.Count() != 0;
     }
     return exists;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the room capacity.
 /// </summary>
 /// <returns>The room capacity.</returns>
 /// <param name="roomId">Room identifier.</param>
 public int GetRoomCapacity(RoomIdentifier roomId)
 {
     int val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from room in ctx.Rooms
                     where room.RoomID.ToString().Equals(roomId.Value)
                     select room.Capacity;
         val = query.First();
     }
     return val;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the SiteIdentifier corresponding to this user location.
        /// </summary>
        /// <value>The location.</value>
        public SiteIdentifier GetLocation(UserIdentifier username)
        {
            ValidateProfile(username);

            SiteIdentifier val;
            using (var ctx = new DatabaseContexts.MainContext())
            {
                var query = from profile in ctx.UsersProfile
                            where profile.Username.Equals(username.Value)
                            select profile.SiteID;

                val = new SiteIdentifier(query.First().ToString());
            }
            return val;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets a value indicating if the given user is an administator.
        /// </summary>
        /// <param name="username">Username.</param>
        public bool IsAdmin(UserIdentifier username)
        {
            ValidateProfile(username);

            bool isAdmin;
            using (var ctx = new DatabaseContexts.MainContext())
            {
                var query = from profile in ctx.UsersProfile
                            where profile.Username.Equals(username.Value)
                            select profile.IsAdmin;

                isAdmin = query.First();
            }
            return isAdmin;
        }
Exemplo n.º 7
0
 public int SitesCount()
 {
     int val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from site in ctx.Sites
                     select site.SiteID;
         val = query.Count();
     }
     return val;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Checks if the given site exists.
 /// </summary>
 /// <param name="siteId">Site identifier.</param>
 public bool SiteExists(SiteIdentifier siteId)
 {
     bool val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from site in ctx.Sites
                     where site.SiteID.ToString().Equals(siteId.Value.ToString())
                     select site;
         val = query.Count() > 0;
     }
     return val;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Checks if the given room exists.
 /// </summary>
 /// <param name="roomId">room identifier.</param>
 public bool RoomExists(RoomIdentifier roomId)
 {
     bool val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from room in ctx.Rooms
                     where room.RoomID.ToString().Equals(roomId.Value.ToString())
                     select room;
         val = query.Count() > 0;
     }
     return val;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Checks if the given particularity exists.
 /// </summary>
 /// <param name="particularityId">particularity identifier.</param>
 public bool ParticularityExists(ParticularityIdentifier particularityId)
 {
     bool val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from particularity in ctx.Particularities
                     where particularity.ParticularityID.ToString().Equals(particularityId.Value.ToString())
                     select particularity;
         val = query.Count() > 0;
     }
     return val;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Gets the name of the given site.
 /// </summary>
 /// <returns>The site name.</returns>
 /// <param name="siteId">Site identifier.</param>
 public string GetSiteName(SiteIdentifier siteId)
 {
     string val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from site in ctx.Sites
                     where site.SiteID.ToString().Equals(siteId.Value)
                     select site.Name;
         val = query.First();
     }
     return val;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Gets a list of RoomIdentifier corresponding to the rooms in the given site.
        /// </summary>
        /// <returns>The rooms.</returns>
        public List<RoomIdentifier> GetRooms(SiteIdentifier siteID)
        {
            List<RoomIdentifier> val;
            using (var ctx = new DatabaseContexts.MainContext())
            {
                var query = from site in ctx.Sites
                            where site.SiteID.ToString().Equals(siteID.Value.ToString())
                            select site.Rooms;

                val = query.First().ToList().ConvertAll(room => new RoomIdentifier(room.RoomID.ToString()));
            }
            return val;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets a list of RoomIdentifier corresponding to all the rooms in the database.
        /// </summary>
        /// <returns>The rooms.</returns>
        public List<RoomIdentifier> GetRooms()
        {
            List<RoomIdentifier> val;
            using (var ctx = new DatabaseContexts.MainContext())
            {
                var query = from room in ctx.Rooms
                            select room.RoomID;

                val = query.ToList().ConvertAll(id => new RoomIdentifier(id.ToString()));
            }
            return val;
        }
Exemplo n.º 14
0
 /// <summary>
 /// Gets the room particularities.
 /// </summary>
 /// <returns>The room particularities.</returns>
 /// <param name="roomId">Room identifier.</param>
 public List<ParticularityIdentifier> GetRoomParticularities(RoomIdentifier roomId)
 {
     List<ParticularityIdentifier> val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from room in ctx.Rooms
                     where room.RoomID.ToString().Equals(roomId.Value)
                     select room.Particularities;
         val = query.First().ToList().ConvertAll(part => new ParticularityIdentifier(part.ParticularityID.ToString()));
     }
     return val;
 }
Exemplo n.º 15
0
        /// <summary>
        /// Sets the given user location.
        /// When setting, if the user does not yet exist in the underlaying storage system, it is created.
        /// </summary>
        /// <param name="username">Username.</param>
        /// <param name="siteId">Site identifier.</param>
        public void SetLocation(UserIdentifier username, SiteIdentifier siteId)
        {
            ValidateProfile(username);

            using (var ctx = new DatabaseContexts.MainContext())
            {
                var query = from profile in ctx.UsersProfile
                            where profile.Username.Equals(username.Value)
                            select profile;

                DatabaseContexts.MCUserProfile prof = query.First();
                prof.SiteID = Int32.Parse(siteId.Value);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets a list of SiteIdentifiers corresponding to all the sites in the database.
        /// </summary>
        /// <returns>The sites.</returns>
        public List<SiteIdentifier> GetSites()
        {
            List<SiteIdentifier> val;
            using (var ctx = new DatabaseContexts.MainContext())
            {
                var query = from site in ctx.Sites
                            select site.SiteID;

                val = query.ToList().ConvertAll(id => new SiteIdentifier(id.ToString()));
            }
            return val;
        }
Exemplo n.º 17
0
 /// <summary>
 /// Gets the name of the given room.
 /// </summary>
 /// <returns>The room name.</returns>
 /// <param name="roomId">Room identifier.</param>
 public string GetRoomName(RoomIdentifier roomId)
 {
     string val;
     using (var ctx = new DatabaseContexts.MainContext())
     {
         var query = from room in ctx.Rooms
                     where room.RoomID.ToString().Equals(roomId.Value)
                     select room.Name;
         val = query.First();
     }
     return val;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Make sure that the user profile corresponding to the given username exists.
 /// If it doesn't exist, it is created.
 /// </summary>
 /// <param name="username">Username.</param>
 private void ValidateProfile(UserIdentifier username)
 {
     if (!ProfileExists(username))
     {
         using (var ctx = new DatabaseContexts.MainContext())
         {
             DatabaseContexts.MCUserProfile userProfile = new DatabaseContexts.MCUserProfile();
             userProfile.Username = username.Value;
             ctx.UsersProfile.Add(userProfile);
             ctx.SaveChanges();
         }
     }
 }