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); } }
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()); }