public static void UpdateUser(WeChatUser user) { using (WeChatDbContext entity = new WeChatDbContext()) { var weChatUser = (from item in entity.WeChatUsers where item.OpenId == user.OpenId orderby item.WeChatUserId descending select item).FirstOrDefault(); if (weChatUser != null) { entity.Entry(weChatUser).State = System.Data.Entity.EntityState.Modified; weChatUser.Subscribe = user.Subscribe; weChatUser.LastUpdateStateTime = DateTime.Now; if (user.Subscribe == 1) { weChatUser.City = user.City; weChatUser.Country = user.Country; weChatUser.HeadImgUrl = user.HeadImgUrl; weChatUser.Language = user.Language; weChatUser.NickName = user.NickName; weChatUser.Province = user.Province; weChatUser.LastSubscribeChannel = user.LastSubscribeChannel; weChatUser.Sex = user.Sex; } entity.SaveChanges(); } } }
public ActionResult Edit([Bind(Include = "Id,Published,Title,Description,PicUrl,Url,Tags")] Article article) { if (ModelState.IsValid) { db.Entry(article).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(article)); }
public static string GetAccessToken() { string newAccessToken = String.Empty; int weChatExpiresIn = 0; using (WeChatDbContext entity = new WeChatDbContext()) { var accesstoken = (from item in entity.AccessTokens orderby item.AccessTokenId descending select item).FirstOrDefault(); if (accesstoken == null) { WebClient wc = new WebClient(); byte[] data = null; data = wc.DownloadData(String.Format(WeChatWebAPI.GetAccessToken, appId, appSecret)); string strWebData = Encoding.Default.GetString(data); var accessTokenModel = (JObject)JsonConvert.DeserializeObject(strWebData); newAccessToken = accessTokenModel["access_token"].ToString(); weChatExpiresIn = Int32.Parse(accessTokenModel["expires_in"].ToString()); AccessToken at = new AccessToken(); at.AccessTokenStr = newAccessToken; at.ExpiresIn = weChatExpiresIn; at.LastUpdateTime = DateTime.Now; entity.AccessTokens.Add(at); entity.SaveChanges(); } else { newAccessToken = accesstoken.AccessTokenStr; TimeSpan expires_in = DateTime.Now - accesstoken.LastUpdateTime; if ((expires_in.TotalMinutes * 60) > (accesstoken.ExpiresIn - 100)) { WebClient wc = new WebClient(); byte[] data = null; data = wc.DownloadData(String.Format(WeChatWebAPI.GetAccessToken, appId, appSecret)); string strWebData = Encoding.Default.GetString(data); var accessTokenModel = (JObject)JsonConvert.DeserializeObject(strWebData); newAccessToken = accessTokenModel["access_token"].ToString(); weChatExpiresIn = Int32.Parse(accessTokenModel["expires_in"].ToString()); entity.Entry(accesstoken).State = System.Data.Entity.EntityState.Modified; accesstoken.AccessTokenStr = newAccessToken; accesstoken.ExpiresIn = weChatExpiresIn; accesstoken.LastUpdateTime = DateTime.Now; entity.SaveChanges(); } } } return newAccessToken; }
public static void CancelOrder(int orderid, int userid, string username) { using (WeChatDbContext entity = new WeChatDbContext()) { var order = (from item in entity.SysWorkOrder where item.SysWorkOrderId == orderid select item).SingleOrDefault(); if (order != null) { entity.Entry(order).State = System.Data.Entity.EntityState.Modified; order.CurrentStatus = "qx"; SysWorkOrderLog wol = new SysWorkOrderLog(); wol.CreateTime = DateTime.Now; wol.Description = "操作人:" + username + ",取消了保修请求"; wol.OperateUserId = userid; wol.SysWorkOrderId = orderid; entity.SysWorkOrderLog.Add(wol); entity.SaveChanges(); } } }
public static void EditCodeChannel(ActivityChannels c) { using (WeChatDbContext entity = new WeChatDbContext()) { var channel = (from item in entity.ActivityChannels where item.ActivityChannelsId == c.ActivityChannelsId select item).SingleOrDefault(); if (channel != null) { entity.Entry(channel).State = System.Data.Entity.EntityState.Modified; channel.ChannelName = c.ChannelName; channel.ChannelUrl = c.ChannelUrl; channel.KeyWords = c.KeyWords; entity.SaveChanges(); } } }
public static void UpdateCouponCustomerInfo(ActivityModels am) { using (WeChatDbContext entity = new WeChatDbContext()) { var coupon = (from item in entity.ActivityModels where item.CouponCode == am.CouponCode select item).SingleOrDefault(); if (coupon != null) { entity.Entry(coupon).State = System.Data.Entity.EntityState.Modified; coupon.ActivityName = am.ActivityName; coupon.CellPhone = am.CellPhone; coupon.CustomerName = am.CustomerName; coupon.Description = am.Description; coupon.IsCancel = am.IsCancel; coupon.IsRevisited = am.IsRevisited; coupon.IsUsed = am.IsUsed; entity.SaveChanges(); } } }
public static void EditKeyword(KeyWord keyword) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldKeyword = (from item in entity.KeyWords where item.KeyWordId == keyword.KeyWordId select item).SingleOrDefault(); if (oldKeyword != null) { entity.Entry(oldKeyword).State = System.Data.Entity.EntityState.Modified; oldKeyword.Title = keyword.Title; oldKeyword.ResultUrl = keyword.ResultUrl; oldKeyword.MsgKeyValue = keyword.MsgKeyValue; oldKeyword.LastUpdateTime = DateTime.Now; oldKeyword.Content = keyword.Content; entity.SaveChanges(); } } }
public static string BindStaffOpenId(string cellphone, string password, string openid) { using (WeChatDbContext entity = new WeChatDbContext()) { var staff = (from item in entity.Staffs where (item.CellPhone == cellphone) && (item.Password == password) select item).SingleOrDefault(); if (staff != null) { entity.Entry(staff).State = System.Data.Entity.EntityState.Modified; staff.OpenId = openid; entity.SaveChanges(); return "success"; } return "error"; } }
public static void EditStaff(Staff staff) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldStaff = (from item in entity.Staffs where (item.StaffId == staff.StaffId) && (item.CellPhone == staff.CellPhone) select item).FirstOrDefault(); if (oldStaff != null) { entity.Entry(oldStaff).State = System.Data.Entity.EntityState.Modified; oldStaff.LastUpdateTime = DateTime.Now; oldStaff.CellPhone = staff.CellPhone; oldStaff.IsEnabled = staff.IsEnabled; oldStaff.Name = staff.Name; if (staff.Password != "") { oldStaff.Password = staff.Password; } oldStaff.StaffType = staff.StaffType; entity.SaveChanges(); } } }
public static void EditQRCode(QRCode qrcode) { using (WeChatDbContext entity = new WeChatDbContext()) { var q = (from item in entity.QRCodes where item.QRCodeId == qrcode.QRCodeId select item).SingleOrDefault(); if (q != null) { entity.Entry(q).State = System.Data.Entity.EntityState.Modified; q.Title = qrcode.Title; q.LastUpdateTime = DateTime.Now; entity.SaveChanges(); } } }
public static void EditMessage(Message m) { using (WeChatDbContext entity = new WeChatDbContext()) { var menu = (from item in entity.Messages where item.MessageId == m.MessageId select item).SingleOrDefault(); if (menu != null) { entity.Entry(menu).State = System.Data.Entity.EntityState.Modified; menu.MessageUrl = m.MessageUrl; menu.Title = m.Title; menu.Key = m.Key; menu.ImageUrl = m.ImageUrl; menu.Content = m.Content; entity.SaveChanges(); } } }
public static void EditMenu(Menu m) { using (WeChatDbContext entity = new WeChatDbContext()) { var menu = (from item in entity.Menus where m.MenuId == item.MenuId select item).SingleOrDefault(); if (menu != null) { entity.Entry(menu).State = System.Data.Entity.EntityState.Modified; menu.MenuType = m.MenuType; menu.MenuValue = m.MenuValue; menu.ParentMenuId = m.ParentMenuId; menu.Title = m.Title; entity.SaveChanges(); } } }
public static void UpdateSysWorkOrder(SysWorkOrder order, SysWorkOrderLog orderLog) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldorder = (from item in entity.SysWorkOrder where item.SysWorkOrderId == order.SysWorkOrderId select item).SingleOrDefault(); if (oldorder != null) { entity.Entry(oldorder).State = System.Data.Entity.EntityState.Modified; oldorder.OrderTitle = order.OrderTitle; oldorder.LastUpdateTime = DateTime.Now; oldorder.Device = order.Device; oldorder.DeviceCode = order.DeviceCode; oldorder.Description = order.Description; oldorder.Department = order.Department; oldorder.CurrentStatus = order.CurrentStatus; oldorder.LastUpdateUserId = order.LastUpdateUserId; entity.SysWorkOrderLog.Add(orderLog); entity.SaveChanges(); } } }