コード例 #1
0
        /// <summary>
        /// Adds the given relationship to this node.
        /// </summary>
        /// <param name="relationship">The relationship to add</param>
        /// <param name="relatedNode">The related node</param>
        public void AddRelationship(IRelationship relationship, INode relatedNode)
        {
            NodeContentType relatedType;
            Guid            relatedId;

            if (Guid.TryParse(relatedNode["id"].As <string>(), out relatedId) && Enum.TryParse <NodeContentType>(relatedNode.Labels[0], out relatedType))
            {
                // Create the relationship
                RelationshipModel relModel = new RelationshipModel
                {
                    SourceId   = Id,
                    TargetId   = relatedId,
                    TargetName = relatedNode["commonName"].As <string>(),
                    Roles      = relationship["roles"].As <List <string> >()
                };

                // Add the relationship to the correct list
                if (relatedType == NodeContentType.Company)
                {
                    RelatedCompanies.Add(relModel);
                }
                else if (relatedType == NodeContentType.Media)
                {
                    RelatedMedia.Add(relModel);
                }
                else if (relatedType == NodeContentType.Person)
                {
                    RelatedPeople.Add(relModel);
                }
            }
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            RelatedMedia relatedMedia = db.RelatedMedia.Find(id);

            db.RelatedMedia.Remove(relatedMedia);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,MediaLink,Format,Duration")] RelatedMedia relatedMedia)
 {
     if (ModelState.IsValid)
     {
         db.Entry(relatedMedia).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(relatedMedia));
 }
コード例 #4
0
        public ActionResult Create([Bind(Include = "Id,MediaLink,Format,Duration")] RelatedMedia relatedMedia)
        {
            if (ModelState.IsValid)
            {
                db.RelatedMedia.Add(relatedMedia);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(relatedMedia));
        }
コード例 #5
0
        // GET: RelatedMedia/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RelatedMedia relatedMedia = db.RelatedMedia.Find(id);

            if (relatedMedia == null)
            {
                return(HttpNotFound());
            }
            return(View(relatedMedia));
        }
コード例 #6
0
        public ActionResult GetPaged(RelatedMedia model)
        {
            // Don't inherits RelatedMedia from first post
            ModelState.Clear();

            var viewModel = new RelatedMedia()
            {
                Id           = model.Id,
                ItemsPerPage = model.ItemsPerPage <= 0 ? 5 : model.ItemsPerPage,
                Page         = model.Page <= 0 ? 1 : model.Page,
                Properties   = model.Properties,
                Tags         = model.Tags,
                Exclude      = model.Exclude
            };
            //var excludes = new List<string>();
            var excludes = viewModel.Exclude.Select(x => x.ToString()).ToList();

            excludes.Add(CurrentPage.Id.ToString());

            var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
            var creteria = searcher.CreateSearchCriteria();
            var query    = creteria.GroupedOr(viewModel.Properties, viewModel.Tags.Select(x => x.Id.ToString()).ToArray())
                           .Not()
                           .GroupedOr(new string[] { "id" }, excludes.ToArray());

            var searchResult = Umbraco.TypedSearch(query.Compile(), searcher);

            LogHelper.Debug <RelatedMediaController>("Searched with: {0}\nGot content: {1}",
                                                     () => query.ToString(),
                                                     () => string.Join(",", searchResult.Select(x => x.Id).ToArray())
                                                     );

            var result = searchResult.Skip(viewModel.Skips)
                         .Take(viewModel.ItemsPerPage)
                         .Select(x => new MediaListItem(x));

            viewModel.Result     = result.ToList();
            viewModel.Page       = viewModel.Page + 1;
            viewModel.TotalPages = Math.Ceiling((decimal)searchResult.Count() / viewModel.ItemsPerPage);

            return(PartialView("~/Views/Partials/Shared/_RelatedMedia.cshtml", viewModel));
        }