Exemplo n.º 1
0
 public int InsertSubCate(JObject cate)
 {
     try
     {
         var catetitle = cate["catename"].ToString();
         while (catetitle.Contains("  "))
         {
             catetitle.Replace("  ", " ");
         }
         catetitle = TienIchController.RemoveUnicode(catetitle);
         catetitle = catetitle.Replace(" ", "-");
         LoaiTin data = new LoaiTin();
         data.Ten          = cate["catename"].ToString();
         data.Ten_KhongDau = catetitle;
         data.AnHien       = (byte)cate["cateactive"];
         data.ThuTu        = (byte)cate["catenumber"];
         data.idTL         = (int)cate["cate"];
         db.LoaiTins.Add(data);
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemplo n.º 2
0
 public int UpdatePost(JObject post)
 {
     try
     {
         var posttitle = post["title"].ToString();
         while (posttitle.Contains("  "))
         {
             posttitle.Replace("  ", " ");
         }
         posttitle = TienIchController.RemoveUnicode(posttitle);
         posttitle = posttitle.Replace(" ", "-");
         var data = db.Tins.Find(post["id"]);
         data.TieuDe          = post["title"].ToString();
         data.TieuDe_KhongDau = posttitle;
         data.urlHinh         = post["image"].ToString();
         data.idTL            = (int)post["cate"];
         data.idLT            = (int)post["subcate"];
         data.TinNoiBat       = (byte)post["hot"];
         data.TomTat          = post["summary"].ToString();
         data.AnHien          = (byte)post["active"];
         data.Content         = post["content"].ToString();
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemplo n.º 3
0
 public int InsertUser(JObject user)
 {
     try
     {
         User data = new User();
         data.HoTen      = user["name"].ToString();
         data.Username   = user["username"].ToString();
         data.Password   = TienIchController.Base64Encode(user["password"].ToString());
         data.DiaChi     = user["address"].ToString();
         data.Dienthoai  = user["phone"].ToString();
         data.Email      = user["email"].ToString();
         data.NgayDangKy = DateTime.ParseExact(DateTime.Now.ToShortDateString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
         data.NgaySinh   = DateTime.ParseExact(user["birthday"].ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
         data.idGroup    = (int)user["group"];
         data.GioiTinh   = (byte)user["sex"];
         data.Active     = (int)user["active"];
         db.Users.Add(data);
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemplo n.º 4
0
        public IHttpActionResult getUserByID(int id)
        {
            var user = db.Users.Find(id);

            if (user != null)
            {
                user.Password = TienIchController.Base64Decode(user.Password);
                return(Ok(user));
            }
            return(NotFound());
        }
Exemplo n.º 5
0
 public int UpdateCate(JObject cate)
 {
     try
     {
         var catetitle = cate["catename"].ToString();
         while (catetitle.Contains("  "))
         {
             catetitle.Replace("  ", " ");
         }
         catetitle = TienIchController.RemoveUnicode(catetitle);
         catetitle = catetitle.Replace(" ", "-");
         var data = db.TheLoais.Find(cate["cateid"]);
         data.TenTL          = cate["catename"].ToString();
         data.TenTL_KhongDau = catetitle;
         data.AnHien         = (byte)cate["cateactive"];
         data.ThuTu          = (int)cate["catenumber"];
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemplo n.º 6
0
        public IHttpActionResult Login(JObject objects)
        {
            string username = objects["username"].ToString();
            string password = objects["password"].ToString();
            var    user     = db.Users.Where(x => x.Username == username && x.Password == TienIchController.Base64Encode(password)).SingleOrDefault();

            if (user != null)
            {
                UserLogin data = new UserLogin(user.Username, user.idUser, 1, user.idGroup);
                return(Ok(data));
            }
            return(NotFound());
        }