public int InsertBook(Dictionary <string, object> dic) { using (CommercedataContext context = new CommercedataContext()) { SupplierBookInfo info = JsonConvert.DeserializeObject <SupplierBookInfo>(dic["obj"].ToString()); string token = dic["token"].ToString(); if (token == "undefined") { return(0); } JWTHelper jWT = new JWTHelper(); UserRoderInfo user = JsonConvert.DeserializeObject <UserRoderInfo>(jWT.GetPayload(token)); var ue = context.UserRoderInfo.Where(n => n.ContactName.Equals(user.ContactName) && n.SupplierPwd.Equals(user.SupplierPwd)).FirstOrDefault(); if (ue == null) { return(0); } string SupplierId = ue.SuppLierId; var list = (from s in context.SupplierBookInfo where s.Isbn == info.Isbn select s).FirstOrDefault(); if (list == null) { info.Score = 0; info.SaledQuantity = 0; info.BookStues = "未出售"; info.SupplierId = SupplierId; context.SupplierBookInfo.Add(info); return(context.SaveChanges()); } else { return(0); } } }
public int UpdBook(Dictionary <string, object> dic) { using (CommercedataContext context = new CommercedataContext()) { SupplierBookInfo info = JsonConvert.DeserializeObject <SupplierBookInfo>(dic["obj"].ToString()); string token = dic["token"].ToString(); if (token == "undefined") { return(0); } JWTHelper jWT = new JWTHelper(); UserRoderInfo user = JsonConvert.DeserializeObject <UserRoderInfo>(jWT.GetPayload(token)); var ue = context.UserRoderInfo.Where(n => n.ContactName.Equals(user.ContactName) && n.SupplierPwd.Equals(user.SupplierPwd)).FirstOrDefault(); if (ue == null) { return(0); } string SupplierId = ue.SuppLierId; var list = (from s in context.SupplierBookInfo where s.Isbn == info.Isbn select s).FirstOrDefault(); list.Price = info.Price; list.Discount = info.Discount; list.TotalQuantity = info.TotalQuantity; list.BookType = info.BookType; context.SupplierBookInfo.Update(list); return(context.SaveChanges()); } }