public String SubmitUserInfo(string userInfo) { UserInfo us = (UserInfo)JsonConvert.DeserializeObject(userInfo, typeof(UserInfo)); if (us.UserId == 0) { return(AddUserInfo(us)); } UserInfo order = new UserInfo(); UserInfo existingInfo = null; using (DSLEntities entity = new DSLEntities()) { existingInfo = entity.UserInfo.Where(a => a.UserId == us.UserId).ToList().FirstOrDefault(); } if (existingInfo != null) { using (DSLEntities entity = new DSLEntities()) { existingInfo = us; entity.Entry(existingInfo).State = System.Data.Entity.EntityState.Modified; entity.SaveChanges(); } } return("0"); }
public String SubmitProductInfo(string userInfo) { ProductInfo us = (ProductInfo)JsonConvert.DeserializeObject(userInfo, typeof(ProductInfo)); ProductInfo proInfo = new ProductInfo(); ProductInfo existingData = new ProductInfo(); using (DSLEntities entity = new DSLEntities()) { existingData = entity.ProductInfo.Where(a => a.ProductId == us.ProductId).ToList().FirstOrDefault(); } if (existingData != null) { using (DSLEntities entity = new DSLEntities()) { existingData = us; entity.Entry(existingData).State = System.Data.Entity.EntityState.Modified; entity.SaveChanges(); } } return("0"); }
private String AddUserInfo(UserInfo userInfo) { using (DSLEntities entity = new DSLEntities()) { entity.UserInfo.Add(userInfo); entity.SaveChanges(); } return("0"); }
public JsonResult GetAllUserData() { UserInfo order = new UserInfo(); List <UserInfo> result = null; using (DSLEntities entity = new DSLEntities()) { result = entity.UserInfo.ToList(); //写回数据库 entity.SaveChanges(); } Console.WriteLine("OK"); return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetProductById(int id) { UserInfo order = new UserInfo(); List <ProductInfo> result = null; using (DSLEntities entity = new DSLEntities()) { result = entity.ProductInfo.OrderBy(a => a.ProductName).Where(a => a.ProductId == id).ToList(); //写回数据库 entity.SaveChanges(); } Console.WriteLine("OK"); return(Json(result, JsonRequestBehavior.AllowGet)); }
public String SubmitRechargeInfo(String paymentId, String amount, String paymentTime) { OAuthTokenCredential oa = new OAuthTokenCredential("AQmW6s0chChHeblhmaIYQda6Bn1gmfSSUnvUCHNCLZM_7BiLOb5BMrINuIxUswdG8Prb8K3ktHQpZuho", "ENQKqkutUnKuTGBWiNDvJ_sA131lwCU4c1eaJwFcn58M88LtjHJd9TLgvjT4nuXkruuSkD0OF0u_XP_W"); PayPal.Api.APIContext apiContext = new PayPal.Api.APIContext(oa.GetAccessToken()); try { Payment payment = PayPal.Api.Payment.Get(apiContext, paymentId); if (payment == null || String.IsNullOrEmpty(payment.id)) { return("11"); } } catch (Exception ex) { return("11"); } LoginViewModel user = Utils.GetUserInfo(); PaymentInfo pInfo = null; using (DSLEntities entity = new DSLEntities()) { pInfo = entity.PaymentInfo.Where(a => a.UserId.ToString() == user.UserId && a.PaymentId == paymentId).ToList().FirstOrDefault(); } if (pInfo != null) { return("1"); } UserInfo existingData = null; using (DSLEntities entity = new DSLEntities()) { existingData = entity.UserInfo.Where(a => a.UserId.ToString() == user.UserId).ToList().FirstOrDefault(); } if (existingData != null) { using (DSLEntities entity = new DSLEntities()) { existingData.Balance += decimal.Parse(amount); entity.Entry(existingData).State = System.Data.Entity.EntityState.Modified; entity.SaveChanges(); } } PaymentInfo addPayInfo = new PaymentInfo(); addPayInfo.Amount = Decimal.Parse(amount); addPayInfo.PaymentId = paymentId; addPayInfo.PaymentState = "Approval"; addPayInfo.PaymentType = "PayPal"; addPayInfo.UserId = int.Parse(user.UserId); addPayInfo.PaymentTime = DateTime.Parse(paymentTime); using (DSLEntities entity = new DSLEntities()) { entity.PaymentInfo.Add(addPayInfo); entity.SaveChanges(); } return("0"); }