Ejemplo n.º 1
0
        public static bool DeteteCategory(string name, List <int> arrid)
        {
            using (var context = new CategoryDbFullDataContext())
            {
                checkUserPermission(context, name);

                foreach (int id in arrid)
                {
                    var category = context.tbCategories.SingleOrDefault(x => x.Id == id);
                    if (category != null)
                    {
                        if (category.Id == 1)
                        {
                            throw new Exception("Không thể xóa chuyên mục này");
                        }
                        foreach (var item in category.tbSoftwares)
                        {
                            item.CategoryId = 1;
                        }
                        context.tbCategories.DeleteOnSubmit(category);
                    }
                    else
                    {
                        throw new Exception("Không tìm thấy chuyên mục này");
                    }
                }
                context.SubmitChanges();
                return(true);
            }
        }
Ejemplo n.º 2
0
        private static void checkUserPermission(CategoryDbFullDataContext context, string name)
        {
            var user = context.tbUsers.FirstOrDefault(x => x.UserName.Equals(name));

            if (user == null)
            {
                throw new Exception("Tài khoản không tồn tại");
            }
            if (user.tbTypeUser.Id != 1)
            {
                throw new Exception("Bạn không có quyền xóa chuyên mục");
            }
        }
Ejemplo n.º 3
0
        public static bool AddCategory(String currentUser, int id, string name, string description, int order, int parent)
        {
            int?_parent = null;

            if (parent != 0)
            {
                _parent = parent;
            }
            using (var context = new CategoryDbFullDataContext())
            {
                checkUserPermission(context, currentUser);
                if (id == 0)
                {
                    context.tbCategories.InsertOnSubmit(new Db.Category.CategoryDbFull.tbCategory()
                    {
                        Name        = name,
                        Description = description,
                        Order       = order,
                        ParentId    = _parent
                    });
                    context.SubmitChanges();
                }
                else
                {
                    var category = context.tbCategories.SingleOrDefault(x => x.Id == id);
                    if (category == null)
                    {
                        throw new Exception("Không tìm thấy thông tin về chuyên mục này");
                    }
                    category.Name        = name;
                    category.ParentId    = _parent;
                    category.Order       = order;
                    category.Description = description;
                    context.SubmitChanges();
                }
                return(true);
            }
        }