// GET: Category/Details/5
        public ActionResult Details(int id)
        {
            CategoryDal pd       = new CategoryDal();
            var         category = pd.CategoryDetail(id);

            return(View(category));
        }
        // GET: Category/Delete/5
        public ActionResult Delete(int id)
        {
            CategoryDal ct       = new CategoryDal();
            var         category = ct.CategoryDetail(id);

            return(View(category));
        }
Example #3
0
 private void cbCategories_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         var bookList     = new BookDal().GetAll();
         var categoryList = new CategoryDal().GetAll();
         dgvBooks.DataSource =
             bookList
             .Join(categoryList,
                   b => b.CategoryId,
                   c => c.CategoryId,
                   (b, c) => new
         {
             Id           = b.Id,
             Title        = b.Title,
             Description  = b.Description,
             Year         = b.Year,
             CategoryId   = c.CategoryId,
             CategoryName = c.CategoryName
         })
             .Where(b => b.CategoryId == Convert.ToInt32(cbCategories.SelectedValue.ToString()))
             .ToList();
     }
     catch
     {
     }
 }
Example #4
0
        public IActionResult Index()
        {
            string      str     = "";
            Random      r       = new Random();
            BlogDal     blogdal = new BlogDal();
            CategoryDal cadal   = new CategoryDal();

            List <Model.Category> list_ca = cadal.GetList("");

            for (int i = 0; i < 102; i++)
            {
                string         title  = $"新闻标题{i}";
                string         body   = title + "的内容";
                Model.Category ca     = list_ca[r.Next(0, list_ca.Count)];
                string         cabh   = ca.Num,
                               caname = ca.CaName;

                blogdal.Insert(new Model.Blog
                {
                    Title    = title,
                    Body     = body,
                    VisitNum = r.Next(100, 999),
                    CaNum    = cabh,
                    CaName   = caname,
                });
            }
            str = "添加102条测试新闻成功!";

            return(Content(str));
        }
        // GET: Category
        public ActionResult Index()
        {
            CategoryDal pd         = new CategoryDal();
            var         categories = pd.CategoryList();

            return(View(categories));
        }
Example #6
0
        public int EditCategory(int id, string name)
        {
            ValidateName(name);

            var categoryDal = new CategoryDal();

            return(categoryDal.EditCategory(id, name));
        }
Example #7
0
        public static CategoryDto GetCategory(int id)
        {
            Category    category    = CategoryDal.GetCategory(id);
            CategoryDto dtoCategory = new CategoryDto(category);

            //converting Dal Object to Dto
            return(dtoCategory);
        }
Example #8
0
        public ActionResult AddCategory(CategoryDal obj)
        {
            CategoryDal objcat = new CategoryDal();

            objcat.AddCategory(obj.Categoryname);

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
Example #9
0
        public int CreateCategory(string name)
        {
            ValidateName(name);

            var categoryDal = new CategoryDal();

            return(categoryDal.CreateCategory(name));
        }
Example #10
0
        public static List <CategoryDto> GetProductsCategories()
        {
            //categories from dataBase
            List <Category>    categories    = CategoryDal.GetProductsCategories();
            List <CategoryDto> dtoCategories = new List <CategoryDto>();

            for (int i = 0; i < categories.Count; i++)
            {
                dtoCategories.Add(new CategoryDto(categories[i]));
            }
            return(dtoCategories);
        }
Example #11
0
        public static List <CategoryDto> GetCatgsToppingsForCatgProduct(int catgProductId)
        {
            //categories from dataBase
            List <Category>    categories    = CategoryDal.GetCatgsToppingsForCatgProduct(catgProductId);
            List <CategoryDto> dtoCategories = new List <CategoryDto>();

            for (int i = 0; i < categories.Count; i++)
            {
                dtoCategories.Add(new CategoryDto(categories[i]));
            }
            return(dtoCategories);
        }
        public ActionResult GetCategoriesByJson()
        {
            //get json of all the categories from DB
            if (Session["CurrentUser"] == null)
            {
                return(RedirectToAction("RedirectByUser", "Home"));
            }
            CategoryDal     ctgyDal    = new CategoryDal();
            List <Category> categories = ctgyDal.Categories.ToList <Category>();

            Thread.Sleep(1000);
            return(Json(categories, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Delete(category cat)
        {
            try
            {
                CategoryDal ct = new CategoryDal();
                ct.DeleteProduct(cat.CategoryID);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(category cat)
        {
            try
            {
                CategoryDal ct = new CategoryDal();
                ct.UpdateProduct(cat);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
        public ActionResult Create(category cat)
        {
            try
            {
                CategoryDal ct = new CategoryDal();
                ct.AddCategory(cat);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Example #16
0
        public Category GetCategory(int id)
        {
            var categoryDal = new CategoryDal();
            var dt          = categoryDal.GetCategory(id);
            var category    = new Category();

            if (dt.Rows.Count <= 0)
            {
                return(null);
            }

            var dr = dt.Rows[0];

            category.Id   = int.Parse(dr["Id"].ToString());
            category.Name = dr["Name"].ToString();

            return(category);
        }
Example #17
0
        public ActionResult ShowCategoryList()
        {
            CategoryDal        objcat      = new CategoryDal();
            DataTable          dt          = objcat.ShowCategory();
            List <CategoryDal> objmenulist = new List <CategoryDal>();


            foreach (DataRow row in dt.Rows)
            {
                CategoryDal objmenu = new CategoryDal();
                objmenu.Categoryname = row["cat_name"].ToString();

                objmenulist.Add(objmenu);
            }


            return(Json(objmenulist, JsonRequestBehavior.AllowGet));
        }
Example #18
0
        public List <Category> SearchCategories(string name)
        {
            var categoryDal    = new CategoryDal();
            var dt             = categoryDal.SearchCategories(name);
            var categoriesList = new List <Category>();

            foreach (DataRow dr in dt.Rows)
            {
                var category = new Category()
                {
                    Id   = int.Parse(dr["Id"].ToString()),
                    Name = dr["Name"].ToString(),
                };

                categoriesList.Add(category);
            }

            return(categoriesList);
        }
        public ActionResult SaveNewCategory()
        {
            //save the new category
            if (!Authorize())
            {
                return(RedirectToAction("RedirectByUser", "Home"));
            }
            CategoryDal ctgyDal     = new CategoryDal();
            Category    newCategory = new Category
            {
                Type = Request.Form["Type"].ToString()
            };

            ModelState.Clear();
            TryValidateModel(newCategory);
            if (ModelState.IsValid)
            {
                try
                {
                    ctgyDal.Categories.Add(newCategory);
                    ctgyDal.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    //TODO: show error message in client side
                    ViewBag.addNewCategoryError = "התרחשה שגיאה בהוספת הקטגוריה";
                }
            }
            else
            {
                ViewBag.addNewCategoryError = "הזן קטגוריה תקינה!";
            }
            List <Category> categories = ctgyDal.Categories.ToList <Category>();

            Thread.Sleep(1000);
            return(Json(categories, JsonRequestBehavior.AllowGet));
        }
Example #20
0
 /// <summary>
 /// 根据分类ID获取分类信息
 /// </summary>
 /// <param name="categoryID"></param>
 /// <returns></returns>
 public Category Get(string categoryID)
 {
     if (string.IsNullOrEmpty(categoryID))
     {
         return null;
     }
     using (CategoryDal dal = new CategoryDal())
     {
         return dal.Get(categoryID);
     }
 }
Example #21
0
 /// <summary>
 /// 根据分类名字获取分类信息
 /// </summary>
 /// <param name="categoryName"></param>
 /// <returns></returns>
 public Category GetName(string categoryName)
 {
     if (string.IsNullOrEmpty(categoryName))
     {
         return null;
     }
     Category entity = this.GetAllCache().Where(x => x.Name == categoryName).SingleOrDefault();
     if (entity == null)
     {
         using (CategoryDal dal = new CategoryDal())
         {
             entity = dal.GetByName(categoryName);
         }
     }
     return entity;
 }
Example #22
0
 public CategoryLogic()
 {
     this.dal = new CategoryDal();
 }
Example #23
0
 private CategoryManager()
 {
     categoryDal = CategoryDal.GetInstance();
 }
Example #24
0
 public BlogController(BlogDal bdal, CategoryDal cadal)
 {
     this.dal   = bdal;
     this.cadal = cadal;
 }
Example #25
0
 public CategoryBll()
 {
     this._CategoryDal = new CategoryDal();
 }
Example #26
0
        public void ChooseActionForCategories()
        {
            CategoryDal categoryDal = new CategoryDal();

            Console.Clear();
            Console.WriteLine("TABLE: CATEGORIES\n\n");
            Console.WriteLine("What action you want to choose?\n" +
                              "1. View all categories\n" +
                              "2. Get category by Id\n" +
                              "3. Get category by name of column\n" +
                              "4. Add category\n" +
                              "5. Edit info about category\n" +
                              "6. Delete category by Id\n" +
                              "7. Delete category by name of column\n" +
                              "8. Back to start menu");
            Console.Write("\nYour selection: ");

            string ch = Console.ReadLine();

            switch (ch)
            {
            case "1":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    categoryDal.PrintListOfCategories(categoryDal.GetAll());
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "2":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\nId: ");

                    int id = Convert.ToInt32(Console.ReadLine());
                    categoryDal.PrintCategory(categoryDal.GetById(id));
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "3":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    Console.WriteLine("Name of column: ");
                    string fieldName = Console.ReadLine();
                    Console.WriteLine("\nValue: ");
                    string text = Console.ReadLine();
                    categoryDal.PrintListOfCategories(categoryDal.GetByFieldName(fieldName, text));
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "4":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    Console.WriteLine("NAME: ");
                    string name = Console.ReadLine();

                    Console.WriteLine("DESCRIPTION: ");
                    string desc = Console.ReadLine();

                    Category category = new Category(name, desc);
                    categoryDal.Insert(category);

                    Console.WriteLine("Category succesfully inserted :)");
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "5":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    Console.WriteLine("Name of column (set): ");
                    string fieldName = Console.ReadLine();

                    Console.WriteLine("Value (set): ");
                    string text = Console.ReadLine();

                    Console.WriteLine("Name of column (condition): ");
                    string fieldCondition = Console.ReadLine();

                    Console.WriteLine("Value (condition): ");
                    string textCondition = Console.ReadLine();

                    categoryDal.UpdateByFieldName(fieldName, text, fieldCondition, textCondition);

                    Console.WriteLine("Category succesfully updated :)");
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "6":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\nId: ");
                    int id = Convert.ToInt32(Console.ReadLine());
                    categoryDal.DeleteById(id);

                    Console.WriteLine("Category succesfully deleted :)");
                    Console.ReadKey();
                    break;
                }

                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "7":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n ");

                    Console.WriteLine("Name of column (condition): ");
                    string fieldCondition = Console.ReadLine();

                    Console.WriteLine("Value (condition): ");
                    string textCondition = Console.ReadLine();

                    categoryDal.DeleteByFieldName(fieldCondition, textCondition);

                    Console.WriteLine("Category succesfully deleted :)");
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "8":
            {
                Menu menu = new Menu();
                menu.ChooseTable();
                break;
            }

            default:
                Console.WriteLine("Invalid selection. Please select 1, 2, 3, 4, 5, 6, 7 or 8.");
                break;
            }
        }
Example #27
0
 /// <summary>
 /// 获取顶级分类信息/即:导航菜单
 /// </summary>
 /// <returns></returns>
 public IList<Category> GetMenu()
 {
     IList<Category> list = this.GetAllCache().Where(e => (e.ParentID == "0" && e.Status > 0)).OrderBy(e => e.Status).ToList();
     if (list == null || list.Count < 1)
     {
         using (CategoryDal dal = new CategoryDal())
         {
             list = dal.GetMenu();
         }
     }
     else
     {
         log.Debug("Get navigation from cache !");
     }
     return list;
 }
Example #28
0
 public IList<Category> GetAllCache()
 {
     IList<Category> cache = Common.BuildCache<IList<Category>>.Default.Get(this.CategoryAllCacheKey);
     if (cache == null)
     {
         using (CategoryDal dal = new CategoryDal())
         {
             cache = dal.GetAll();
             if (cache != null)
             {
                 lock (this.lockCategory)
                 {
                     Common.BuildCache<IList<Category>>.Default.Cache(this.CategoryAllCacheKey, cache);
                 }
             }
         }
     }
     return cache;
 }
Example #29
0
        public IList<Category> GetByParentID(string parentID)
        {
            if (string.IsNullOrEmpty(parentID))
            {
                return null;
            }

            IList<Category> list = GetAllCache().Where(x => x.ParentID == parentID).Where(e => e.Status > -1).ToList();

            if (list == null || list.Count < 1)
            {
                using (CategoryDal dal = new CategoryDal())
                {
                    list = dal.GetByParentID(parentID);
                }
            }
            return list;
        }
Example #30
0
 /// <summary>
 /// 获取相似的分类信息
 /// </summary>
 /// <param name="likeCategoryID"></param>
 /// <returns></returns>
 public IList<Category> GetLike(string likeCategoryID)
 {
     using (CategoryDal dal = new CategoryDal())
     {
         return dal.GetLike(likeCategoryID);
     }
 }
Example #31
0
        public int DeleteCategory(int dni)
        {
            var categoryDal = new CategoryDal();

            return(categoryDal.DeleteCategory(dni));
        }
 public CategoryController(CategoryDal cadal)
 {
     this.dal = cadal;
 }
Example #33
0
        public Category Add(Category item)
        {
            CategoryDal categoryDal = new CategoryDal();

            return(categoryDal.Add(item));
        }
Example #34
0
        /// <summary>
        /// 添加或修改分类信息
        /// <br/>
        /// 清除分类缓存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public ReturnValue AddOrEdit(Category entity)
        {
            ReturnValue retValue = new ReturnValue();

            if (string.IsNullOrEmpty(entity.Name))
            {
                retValue.IsExists = false;
                retValue.Message = "分类名称";
                return retValue;
            }
            if (string.IsNullOrEmpty(entity.Title))
            {
                retValue.IsExists = false;
                retValue.Message = "分类显示名称";
                return retValue;
            }

            using (CategoryDal dal = new CategoryDal())
            {
                Category old = dal.Get(entity.CategoryID);
                if (old == null)//添加
                {
                    old = dal.GetByName(entity.Name);
                    if (old != null)
                    {
                        retValue.IsExists = false;
                        retValue.Message = "分类已存在";
                        return retValue;
                    }
                    if (dal.Add(entity))
                    {
                        retValue.IsExists = true;
                        retValue.Message = "分类添加成功";
                    }
                    else
                    {
                        retValue.IsExists = false;
                        retValue.Message = "分类添加失败";
                    }
                }
                else
                {
                    if (entity.Name != old.Name)
                    {
                        old = dal.GetByName(entity.Name);
                        if (old != null)
                        {
                            retValue.IsExists = false;
                            retValue.Message = "分类已存在";
                            return retValue;
                        }
                    }
                    if (dal.Modify(entity))
                    {
                        retValue.IsExists = true;
                        retValue.Message = "分类修改成功";
                    }
                    else
                    {
                        retValue.IsExists = false;
                        retValue.Message = "分类修改失败";
                    }
                }
            }
            if (retValue.IsExists)
            {
                ClearCache();
            }
            return retValue;
        }
        /// <summary>
        /// 是否重新下载项目信息
        /// </summary>
        /// <param name="updatejson">是否重新下载配置分类</param>
        public void LoadConfig(bool isload)
        {
            lock (_lockconfig)
            {
                string jasonpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "json", "json.txt");
                try
                {
                    bool     isupdatelocal = false;
                    DateTime updatetime    = DateTime.Now;

                    if (isload)
                    {
                        SystemConfigDal scdal = new SystemConfigDal();
                        SystemConfig    sc    = scdal.GetRedisServer(AppDomainContext.Context.ConfigParams.ConfigManagerConnectString);
                        if (sc != null)
                        {
                            AppDomainContext.Context.ConfigParams.RedisServer = sc.ConfigValue;
                        }

                        //更新项目信息
                        ProjectDal prodal = new ProjectDal();
                        AppDomainContext.Context.ProjectModel = prodal.GetByName(AppDomainContext.Context.ConfigParams.ConfigManagerConnectString, AppDomainContext.Context.ConfigParams.ProjectName);

                        //更新分类信息
                        CategoryDal catedal = new CategoryDal();
                        AppDomainContext.Context.CategoryModels = catedal.GetListByIds(AppDomainContext.Context.ConfigParams.ConfigManagerConnectString, AppDomainContext.Context.ProjectModel.CategoryIds);
                        long[] cids = AppDomainContext.Context.CategoryModels.Select(p => p.Id).ToArray();
                        //更新配置信息
                        ConfigDal          configdal    = new ConfigDal();
                        List <Config>      configs      = configdal.GetListByCategoryIds(AppDomainContext.Context.ConfigParams.ConfigManagerConnectString, cids, updatetime);
                        List <ConfigModel> configmodels = ToConfigModel(configs);

                        ConfigInfoOfKeyDic dic = new ConfigInfoOfKeyDic();
                        foreach (var item in configmodels)
                        {
                            dic.SetConfig(item);
                        }
                        AppDomainContext.Context.ConfigInfoOfKeyDic = dic;

                        if (configs.Count > 0)
                        {
                            configdal.SetUpdatetime(AppDomainContext.Context.ConfigParams.ConfigManagerConnectString, cids, updatetime);
                            isupdatelocal = true;
                        }
                    }
                    else
                    {
                        ConfigDal configdal = new ConfigDal();
                        long[]    cids      = AppDomainContext.Context.CategoryModels.Select(p => p.Id).ToArray();

                        List <Config>      configs      = configdal.GetListByCategoryIds(AppDomainContext.Context.ConfigParams.ConfigManagerConnectString, cids, updatetime);
                        List <ConfigModel> configmodels = ToConfigModel(configs);
                        foreach (var item in configmodels)
                        {
                            AppDomainContext.Context.ConfigInfoOfKeyDic.SetConfig(item);
                        }
                        if (configs.Count > 0)  //本次有配置更新
                        {
                            configdal.SetUpdatetime(AppDomainContext.Context.ConfigParams.ConfigManagerConnectString, cids, updatetime);
                            isupdatelocal = true;
                        }
                    }

                    if (isupdatelocal)
                    {
                        string json1 = JsonConvert.SerializeObject(AppDomainContext.Context);
                        IOHelper.Write(jasonpath, json1);  //写入磁盘
                        LogHelper.WriteInfo("写入磁盘成功");
                    }
                }
                catch (Exception)
                {
                    string json2 = IOHelper.Read(jasonpath);
                    JsonConvert.DeserializeObject <ConfigContext>(json2);   //从磁盘获得上次正确的配置
                    LogHelper.WriteInfo("从磁盘读取配置");
                }
            }
        }
Example #36
0
 public CategoryController()
 {
     category_dal = new CategoryDal();
 }
Example #37
0
 public CategoryService(CategoryDal categoryDal, IMapper mapper)
 {
     _categoryDal = categoryDal;
     _mapper      = mapper;
 }
Example #38
0
        public ReturnValue Delete(string ids)
        {
            ReturnValue retValue = new ReturnValue();

            string[] categoryIdArr = ids.Split(new Char[] { ',' });
            using (CategoryDal dal = new CategoryDal())
            {
                foreach (string item in categoryIdArr)
                {
                    if (dal.Delete(item))
                    {
                        retValue.PutValue("ok", retValue.GetInt("ok"));
                    }
                    else
                    {
                        retValue.PutValue("error", retValue.GetInt("error"));
                    }
                }
            }
            if (retValue.GetInt("error") != 0)
            {
                retValue.IsExists = false;
                retValue.Message = string.Format("删除分类失败,成功{0},失败{1}!", retValue.GetInt("ok"), retValue.GetInt("error"));
            }
            else
            {
                retValue.IsExists = true;
                retValue.Message = "删除分类成功!";
                ClearCache();//清除缓存
            }
            return retValue;
        }