public ReservationRule(Entities.Rule rule)
 {
     CreatedDate = rule.CreatedDate;
     ActiveFrom  = rule.ActiveFrom;
     ActiveTo    = rule.ActiveTo;
     Id          = rule.Id;
     Restriction = (AccountRestriction)rule.Restriction;
     CourseId    = rule.CourseId;
     Course      = new Course(rule.Course.CourseId, rule.Course.Title, rule.Course.Level.ToString(), rule.Course.EffectiveTo);
 }
Ejemplo n.º 2
0
        // Get data properties depending on the type.
        public string GetItemProperty(int id, ServerData data, PropertyData property)
        {
            switch (data)
            {
            case ServerData.Video:
                Video video = _context.Videos.Where(u => u.Id == id).FirstOrDefault();
                if (video == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(video.Name);

                case PropertyData.Description:
                    return(video.Description);

                case PropertyData.Path:
                    return(video.Path);

                case PropertyData.Imgpath:
                    return(video.ImgPath);

                case PropertyData.SubPath:
                    return(video.SubPath);

                case PropertyData.Year:
                    return(video.Year == null? null: video.Year.ToString());

                case PropertyData.Created:
                    return(video.Created.ToLongDateString());
                }
                break;

            case ServerData.Book:
                Book book = _context.Books.Where(u => u.Id == id).FirstOrDefault();
                if (book == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(book.Name);

                case PropertyData.Description:
                    return(book.Description);

                case PropertyData.Path:
                    return(book.Path);

                case PropertyData.Imgpath:
                    return(book.ImgPath);

                case PropertyData.Year:
                    return(book.Year == null ? null : book.Year.ToString());

                case PropertyData.Created:
                    return(book.Created.ToLongDateString());
                }
                break;

            case ServerData.Game:
                Game game = _context.Games.Where(u => u.Id == id).FirstOrDefault();
                if (game == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(game.Name);

                case PropertyData.Description:
                    return(game.Description);
                }
                break;

            case ServerData.Grammar:
                Grammar grammar = _context.Grammars.Where(u => u.Id == id).FirstOrDefault();
                if (grammar == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(grammar.Title);

                case PropertyData.Description:
                    return(grammar.Description);
                }
                break;

            case ServerData.Rule:
                Entities.Rule rule = _context.Rules.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(rule?.Name);
                }
                break;

            case ServerData.GrammarExample:
                GrammarExample ge = _context.GrammarExamples.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(ge?.Name);
                }
                break;

            case ServerData.GrammarException:
                GrammarException gex = _context.Exceptions.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(gex?.Name);
                }
                break;

            case ServerData.Role:
                Role role = _context.Roles.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(role?.Name);
                }
                break;

            case ServerData.User:
                User user = _context.Users.Where(u => u.Id == id).FirstOrDefault();
                if (user == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                case PropertyData.Login:
                    return(user.Username);

                case PropertyData.Imgpath:
                    return(user.Avatar);

                case PropertyData.Password:
                    return(user.Password);

                case PropertyData.ScoreCount:
                    int score = 0;
                    foreach (Score item in _context.Scores.Where(s => s.UserID == user.Id).ToList())
                    {
                        score += item.ScoreCount;
                    }
                    return(score.ToString());

                case PropertyData.Level:
                    return(user.Level.ToString());

                case PropertyData.Role:
                    return(user.RoleID.ToString());

                case PropertyData.RolesName:
                    return(_context.Roles.Where(r => r.Id == user.RoleID).FirstOrDefault()?.Name);
                }
                break;

            case ServerData.VideoCategory:
                VideoCategory videoCategory = _context.VideoCategories.Where(u => u.Id == id).FirstOrDefault();
                if (videoCategory == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(videoCategory.Name);
                }
                break;

            case ServerData.BookCategory:
                BookCategory bookCategory = _context.BookCategories.Where(u => u.Id == id).FirstOrDefault();
                if (bookCategory == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(bookCategory.Name);
                }
                break;

            case ServerData.Word:
                Word word = _context.Dictionary.Where(u => u.Id == id).FirstOrDefault();
                if (word == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(word.Name);

                case PropertyData.Imgpath:
                    return(word.ImgPath);

                case PropertyData.PluralForm:
                    return(_context.WordForms.Where(f => f.Id == word.FormID).FirstOrDefault()?.PluralForm);

                case PropertyData.PastForm:
                    return(_context.WordForms.Where(f => f.Id == word.FormID).FirstOrDefault()?.PastForm);

                case PropertyData.PastThForm:
                    return(_context.WordForms.Where(f => f.Id == word.FormID).FirstOrDefault()?.PastThForm);

                case PropertyData.Transcription:
                    return(word.TranscriptionID == null? null: word.TranscriptionID.ToString());
                }
                break;

            case ServerData.WordForm:
                WordForm wordForm = _context.WordForms.Where(u => u.Id == id).FirstOrDefault();
                if (wordForm == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.PastForm:
                    return(wordForm.PastForm);

                case PropertyData.PastThForm:
                    return(wordForm.PastThForm);

                case PropertyData.PluralForm:
                    return(wordForm.PluralForm);
                }
                break;

            case ServerData.Group:
                WordsGroup group = _context.Groups.Where(u => u.Id == id).FirstOrDefault();
                if (group == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(group.Name);
                }
                break;

            case ServerData.WordCategory:
                WordCategory wordCategory = _context.WordCategories.Where(u => u.Id == id).FirstOrDefault();
                if (wordCategory == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(wordCategory.Name);

                case PropertyData.Abbreviation:
                    return(wordCategory.Abbreviation);
                }
                break;

            case ServerData.Transcription:
                Transcription transcription = _context.Transcriptions.Where(u => u.Id == id).FirstOrDefault();
                if (transcription == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.British:
                    return(transcription.British);

                case PropertyData.Canadian:
                    return(transcription.Canadian);

                case PropertyData.Australian:
                    return(transcription.Australian);

                case PropertyData.American:
                    return(transcription.American);
                }
                break;

            case ServerData.Translation:
                Translation translation = _context.Translations.Where(u => u.Id == id).FirstOrDefault();
                if (translation == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(translation.Name);
                }
                break;

            case ServerData.Definition:
                Definition definition = _context.Definitions.Where(u => u.Id == id).FirstOrDefault();
                if (definition == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(definition.Name);
                }
                break;

            case ServerData.Author:
                Author author = _context.Authors.Where(u => u.Id == id).FirstOrDefault();
                if (author == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(author.Name);

                case PropertyData.Surname:
                    return(author.Surname);
                }
                break;

            case ServerData.Example:
                Example example = _context.Examples.Where(u => u.Id == id).FirstOrDefault();
                if (example == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(example.Name);
                }
                break;

            case ServerData.VideoBookmark:
                VideoBookmark videoBookmark = _context.VideoBookmarks.Where(u => u.Id == id).FirstOrDefault();
                if (videoBookmark == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Position:
                    return(videoBookmark.Position.ToString());
                }
                break;

            case ServerData.Bookmark:
                Bookmark bookmark = _context.Bookmarks.Where(u => u.Id == id).FirstOrDefault();
                if (bookmark == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Position:
                    return(bookmark.Position.ToString());
                }
                break;
            }

            return(null);
        }
Ejemplo n.º 3
0
        public void AddItemData(int item, int cat, ServerData data)
        {
            switch (data)
            {
            case ServerData.VideoCategory:
                if (_context.Videos.Where(u => u.Id == item).FirstOrDefault() == null || _context.VideoCategories.Where(u => u.Id == cat).FirstOrDefault() == null)
                {
                    return;
                }
                _context.Videos.Where(u => u.Id == item).FirstOrDefault().Categories.Add(_context.VideoCategories.Where(u => u.Id == cat).FirstOrDefault());
                break;

            case ServerData.BookCategory:
                Book         book         = (_context.Books.Where(u => u.Id == item).FirstOrDefault());
                BookCategory bookCategory = _context.BookCategories.Where(u => u.Id == cat).FirstOrDefault();
                if (book == null || bookCategory == null)
                {
                    return;
                }
                book.Categories.Add(bookCategory);
                break;

            case ServerData.WordCategory:
                Word         word      = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                WordCategory wCategory = _context.WordCategories.Where(u => u.Id == cat).FirstOrDefault();
                if (word == null || wCategory == null)
                {
                    return;
                }
                word.Categories.Add(wCategory);
                break;

            case ServerData.Translation:
                Word        wordT = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                Translation tr    = _context.Translations.Where(u => u.Id == cat).FirstOrDefault();
                if (wordT == null || tr == null)
                {
                    return;
                }
                wordT.Translations.Add(tr);
                break;

            case ServerData.Definition:
                Word       wordD = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                Definition def   = _context.Definitions.Where(u => u.Id == cat).FirstOrDefault();
                if (wordD == null || def == null)
                {
                    return;
                }
                wordD.Descriptions.Add(def);
                break;

            case ServerData.Group:
                Word       wordG = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                WordsGroup gr    = _context.Groups.Where(u => u.Id == cat).FirstOrDefault();
                if (wordG == null || gr == null)
                {
                    return;
                }
                wordG.Groups.Add(gr);
                break;

            case ServerData.Example:
                Word    wordE = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                Example ex    = _context.Examples.Where(u => u.Id == cat).FirstOrDefault();
                if (wordE == null || ex == null)
                {
                    return;
                }
                ex.WordID = wordE.Id;
                break;

            case ServerData.GrammarExample:
                Grammar        grammar = (_context.Grammars.Where(u => u.Id == item).FirstOrDefault());
                GrammarExample example = _context.GrammarExamples.Where(u => u.Id == cat).FirstOrDefault();
                if (grammar == null || example == null)
                {
                    return;
                }
                grammar.Examples.Add(example);
                break;

            case ServerData.GrammarException:
                Grammar          grammarE  = (_context.Grammars.Where(u => u.Id == item).FirstOrDefault());
                GrammarException exception = _context.Exceptions.Where(u => u.Id == cat).FirstOrDefault();
                if (grammarE == null || exception == null)
                {
                    return;
                }
                grammarE.Exceptions.Add(exception);
                break;

            case ServerData.Rule:
                Grammar       grammarR = (_context.Grammars.Where(u => u.Id == item).FirstOrDefault());
                Entities.Rule rule     = _context.Rules.Where(u => u.Id == cat).FirstOrDefault();
                if (grammarR == null || rule == null)
                {
                    return;
                }
                grammarR.Rules.Add(rule);
                break;
            }
            _context.SaveChanges();
        }