public List <Book> GetList() { WebApiDbcontext context = new WebApiDbcontext(); List <Book> list = context.Books.ToList(); return(list); }
//public void Add(OrderAddArgs args) //{ // OrderRepository repository = new OrderRepository(); // repository.Insert(new Order() // { // OrderDate = DateTime.Now, // OrderId = args.OrderID, // Price = args.Price, // }); //} public void Add() { using (var context = new WebApiDbcontext()) { var isCreate = context.Database.CreateIfNotExists(); } }
public string Delete(int id) { WebApiDbcontext context = new WebApiDbcontext(); Book oldBook = context.Books.FirstOrDefault(t => t.book_id == id); if (oldBook != null) { context.Books.Remove(oldBook); } context.SaveChanges(); return("删除成功"); }
public string Add(Book book) { WebApiDbcontext context = new WebApiDbcontext(); context.Books.Add(new Book() { book_auth = book.book_auth, book_name = book.book_name, book_price = book.book_price, CreaTime = book.CreaTime, }); context.SaveChanges(); return("添加成功"); }
public string Modify(Book book) { WebApiDbcontext context = new WebApiDbcontext(); Book oldBook = context.Books.FirstOrDefault(t => t.book_id == book.book_id); if (oldBook != null) { oldBook.book_auth = book.book_auth; oldBook.book_name = book.book_name; oldBook.book_price = book.book_price; } context.Entry <Book>(oldBook).State = EntityState.Modified; context.SaveChanges(); return("修改成功"); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); WebApiDbcontext accService = new WebApiDbcontext(); //string md5Pwd = LogHelper.MD5CryptoPasswd(context.Password); try { //var user = accService.Users.FirstOrDefault(u => u.UserName == context.UserName && u.PassWord == context.Password); var user = await accService.Users.FirstOrDefaultAsync(u => u.UserName == context.UserName && u.PassWord == context.Password); if (user == null) { context.SetError("invalid_grant", "The username or password is incorrect"); return; } var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("sub", context.UserName)); identity.AddClaim(new Claim("role", "user")); context.Validated(identity); } catch (Exception e) { throw e; } //List<User> ul = accService.Users.Where(u=>u.UserName== context.UserName&&u.PassWord==context.Password).ToList(); //IList<object[]> ul = accService.Login(context.UserName, md5Pwd); //if (user != null) //{ // context.SetError("invalid_grant", "The username or password is incorrect"); // return; //} //var identity = new ClaimsIdentity(context.Options.AuthenticationType); //identity.AddClaim(new Claim("sub", context.UserName)); //identity.AddClaim(new Claim("role", "user")); //context.Validated(identity); }