public ActionResult Add()
        {
            //check
            if (!this._nhanvien_permission.Contains("nhomsanpham_add"))
            {
                return this._fail_permission("nhomsanpham_add");
            }
            //get data
            int p_id = TextLibrary.ToInt(Request["cat_parent_id"]);
            //nên lấy instance của chính Controller đó để dùng sẽ không bị lỗi track changes
            NhomSanPhamController controller = new NhomSanPhamController();

            NhomSanPham obj = new NhomSanPham();
            obj.ten =  TextLibrary.ToString(Request["cat_name"]);
            obj.mota = TextLibrary.ToString(Request["cat_description"]);
            obj.active = TextLibrary.ToBoolean(Request["cat_active"]);
            if (obj.ten.Equals(""))
            {
                //lỗi
                Debug.WriteLine("Lỗi cat_name= rỗng");
                return RedirectToAction("Index", "AdminNhomSanPham");
            }
            NhomSanPham p_obj = controller._db.ds_nhomsanpham.Where(x => x.id == p_id).FirstOrDefault();
            if (p_obj != null)
            {
                obj.nhomcha = p_obj;
            }
            //call add
            controller.add(obj);
            Debug.WriteLine("Thêm Thành Công Nhóm Sản Phẩm");
            return RedirectToAction("Index","AdminNhomSanPham");
        }
 public int add(NhomSanPham obj)
 {
     this._db.ds_nhomsanpham.Add(obj);
     this._db.SaveChanges();
     //return ma moi nhat
     return this._db.ds_nhomsanpham.Max(x => x.id);
 }
Beispiel #3
0
 public void Load_From(NhomSanPham obj)
 {
     this.id = obj.id;
     //đề phòng null,
     this.ten = TextLibrary.ToString(obj.ten);
     this.mota = TextLibrary.ToString(obj.mota);
     this.active = obj.active;
 }
Beispiel #4
0
 public NhomSanPham Export_To()
 {
     NhomSanPham tmp = new NhomSanPham();
     tmp.id = this.id;
     //đề phòng null,
     tmp.ten = this.ten;
     tmp.mota = this.mota;
     tmp.active = this.active;
     return tmp;
 }
 public List<NhomSanPham2> get_tree(NhomSanPham root=null, int level=0)
 {
     this._tmp_for_get_tree = new List<NhomSanPham2>();
     //để dành level cho root
     if (root != null)
     {
         level++;
     }
     List<NhomSanPham2> tmp = this._get_tree(root, level);
     this._tmp_for_get_tree = new List<NhomSanPham2>();
     //nếu root!=null thì add root vào trước tiên
     if (root != null)
     {
         NhomSanPham2 root_ = new NhomSanPham2();
         root_.Load_From(root);
         root_.level = level-1;
         tmp.Insert(0,root_);
     }
     return tmp;
 }
 public List<SanPham> timkiem_dequy(NhomSanPham root = null, String active = "", int start_point = 0, int count = -1)
 {
     List<SanPham> re = new List<SanPham>();
     NhomSanPhamController ctr=new NhomSanPhamController();
     List<NhomSanPham> list = ctr.get_tree2(root);
     re.AddRange(this.timkiem("","","","",0,0,null,list,active,"id",true,start_point,count));
     return re;
 }
 public List<NhomSanPham> get_tree2(NhomSanPham root = null)
 {
     this._tmp_for_get_tree = new List<NhomSanPham2>();
     List<NhomSanPham2> tmp = this._get_tree(root, 1);
     this._tmp_for_get_tree = new List<NhomSanPham2>();
     List<NhomSanPham> re = new List<NhomSanPham>();
     //nếu root!=null thì add root vào trước tiên
     if (root != null)
     {
         re.Add(root);
     }
     //chuyển tmo vào trong re
     foreach (NhomSanPham2 item in tmp)
     {
         re.Add(this.get_by_id(item.id));
     }
     return re;
 }
 private List<NhomSanPham2> _get_tree(NhomSanPham root, int level)
 {
     List<NhomSanPham> list;
     //lấy các child
     if (root == null)
     {
         list = this._db.ds_nhomsanpham.Where(x => x.nhomcha == null).ToList();
     }
     else
     {
          list = root.ds_nhomcon;
     }
     if (list == null) return new List<NhomSanPham2>();
     foreach (NhomSanPham item in list)
     {
         //add child đang xét vô cùng với level
         NhomSanPham2 tmp = new NhomSanPham2();
         tmp.Load_From(item);//load id, ten, ...
         tmp.level = level;
         this._tmp_for_get_tree.Add(tmp);
         //call recursive for this child
         this._get_tree(item, level+1);
     }
     //finish
     return this._tmp_for_get_tree;
 }
 public Boolean set_parent(NhomSanPham obj, NhomSanPham parent)
 {
     if (parent!=null && this.is_exist(parent.id))
     {
         if (obj.id == parent.id)
         {
             return false;
         }
         obj.nhomcha = parent;
     }
     else
     {
         if (obj.nhomcha == null)
         {
             //nothing
         }
         else
         {
             obj.nhomcha.ds_nhomcon.Remove(obj);
         }
     }
     return true;
 }