示例#1
0
        public ActionResult DeleteResource(ResourceListViewModel res)
        {
            var itemID     = res.EditItemID;
            var categoryID = res.DeleteCategoryID;


            //A resource will be allowed in mulitple categories Thus delete this entries from this table
            var categoryItems = Exigo.GetResourceCategoryItems(new GetResourceCategoryItemsRequest()
            {
                ItemID = itemID
            });

            foreach (var item in categoryItems)
            {
                //2015-09-08
                //Ivan S.
                //66
                //Reorders the following resources (setting their order to a minus 1 value)
                var itemOrder         = item.ItemOrder;
                var categoryItemOrder = Exigo.GetResourceCategoryItems(new GetResourceCategoryItemsRequest()
                {
                    CategoryID = categoryID, ItemOrder = itemOrder
                }).ToList();
                foreach (var catitem in categoryItemOrder)
                {
                    catitem.ItemOrder = catitem.ItemOrder - 1;
                    Exigo.ModifyResourceCategoryItemOrder(catitem);
                }
            }
            //Delete the availabilitiy of the resource
            var availability = Exigo.GetResourceAvailabilities(new GetResourceAvailabilitiesRequest()
            {
                ItemID = itemID
            }).Select(v => v.AvailabilityID).ToList();

            Exigo.DeleteResourceAvailabilities(availability);

            //Delete The Tags Associated with the item
            var tags = Exigo.GetResourceItemTags(new GetResourceItemTagsRequest()
            {
                ItemID = itemID
            }).Select(t => t.TagID).ToList();

            Exigo.DeleteResourceItemTags(tags);

            //Delete the resource itself
            var resource = Exigo.GetResourceItems(new GetResourcesRequest()
            {
                ItemID = itemID
            }).FirstOrDefault();

            Exigo.DeleteResourceItem(resource);

            return(RedirectToAction("ManageResources"));
        }
示例#2
0
        public JsonNetResult EditResource(CreateResource res, string editID)
        {
            try
            {
                var itemID = Guid.Parse(editID);

                //Update ResoureItem

                ResourceItem originalResource = new ResourceItem()
                {
                    ItemID          = itemID,
                    Title           = res.Title,
                    ItemDescription = res.ItemDescription,
                    Url             = res.Url,
                    UrlThumbnail    = res.UrlThumbnail,
                    TypeID          = res.TypeID,
                    StatusID        = res.StatusID,
                    PostDate        = res.PostDate ?? DateTime.Now.ToCST(),
                    Language        = res.Language,
                    CreatedDate     = DateTime.Now.ToCST(),
                };

                Exigo.ModifyResourceItem(originalResource);

                //Current Availabilities
                List <ResourceAvailability> currentAvailability = Exigo.GetResourceAvailabilities(new GetResourceAvailabilitiesRequest()
                {
                    ItemID = originalResource.ItemID
                }).ToList();

                //Wanted Availabilities
                List <ResourceAvailability> keepAvailabilities   = new List <ResourceAvailability>();
                List <Available>            neededAvailabilities = new List <Available>();
                foreach (var market in res.Markets)
                {
                    var availability = new Available();
                    availability.Language = res.Language;
                    availability.Market   = market;
                    var exist = currentAvailability.Where(ca => ca.Language == availability.Language && ca.Market == availability.Market).FirstOrDefault();
                    if (exist == null)
                    {
                        neededAvailabilities.Add(availability);
                    }
                    else
                    {
                        keepAvailabilities.Add(exist);
                    }
                }



                //Add NEW Availabilities
                foreach (var avail in neededAvailabilities)
                {
                    ResourceAvailability availableresource = new ResourceAvailability()
                    {
                        AvailabilityID = Guid.NewGuid(),
                        ItemID         = originalResource.ItemID,
                        Market         = avail.Market,
                        Language       = avail.Language
                    };
                    Exigo.CreateResourceAvailabilities(availableresource);
                }

                //Delete Availabilities no longer wanted
                List <Guid> deleteAvailabilities = currentAvailability.Except(keepAvailabilities).Select(t => t.AvailabilityID).ToList();
                Exigo.DeleteResourceAvailabilities(deleteAvailabilities);

                //Modify ResourceCategoryItems

                // Current ResourceCategoryItems CategoryIDs
                var RCI = Exigo.GetResourceCategoryItems(new GetResourceCategoryItemsRequest()
                {
                    ItemID = originalResource.ItemID
                });
                var currentRCI = RCI.Select(rci => rci.CategoryID);

                // Wanted CategoryIDs
                var wantedRCI = res.CategoryID;

                // Needed CategoryIDs
                var neededRCI = wantedRCI.Except(currentRCI);

                //Add New CategoryItems


                foreach (var category in neededRCI)
                {
                    var lastResource = Exigo.GetResourceCategoryItems(new GetResourceCategoryItemsRequest()
                    {
                        CategoryID = category
                    })
                                       .OrderByDescending(r => r.ItemOrder)
                                       .FirstOrDefault();
                    int lastItemOrder = InitialOrderValue - 1;
                    if (lastResource != null)
                    {
                        lastItemOrder = lastResource.ItemOrder;
                    }

                    ResourceCategoryItem categoryItem = new ResourceCategoryItem()
                    {
                        ItemID     = originalResource.ItemID,
                        CategoryID = category,
                        ItemOrder  = lastItemOrder
                    };
                    Exigo.CreateResourceCategoryItem(categoryItem);
                }
                //Delete Unwanted CategoryItems
                var unwantedRCICategoryIDs = currentRCI.Except(wantedRCI).ToList();
                if (unwantedRCICategoryIDs.Any())
                {
                    Exigo.DeleteResourceCategoryItems(itemID, unwantedRCICategoryIDs);
                }


                List <Tag> tags = new List <Tag>();



                if (res.Keywords.Any())
                {
                    // check to see if tag existis with these keywords. if not add it

                    //Get A List Of Tags Using Provided Keywords
                    var existingTags = Exigo.GetTagsForResources(new GetTagsForResourcesRequest()
                    {
                        Names = res.Keywords
                    });
                    var existingTagNames = existingTags.Select(et => et.Name);

                    //Get a List of Keywords we need to make tags for
                    var newTagsneeded = res.Keywords.Except(existingTagNames);

                    //Create The New Tags
                    List <Tag> NewlyCreatedTags = new List <Tag>();
                    foreach (var keyword in newTagsneeded)
                    {
                        Tag newTag = new Tag()
                        {
                            TagID = Guid.NewGuid(),
                            Name  = keyword
                        };
                        NewlyCreatedTags.Add(newTag);
                        Exigo.CreateTag(newTag);
                    }

                    //Combine existing and New Tags
                    var completeTagList = existingTags.Union(NewlyCreatedTags).ToList();
                    var completeTagIDs  = completeTagList.Select(v => v.TagID);

                    //Get a list of ItemTags currently associated with the Item
                    var currentItemTagIDs = Exigo.GetResourceItemTags(new GetResourceItemTagsRequest()
                    {
                        ItemID = originalResource.ItemID
                    }).Select(v => v.TagID);

                    //Get a list of Tags we need to make ItemTags for
                    var newItemTagsneeded = completeTagList.Where(t => !currentItemTagIDs.Contains(t.TagID));

                    // Update ResourceItemTags Table with new Tags
                    foreach (var tagneeded in newItemTagsneeded)
                    {
                        ResourceItemTag rit = new ResourceItemTag()
                        {
                            TagID  = tagneeded.TagID,
                            ItemID = itemID,
                        };
                        Exigo.CreateResourceItemTag(rit);
                    }

                    // remove any pivot table tags that are no longer being used for this resource
                    var nolongerwanted = currentItemTagIDs.Except(completeTagIDs).ToList();
                    if (nolongerwanted.Count > 0)
                    {
                        Exigo.DeleteResourceItemTags(nolongerwanted);
                    }
                }

                return(new JsonNetResult(new
                {
                    success = true,
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }