コード例 #1
0
        public int AddCate(string ten, string slug, int cateId)
        {
            try
            {
                if (ten != "" && slug != "")
                {
                    theloaitin newCate = new theloaitin();
                    newCate.id          = cateId;
                    newCate.ten         = ten;
                    newCate.slug        = slug;
                    newCate.ngaytao     = DateTime.Now;
                    newCate.ngaycapnhat = DateTime.Now;

                    db.theloaitins.Add(newCate);
                    db.SaveChanges();

                    return(newCate.id);
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
コード例 #2
0
        public theloaitin GetSingleCate(int cateId)
        {
            theloaitin cate = new theloaitin();

            try
            {
                cate = db.theloaitins.Where(x => x.id == cateId).SingleOrDefault();
                return(cate);
            }
            catch
            {
                return(cate);
            }
        }
コード例 #3
0
        public bool DeleteCate(int cateId)
        {
            theloaitin cate = new theloaitin();

            try
            {
                cate = db.theloaitins.Where(x => x.id == cateId).SingleOrDefault();
                db.theloaitins.Remove(cate);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #4
0
        public int EditCate(string ten, string slug, int id)
        {
            try
            {
                theloaitin editCate = db.theloaitins.Where(x => x.id == id).SingleOrDefault();
                editCate.ten         = ten;
                editCate.slug        = slug;
                editCate.ngaycapnhat = DateTime.Now;

                db.SaveChanges();

                return(editCate.id);
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }