Beispiel #1
0
        private bool AllSnippetsView_Filter(object obj)
        {
            if (String.IsNullOrEmpty(FilterText))
            {
                return(true);
            }

            SnippetViewModel currentSnippet  = (SnippetViewModel)obj;
            string           lowerFilterText = FilterText.ToLower();

            if (currentSnippet.Name.ToLower().Contains(lowerFilterText))
            {
                return(true);
            }
            if (currentSnippet.Language.Name.ToLower().Contains(lowerFilterText))
            {
                return(true);
            }
            if (currentSnippet.Tags.ToLower().Contains(lowerFilterText))
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public SnippetViewModel GetSnippetDetails(int id)
        {
            Snippet          snippet   = this.Context.Snippets.FirstOrDefault(s => s.Id == id);
            SnippetViewModel snippetVm = Mapper.Map <Snippet, SnippetViewModel>(snippet);

            return(snippetVm);
        }
        public EditSnippetViewModel(Guid snippetID)
        {
            Snippet sn = DataService.Instance.Snippets.FirstOrDefault(x => x.ID == snippetID);
            List <LanguageViewModel> lVM = new List <LanguageViewModel>(); List <TagViewModel> tVM = new List <TagViewModel>();

            DataService.Instance.Languages.ForEach(x => lVM.Add(new LanguageViewModel(x)));
            Snippet = new SnippetViewModel(sn, lVM);
        }
        public EditSnippetDialogViewModel(Guid snippetID)
        {
            Snippet sn = (Snippet)DataContext.Instance.Snippets.FirstOrDefault(x => x.ID == snippetID).Clone();   //Damit nicht nur die Instanz übergeben wird
            List <LanguageViewModel> lVM = new List <LanguageViewModel>();

            DataContext.Instance.Languages.ForEach(x => lVM.Add(new LanguageViewModel(x)));
            Snippet = new SnippetViewModel(sn, lVM);
        }
        public AddSnippetDialogViewModel()
        {
            List <LanguageViewModel> lVM = new List <LanguageViewModel>(); DataContext.Instance.Languages.ForEach(x => lVM.Add(new LanguageViewModel(x)));

            Model.Snippet sModel = new Model.Snippet(); sModel.Name = ""; sModel.LanguageID = lVM.FirstOrDefault().ID;
            sModel.SnippetEnitries = new List <Model.SnippetEnitry>();
            Snippet = new SnippetViewModel(sModel, lVM);
        }
        public ActionResult CodeSnippet(SnippetViewModel snippet)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Snippet newSnippet = new Snippet();
                    newSnippet.Name        = snippet.Name.Trim();
                    newSnippet.Description = snippet.Description.Trim();
                    newSnippet.GroupName   = snippet.GroupName.ToLower().Trim();
                    newSnippet.Keys        = _utilityService.ResolveKeys(snippet.Keys);
                    newSnippet.DateCreated = DateTime.Now;
                    if (!string.IsNullOrEmpty(snippet.Website))
                    {
                        newSnippet.Website = snippet.Website.Trim();
                    }
                    newSnippet.Code = snippet.Code;
                    newSnippet.ProgrammingLanguageID = snippet.ProgrammingLanguageID;

                    try
                    {
                        _snippetService.CreateSnippet(newSnippet);
                        _snippetService.SaveSnippet();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        var errorMessages = ex.EntityValidationErrors
                                            .SelectMany(x => x.ValidationErrors)
                                            .Select(x => x.ErrorMessage);

                        // Join the list to a single string.
                        var fullErrorMessage = string.Join("; ", errorMessages);

                        // Combine the original exception message with the new one.
                        var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                        // Throw a new DbEntityValidationException with the improved exception message.
                        throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                    }

                    SetLanguagesTypes();
                    return(RedirectToAction("Code", "Snippets", new { id = newSnippet.ID })
                           .WithSuccess(newSnippet.Name + " saved successfully."));
                }
                else
                {
                    ModelState.AddModelError("", "Validation errors occured.");

                    SetLanguagesTypes();
                    return(View(snippet));
                }
            }
            catch (Exception ex)
            {
                SetLanguagesTypes();
                return(View(snippet).WithError(ex.Message));
            }
        }
        public ActionResult Edit(SnippetViewModel snippet)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Snippet editedSnippet = _snippetService.GetSnippet(snippet.ID);
                    editedSnippet.Name                  = snippet.Name.Trim();
                    editedSnippet.Description           = snippet.Description.Trim();
                    editedSnippet.GroupName             = snippet.GroupName.Trim();
                    editedSnippet.ProgrammingLanguageID = snippet.ProgrammingLanguageID;
                    editedSnippet.Keys.Clear();
                    editedSnippet.Keys    = _utilityService.ResolveKeys(snippet.Keys);
                    editedSnippet.Website = snippet.Website;
                    editedSnippet.Code    = snippet.Code;

                    try
                    {
                        _snippetService.SaveSnippet();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        var errorMessages = ex.EntityValidationErrors
                                            .SelectMany(x => x.ValidationErrors)
                                            .Select(x => x.ErrorMessage);

                        // Join the list to a single string.
                        var fullErrorMessage = string.Join("; ", errorMessages);

                        // Combine the original exception message with the new one.
                        var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                        // Throw a new DbEntityValidationException with the improved exception message.
                        throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                    }

                    SetLanguageTypes(snippet);

                    return(View(snippet).WithSuccess(snippet.Name + " succesfully updated."));
                }
                else
                {
                    ModelState.AddModelError("", "Validation errors occured.");

                    SetLanguageTypes(snippet);
                    return(View(snippet));
                }
            }
            catch (Exception ex)
            {
                SetLanguageTypes(snippet);
                return(View(snippet).WithError(ex.Message));
            }
        }
        private void SetLanguageTypes(SnippetViewModel selectedSnippet)
        {
            var languageTypes = _languageService.GetProgrammingLanguages();

            ViewBag.LanguageID = new SelectList(languageTypes,
                                                "ID", "Name", selectedSnippet.ProgrammingLanguageID);

            if (string.IsNullOrEmpty(selectedSnippet.ProgrammingLanguageName))
            {
                selectedSnippet.ProgrammingLanguageName = languageTypes
                                                          .FirstOrDefault(t => t.ID == selectedSnippet.ProgrammingLanguageID).Name;
            }

            ViewBag.SelectedLanguage = selectedSnippet;
        }
Beispiel #9
0
        public async Task <List <SnippetViewModel> > Search(string artist)
        {
            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = YoutubeApiKey,
                ApplicationName = this.GetType().ToString()
            });

            var searchListRequest = youtubeService.Search.List("snippet");

            searchListRequest.Q          = artist; // Replace with your search term.
            searchListRequest.MaxResults = 50;

            // Call the search.list method to retrieve results matching the specified query term.
            var searchListResponse = await searchListRequest.ExecuteAsync();

            List <SnippetViewModel> results = new List <SnippetViewModel>();

            // Add each result to the appropriate list, and then display the lists of
            // matching videos, channels, and playlists.
            foreach (var searchResult in searchListResponse.Items)
            {
                SnippetViewModel currentSnippet = new SnippetViewModel()
                {
                    id    = searchResult.Id.VideoId,
                    title = searchResult.Snippet.Title,
                };

                switch (searchResult.Id.Kind)
                {
                case "youtube#video":
                    currentSnippet.kind = YTool.Bases.Enums.YoutubeSnippetKind.video;
                    break;

                case "youtube#channel":
                    currentSnippet.kind = YTool.Bases.Enums.YoutubeSnippetKind.channel;
                    break;

                case "youtube#playlist":
                    currentSnippet.kind = YTool.Bases.Enums.YoutubeSnippetKind.playlist;
                    break;
                }
                results.Add(currentSnippet);
            }

            return(results);
        }
Beispiel #10
0
        private void UpdateEditor(SnippetDescriptor descriptor, ElementEditorContext context)
        {
            var viewModel = new SnippetViewModel {
                Descriptor = descriptor
            };

            if (context.Updater != null)
            {
                foreach (var fieldDescriptor in descriptor.Fields)
                {
                    var name   = fieldDescriptor.Name;
                    var result = context.ValueProvider.GetValue(name);

                    if (result == null)
                    {
                        continue;
                    }

                    context.Element.Data[name] = result.AttemptedValue;
                }
            }

            viewModel.FieldEditors = descriptor.Fields.Select(x => {
                var fieldEditorTemplateName  = $"Elements.Snippet.Field.{x.Type ?? "Text"}";
                var fieldDescriptorViewModel = new SnippetFieldViewModel {
                    Descriptor = x,
                    Value      = context.Element.Data.Get(x.Name)
                };
                var fieldEditor = context.ShapeFactory.EditorTemplate(TemplateName: fieldEditorTemplateName, Model: fieldDescriptorViewModel, Prefix: context.Prefix);

                return(fieldEditor);
            }).ToList();

            var snippetEditorShape = context.ShapeFactory.EditorTemplate(TemplateName: "Elements.Snippet", Model: viewModel, Prefix: context.Prefix);

            snippetEditorShape.Metadata.Position = "Fields:0";

            context.EditorResult.Add(snippetEditorShape);
        }
Beispiel #11
0
        // PUT: api/Default/5
        public IHttpActionResult Put(SnippetViewModel snippet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var context = new AspectKnowledgebaseContext())
            {
                // Linq
                var existingSnippet = context.Snippets.Where(s => s.Id == snippet.Id)
                                      .FirstOrDefault <Snippet>();
                if (existingSnippet != null)
                {
                    existingSnippet.Code    = snippet.Code;
                    existingSnippet.Subject = snippet.Subject;
                    //existingSnippet.Tags = snippet;
                }
                else
                {
                    return(NotFound());
                }

                var newTags = snippet.Tags;

                var existingTags = existingSnippet.Tags.ToList();


                foreach (var tag in existingTags)
                {
                    var doesTagAlreadyExist = newTags.Any(o => o.Id == tag.Id);
                    if (!doesTagAlreadyExist)
                    {
                        existingSnippet.Tags.Remove(tag);
                    }
                }

                foreach (var tag in newTags)
                {
                    var doesTagAlreadyExist = existingTags.Any(o => o.Id == tag.Id);
                    if (!doesTagAlreadyExist)
                    {
                        var foundTag = context.Tags.FirstOrDefault(t => t.Id == tag.Id);
                        if (foundTag != null)
                        {
                            existingSnippet.Tags.Add(foundTag);
                        }
                        else
                        {
                            var newTag = new Tag()
                            {
                                Name = tag.Name
                            };
                            context.Tags.Add(newTag);
                            existingSnippet.Tags.Add(newTag);
                        }
                    }
                }
                context.Entry(existingSnippet).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
            return(Ok());
        }
Beispiel #12
0
        public ActionResult Details(int id)
        {
            SnippetViewModel model = this.services.GetSnippetDetails(id);

            return(View(model));
        }
Beispiel #13
0
 // POST: odata/Snippets
 public IHttpActionResult Post(SnippetViewModel snippet)
 {
     return(StatusCode(HttpStatusCode.NotImplemented));
 }