Esempio n. 1
0
        public async Task <ISession> Get(int Id)
        {
            ISession returnValue = null;

            using (SqlConnection connection = new SqlConnection(Settings.ConnectionString)) {
                connection.Open();

                using (SqlCommand sessionCommand = new SqlCommand("SELECT * FROM Sessions WHERE Id = @Id", connection)) {
                    sessionCommand.Parameters.Add("Id", SqlDbType.Int).Value = Id;

                    using (SqlDataReader dataReader = await sessionCommand.ExecuteReaderAsync()) {
                        if (await dataReader.ReadAsync())
                        {
                            returnValue = new Models.SessionModel(dataReader);
                        }
                    }
                }

                if (null != returnValue)
                {
                    using (SqlCommand tagCommand = new SqlCommand("SELECT * FROM Tags WHERE Id IN ( SELECT TagId FROM SessionTags WHERE SessionId = @SessionId );", connection)) {
                        tagCommand.Parameters.Add("SessionId", SqlDbType.Int).Value = returnValue.Id;

                        using (SqlDataReader dataReader = await tagCommand.ExecuteReaderAsync()) {
                            while (await dataReader.ReadAsync())
                            {
                                returnValue = returnValue.AddTag(new Models.TagModel(dataReader));
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }
        public async Task <ISession> Get(int Id)
        {
            ISession returnValue = null;

            using (SqlConnection connection = new SqlConnection(Settings.ConnectionString)) {
                connection.Open();

                using (SqlCommand sessionCommand = new SqlCommand("SELECT * FROM Sessions WHERE Id = @Id", connection)) {
                    sessionCommand.Parameters.Add("Id", SqlDbType.Int).Value = Id;

                    using (SqlDataReader dataReader = await sessionCommand.ExecuteReaderAsync()) {
                        if (await dataReader.ReadAsync())
                        {
                            returnValue = new Models.SessionModel(dataReader);
                        }
                    }
                }

                if (null != returnValue)
                {
                    using (SqlCommand tagCommand = new SqlCommand("SELECT * FROM Tags WHERE Id IN ( SELECT TagId FROM SessionTags WHERE SessionId = @SessionId );", connection)) {
                        tagCommand.Parameters.Add("SessionId", SqlDbType.Int).Value = returnValue.Id;

                        using (SqlDataReader dataReader = await tagCommand.ExecuteReaderAsync()) {
                            while (await dataReader.ReadAsync())
                            {
                                ITag tag = new Models.TagModel(dataReader);
                                returnValue = returnValue.AddTag(tag);
                            }
                        }
                    }
                }
            }

            LevelDataStore levels = new LevelDataStore();

            returnValue = returnValue.UpdateLevel(await levels.Get((returnValue as Models.SessionModel).LevelId));

            CategoryDataStore categories = new CategoryDataStore();

            returnValue = returnValue.UpdateCategory(await categories.Get((returnValue as Models.SessionModel).CategoryId));

            TimeSlotDataStore timeSlots = new TimeSlotDataStore();

            returnValue = returnValue.UpdateTimeSlot(await timeSlots.Get((returnValue as Models.SessionModel).TimeSlotId));

            RoomDataStore rooms = new RoomDataStore();

            return(returnValue.UpdateRoom(await rooms.Get((returnValue as Models.SessionModel).RoomId)));
        }
Esempio n. 3
0
        public ISession UpdateCategory(ITag value)
        {
            SessionModel newSession = this.Clone();

            if (null == value)
            {
                newSession.CategoryId = 0;
                newSession.Category   = null;
            }
            else
            {
                newSession.CategoryId = value.Id;
                newSession.Category   = new TagModel(value);
            }
            newSession.Category = value;
            return(newSession);
        }
Esempio n. 4
0
        public ISession UpdateLevel(ITag value)
        {
            SessionModel newSession = this.Clone();

            if (null == value)
            {
                newSession.LevelId = 0;
                newSession.Level   = null;
            }
            else
            {
                newSession.LevelId = value.Id;
                newSession.Level   = new TagModel(value);
            }
            newSession.Level = value;
            return(newSession);
        }
Esempio n. 5
0
        private SessionModel Clone()
        {
            SessionModel cloned = new SessionModel {
                Id       = this.Id,
                UserId   = this.UserId,
                Title    = string.Copy(this.Title),
                Abstract = string.Copy(this.Abstract),
                Accepted = this.Accepted,
                Tags     = this.Tags?.ToImmutableList()
            };

            if (!string.IsNullOrWhiteSpace(cloned.Notes))
            {
                cloned.Notes = string.Copy(this.Notes);
            }

            return(cloned);
        }