示例#1
0
        /// <summary>
        /// 更新栏目
        /// </summary>
        /// <param name="category">栏目</param>
        /// <param name="link">链接信息</param>
        /// <returns></returns>
        public Response Update(Model.Category.Category category, CategoryLink link)
        {
            Response _response = new Response()
            {
                Code = 1
            };

            _response = base.Update(category);
            if (_response.Code == 1)
            {
                link.CategoryID = category.ID;
                var _linkManager = new CategoryLinkManager();
                if (link.ID == 0)
                {
                    _response = _linkManager.Add(link);
                }
                else
                {
                    _response = _linkManager.Update(link);
                }
            }
            if (_response.Code == 1)
            {
                _response.Message = "更新栏目成功!";
            }
            return(_response);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductId,CategoryId")] CategoryLink categoryLink)
        {
            if (id != categoryLink.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(categoryLink);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryLinkExists(categoryLink.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Id", categoryLink.CategoryId);
            ViewData["ProductId"]  = new SelectList(_context.Product, "Id", "Id", categoryLink.ProductId);
            return(View(categoryLink));
        }
        /// <summary>
        /// segregated only link funtionality of categories
        /// </summary>
        /// <param name="IdsStudyVariables">comma seperated values of variable ids to be un linked</param>
        /// <param name="IdsTaxonomyVariables">comma seperated values of  taxonomy variable ids to be un linked</param>
        /// <returns></returns>
        private static void LinkCategories(string[] ArrIdsStudyCategories, string[] ArrIdsTaxonomyCategories)
        {
            TaxonomyCategory taxonomyCategory = Global.Core.TaxonomyCategories.GetSingle(new Guid(ArrIdsTaxonomyCategories[0]));

            for (int i = 0; i < ArrIdsStudyCategories.Count(); i++)
            {
                Category category = Global.Core.Categories.GetSingle(new Guid(ArrIdsStudyCategories[i]));

                foreach (var taxonomyCategories in ArrIdsTaxonomyCategories)
                {
                    List <object[]> categoryLinks = Global.Core.CategoryLinks.GetValues(new string[] { "Id" }, new string[] { "IdCategory", "IdTaxonomyCategory", "IdVariable", "IdTaxonomyVariable" }, new object[] { ArrIdsStudyCategories[i], taxonomyCategories, category.IdVariable, taxonomyCategory.IdTaxonomyVariable });

                    if (categoryLinks.Count() == 0)
                    {
                        CategoryLink categoryLink = new CategoryLink(Global.Core.CategoryLinks);
                        categoryLink.IdCategory         = new Guid(ArrIdsStudyCategories[i]);
                        categoryLink.IdTaxonomyCategory = new Guid(taxonomyCategories);
                        categoryLink.IdVariable         = category.IdVariable;
                        categoryLink.IdTaxonomyVariable = taxonomyCategory.IdTaxonomyVariable;
                        categoryLink.CreationDate       = DateTime.Now;
                        categoryLink.Insert();
                    }
                }
            }
        }
        /// <summary>
        /// 添加外部链接
        /// </summary>
        /// <returns></returns>
        public ActionResult AddLink()
        {
            var _link = new CategoryLink()
            {
                Url = "http://"
            };

            return(View(_link));
        }
示例#5
0
        public virtual CategoryRelationEntity FromModel(CategoryLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            TargetCategoryId = link.CategoryId;
            TargetCatalogId  = link.CatalogId;

            return(this);
        }
        public virtual CategoryLink ToModel(CategoryLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            link.CategoryId = TargetCategoryId;
            link.CatalogId  = TargetCatalogId;

            return(link);
        }
        public async Task <IActionResult> Create([Bind("Id,ProductId,CategoryId")] CategoryLink categoryLink)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categoryLink);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Id", categoryLink.CategoryId);
            ViewData["ProductId"]  = new SelectList(_context.Product, "Id", "Id", categoryLink.ProductId);
            return(View(categoryLink));
        }
        public virtual CategoryItemRelationEntity FromModel(CategoryLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            this.CategoryId = link.CategoryId;
            this.CatalogId  = link.CatalogId;
            this.Priority   = link.Priority;

            return(this);
        }
示例#9
0
        public virtual CategoryLink ToModel(CategoryLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            link.ListEntryId = ItemId;
            link.CategoryId  = CategoryId;
            link.CatalogId   = CatalogId;
            link.Priority    = Priority;

            return(link);
        }
示例#10
0
        /// <summary>
        /// 添加栏目
        /// </summary>
        /// <param name="category">基本信息</param>
        /// <param name="link">链接栏目信息</param>
        /// <returns></returns>
        public Response Add(Model.Category.Category category, CategoryLink link)
        {
            Response _response = new Response()
            {
                Code = 1
            };

            _response       = base.Add(category);
            link.CategoryID = category.ID;
            var _linkManager = new CategoryLinkManager();

            _linkManager.Add(link);
            return(_response);
        }
        /// <summary>
        /// 链接栏目
        /// </summary>
        /// <param name="id">栏目ID</param>
        /// <returns></returns>
        public ActionResult ModifyLink(int id)
        {
            var _linkManager = new CategoryLinkServices();
            var _link        = _linkManager.Find(id);

            if (_link == null)
            {
                _link = new CategoryLink()
                {
                    Url = "http://"
                }
            }
            ;
            return(PartialView(_link));
        }
示例#12
0
        public static string Link(string IdTaxonomyCategory, string IdCategory, string IdVariable, string IdTaxonomyVariable)
        {
            VariableLink variableLink = new VariableLink(Global.Core.VariableLinks);

            List <object[]> variableLinks = Global.Core.VariableLinks.GetValues(
                new string[] { "Id" },
                new string[] { "IdVariable", "IdTaxonomyVariable" },
                new object[] { IdVariable, IdTaxonomyVariable });

            variableLink.IdVariable         = new Guid(IdVariable);
            variableLink.IdTaxonomyVariable = new Guid(IdTaxonomyVariable);
            variableLink.CreationDate       = DateTime.Now;

            if (variableLinks.Count() == 0)
            {
                variableLink.Insert();
            }

            CategoryLink categoryLink = new CategoryLink(Global.Core.CategoryLinks);

            categoryLink.IdCategory         = new Guid(IdCategory);
            categoryLink.IdTaxonomyCategory = new Guid(IdTaxonomyCategory);
            categoryLink.IdVariable         = new Guid(IdVariable);
            categoryLink.IdTaxonomyVariable = new Guid(IdTaxonomyVariable);
            categoryLink.CreationDate       = DateTime.Now;

            List <object[]> categoryLinks = Global.Core.CategoryLinks.GetValues(
                new string[] { "Id" },
                new string[] {
                "IdCategory",
                "IdTaxonomyCategory",
                "IdVariable",
                "IdTaxonomyVariable"
            },
                new object[] {
                IdCategory,
                IdTaxonomyCategory,
                IdVariable,
                IdTaxonomyVariable
            });

            if (categoryLinks.Count() == 0)
            {
                categoryLink.Insert();
            }

            return("sucess");
        }
        public ActionResult Add()
        {
            Category _category = new Category();

            TryUpdateModel(_category, new string[] { "Type", "ParentID", "Name", "Description", "Order", "Target" });
            if (ModelState.IsValid)
            {
                //检查父栏目
                if (_category.ParentID > 0)
                {
                    var _parentCategory = categoryManager.Find(_category.ParentID);
                    if (_parentCategory == null)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不存在,请刷新后重新添加");
                    }
                    else if (_parentCategory.Type != CategoryType.General)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不允许添加子栏目");
                    }
                    else
                    {
                        _category.ParentPath = _parentCategory.ParentPath + "," + _parentCategory.CategoryID;
                        _category.Depth      = _parentCategory.Depth + 1;
                    }
                }
                else
                {
                    _category.ParentPath = "0";
                    _category.Depth      = 0;
                }
                //栏目基本信息保存
                Response _response = new Response()
                {
                    Code = 0, Message = "初始失败信息"
                };
                //根据栏目类型进行处理
                switch (_category.Type)
                {
                case CategoryType.General:
                    var _general = new CategoryGeneral();
                    TryUpdateModel(_general);
                    _response = categoryManager.Add(_category, _general);
                    break;

                case CategoryType.Page:
                    var _page = new CategoryPage();
                    TryUpdateModel(_page);
                    _response = categoryManager.Add(_category, _page);
                    break;

                case CategoryType.Link:
                    var _link = new CategoryLink();
                    TryUpdateModel(_link);
                    _response = categoryManager.Add(_category, _link);
                    break;
                }
                if (_response.Code == 1)
                {
                    return(View("Prompt", new Prompt()
                    {
                        Title = "添加栏目成功", Message = "添加栏目【" + _category.Name + "】成功"
                    }));
                }
                else
                {
                    return(View("Prompt", new Prompt()
                    {
                        Title = "添加失败", Message = "添加栏目【" + _category.Name + "】时发生系统错误,未能保存到数据库,请重试"
                    }));
                }
            }
            //var _parentCategoryList = ComboTreeList();
            //_parentCategoryList.Insert(0, new SelectListItem() { Text = "无", Value = "0" });
            //ViewBag.ParentCategoryList = _parentCategoryList;
            return(View(_category));
        }
        public ActionResult Modify(int id, FormCollection form)
        {
            Category _category = categoryManager.Find(id);

            if (_category == null)
            {
                return(View("Prompt", new Prompt()
                {
                    Title = "错误", Message = "栏目不存在!"
                }));
            }
            if (TryUpdateModel(_category, new string[] { "Type", "ParentID", "Name", "Description", "Order", "Target" }))
            {
                //检查父栏目
                if (_category.ParentID > 0)
                {
                    var _parentCategory = categoryManager.Find(_category.ParentID);
                    if (_parentCategory == null)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不存在,请刷新后重新添加");
                    }
                    else if (_parentCategory.Type != CategoryType.General)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不允许添加子栏目");
                    }
                    else if (_parentCategory.ParentPath.IndexOf(_category.ParentPath) >= 0)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不能是其本身或其子栏目");
                    }
                    else
                    {
                        _category.ParentPath = _parentCategory.ParentPath + "," + _parentCategory.CategoryID;
                        _category.Depth      = _parentCategory.Depth + 1;
                    }
                }
                else
                {
                    _category.ParentPath = "0";
                    _category.Depth      = 0;
                }
                //栏目基本信息保存
                Response _response = new Response()
                {
                    Code = 0, Message = "初始失败信息"
                };
                //根据栏目类型进行处理
                switch (_category.Type)
                {
                case CategoryType.General:
                    var _generalManager = new CategoryGeneralServices();
                    var _general        = _generalManager.Find(id);
                    if (_general == null)
                    {
                        _general = new CategoryGeneral()
                        {
                            CategoryID = id, View = "Index", ContentView = "Index"
                        }
                    }
                    ;
                    if (TryUpdateModel(_general))
                    {
                        _response = categoryManager.Update(_category, _general);
                    }
                    break;

                case CategoryType.Page:
                    var _pageManager = new CategoryPageServices();
                    var _page        = _pageManager.Find(id);
                    if (_page == null)
                    {
                        _page = new CategoryPage()
                        {
                            CategoryID = id, View = "index"
                        }
                    }
                    ;
                    if (TryUpdateModel(_page))
                    {
                        _response = categoryManager.Update(_category, _page);
                    }
                    break;

                case CategoryType.Link:
                    var _linkManager = new CategoryLinkServices();
                    var _link        = _linkManager.Find(id);
                    if (_link == null)
                    {
                        _link = new CategoryLink()
                        {
                            CategoryID = id, Url = "http://"
                        }
                    }
                    ;
                    if (TryUpdateModel(_link))
                    {
                        _response = categoryManager.Update(_category, _link);
                    }
                    break;
                }
                if (ModelState.IsValid)
                {
                    if (_response.Code == 1)
                    {
                        return(View("Prompt", new Prompt()
                        {
                            Title = "修改栏目成功", Message = "修改栏目【" + _category.Name + "】成功"
                        }));
                    }
                    else
                    {
                        return(View("Prompt", new Prompt()
                        {
                            Title = "修改栏目失败", Message = "修改栏目【" + _category.Name + "】时发生系统错误,未能保存到数据库,请重试"
                        }));
                    }
                }
            }
            return(View(_category));
        }
示例#15
0
 public ListEntryLink(CategoryLink link)
 {
     CatalogId   = link.CatalogId;
     CategoryId  = link.CategoryId;
     ListEntryId = link.SourceItemId;
 }
示例#16
0
        /// <summary>
        /// 更新栏目
        /// </summary>
        /// <param name="category">栏目</param>
        /// <param name="link">链接信息</param>
        /// <returns></returns>
        public Response Update(ContentManageSystem.Entity.Models.Category.Category category, CategoryLink link)
        {
            Response _response = new Response()
            {
                Code = 1
            };

            _response = base.Update(category);
            if (_response.Code == 1)
            {
                link.CategoryID = category.CategoryID;
                var _linkManager = new CategoryLinkServices();
                if (link.CategoryLinkID == 0)
                {
                    _response = _linkManager.Add(link);
                }
                else
                {
                    _response = _linkManager.Update(link);
                }
            }
            if (_response.Code == 1)
            {
                _response.Message = "更新栏目成功!";
            }
            return(_response);
        }
示例#17
0
        /// <summary>
        /// 添加栏目
        /// </summary>
        /// <param name="category">基本信息</param>
        /// <param name="link">链接栏目信息</param>
        /// <returns></returns>
        public Response Add(ContentManageSystem.Entity.Models.Category.Category category, CategoryLink link)
        {
            Response _response = new Response()
            {
                Code = 1
            };

            _response       = base.Add(category);
            link.CategoryID = category.CategoryID;
            var _linkManager = new CategoryLinkServices();

            _linkManager.Add(link);
            return(_response);
        }
        /// <summary>
        /// For Linking Variables and Categories
        /// </summary>
        /// <param name="context"></param>
        public void Link(HttpContext context)
        {
            Guid IdTaxonomyCategory = Guid.Parse(context.Request.Params["IdTaxonomyCategory"]);
            Guid IdCategory         = Guid.Parse(context.Request.Params["IdCategory"]);
            Guid IdVariable         = Guid.Parse(context.Request.Params["IdVariable"]);
            Guid IdTaxonomyVariable = Guid.Parse(context.Request.Params["IdTaxonomyVariable"]);

            VariableLink variableLink = new VariableLink(Global.Core.VariableLinks);

            List <object[]> variableLinks = Global.Core.VariableLinks.GetValues(
                new string[] { "Id" },
                new string[] { "IdVariable", "IdTaxonomyVariable" },
                new object[] { IdVariable, IdTaxonomyVariable });

            ArrayList categoriesLinkList = new ArrayList();

            variableLink.IdVariable         = IdVariable;
            variableLink.IdTaxonomyVariable = IdTaxonomyVariable;
            variableLink.CreationDate       = DateTime.Now;

            if (variableLinks.Count() == 0)
            {
                variableLink.Insert();
            }

            CategoryLink categoryLink = new CategoryLink(Global.Core.CategoryLinks);

            categoryLink.IdVariable         = IdVariable;
            categoryLink.IdCategory         = IdCategory;
            categoryLink.IdTaxonomyCategory = IdTaxonomyCategory;
            categoryLink.IdTaxonomyVariable = IdTaxonomyVariable;
            categoryLink.CreationDate       = DateTime.Now;

            List <object[]> categoryLinks = Global.Core.CategoryLinks.GetValues(
                new string[] { "Id" },
                new string[] {
                "IdCategory",
                "IdTaxonomyCategory",
                "IdVariable",
                "IdTaxonomyVariable"
            },
                new object[] {
                IdCategory,
                IdTaxonomyCategory,
                IdVariable,
                IdTaxonomyVariable
            });

            if (categoryLinks.Count() == 0)
            {
                categoryLink.Insert();
            }


            foreach (var item in categoryLinks)
            {
                dynamic variable = new { IdVariable = IdVariable, IdCategory = IdCategory, IdTaxonomyCategory = IdTaxonomyCategory, IdTaxonomyVariable = IdTaxonomyVariable };
                categoriesLinkList.Add(variable);
            }

            string jSon = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(categoriesLinkList);

            context.Response.Write(jSon);

            //context.Response.Write("success");
        }
示例#19
0
        public ActionResult Add(Category _category)
        {
            if (ModelState.IsValid)
            {
                //检查父栏目
                if (_category.ParentID > 0)
                {
                    var _parentCategory = categoryManager.Find(_category.ParentID);
                    if (_parentCategory == null)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不存在,请刷新后重新添加");
                    }
                    else if (_parentCategory.Type != CategoryType.General)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不允许添加子栏目");
                    }
                    else
                    {
                        _category.ParentPath = _parentCategory.ParentPath + "," + _parentCategory.ID;
                        _category.Depth      = _parentCategory.Depth + 1;
                    }
                }
                else
                {
                    _category.ParentPath = "0";
                    _category.Depth      = 0;
                }
                //栏目基本信息保存
                Response _response = new Response()
                {
                    Code = 0, Message = "初始失败信息"
                };
                //根据栏目类型进行处理
                switch (_category.Type)
                {
                case CategoryType.General:
                    var _general = new CategoryGeneral();
                    TryUpdateModel(_general);
                    _response = categoryManager.Add(_category, _general);
                    break;

                case CategoryType.Page:
                    return(View("Prompt", new Prompt()
                    {
                        Title = "暂未实现", Message = "暂未实现单页栏目添加"
                    }));

                    var _page = new CategoryPage();
                    TryUpdateModel(_page);
                    _response = categoryManager.Add(_category, _page);
                    break;

                case CategoryType.Link:
                    return(View("Prompt", new Prompt()
                    {
                        Title = "暂未实现", Message = "暂未实现外部链接添加"
                    }));

                    var _link = new CategoryLink();
                    TryUpdateModel(_link);
                    _response = categoryManager.Add(_category, _link);
                    break;
                }
                if (_response.Code == 1)
                {
                    return(View("Prompt", new WebPage.Models.Prompt()
                    {
                        Title = "添加栏目成功", Message = "添加栏目【" + _category.Name + "】成功"
                    }));
                }
                else
                {
                    return(View("Prompt", new Prompt()
                    {
                        Title = "添加失败", Message = "添加栏目【" + _category.Name + "】时发生系统错误,未能保存到数据库,请重试"
                    }));
                }
            }
            return(View(_category));
        }