Пример #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"));
        }