public object InsertExtend([FromBody] CustomerExtend obj) { var msg = new JMessage(); try { var query = from a in _context.CustomerExtends where a.ext_code == obj.ext_code && a.isdeleted == false select a; if (query.Count() == 0) { obj.created_time = DateTime.Now; obj.isdeleted = false; _context.CustomerExtends.Add(obj); _context.SaveChanges(); msg.Error = false; msg.Title = "Thêm trường mở rộng thành công!"; } else { msg.Error = true; msg.Title = "Mã trường mở rộng đã tồn tại!"; } return(Json(msg)); } catch { msg.Error = true; msg.Title = "Có lỗi xảy ra!"; return(Json(msg)); } }
public UserInfoVM GetUserInfoByMobile(string mobile) { using (var ctx = new ShtxSms2008Entities()) { CustomerExtend ce = ctx.CustomerExtend.FirstOrDefault(o => o.SendInterFace == 102 && o.Tel.Contains(mobile)); UserInfoVM userInfo = new UserInfoVM() { EndDate = ce.EndDate.Value.ToString("yyyy-MM-dd") }; var appCustomer = ctx.AppCustomerTokens.FirstOrDefault(o => o.tel == mobile); if (appCustomer != null) { userInfo.IsSound = appCustomer.isSound ?? false; } return(userInfo); } }
public bool renew(string mobile) { bool flag = false; using (var ctx = new ShtxSms2008Entities()) { CustomerExtend ce = ctx.CustomerExtend.FirstOrDefault(o => o.SendInterFace == 102 && o.Tel.Contains(mobile)); if (ce != null) { DateTime endTime = ce.EndDate.Value; ce.FirstDate = endTime; ce.EndDate = endTime.AddYears(1); ce.Valid = true; ce.CusKind = 1; ctx.SaveChanges(); flag = true; } } return(flag); }
public object UpdateExtend([FromBody] CustomerExtend obj) { var msg = new JMessage(); try { obj.updated_time = DateTime.Now.Date; _context.CustomerExtends.Update(obj); _context.SaveChanges(); msg.Error = false; msg.Title = "Cập nhật thành công"; return(Json(msg)); } catch (Exception ex) { msg.Error = true; msg.Title = "Có lỗi xảy ra!"; msg.Object = ex; return(Json(msg)); } }
public TrialError addTrial(string mobile) { string tel; if (mobile.Length != 11) { return(TrialError.Invalid); } lock (obj) { TrialError error = canotAdd(mobile); if (error == TrialError.OK) { try { string pwd = createPwd(); using (TransactionScope tran = new TransactionScope()) { using (var ctx = new ShtxSms2008Entities()) { var cbs = ctx.CustomerBases.Where(o => o.Tel.Contains(mobile)).OrderByDescending(o => o.Tel).ToList(); CustomerBase maxCb = cbs.FirstOrDefault(); if (cbs.Count() > 0) { var maxTel = maxCb.Tel; if (maxTel == mobile) { tel = mobile + "-01"; } else { var suf = int.Parse(maxTel.Split(new char[] { '-' })[1]); tel = mobile + "-" + ((suf + 1).ToString().PadLeft(2, '0')); } } else { tel = mobile; } CustomerExtend maxCe = null; if (maxCb != null) { maxCe = ctx.CustomerExtend.FirstOrDefault(o => o.Tel == maxCb.Tel); } CustomerBase cb = new CustomerBase(); cb.Tel = tel; cb.Name = (maxCb == null ? "app试用用户" : maxCb.Name); cb.CompanyName = (maxCb == null ? "app试用用户" : maxCb.CompanyName); cb.SendInterFace = 102; cb.BargainID = 0; cb.Province = (maxCb == null ? 3 : maxCb.Province); cb.Sort = 0; cb.Appsecret = pwd; cb.ProductLine = 1; CustomerExtend ce = new CustomerExtend(); ce.Tel = tel; DateTime today = DateTime.Today; ce.FirstDate = today; ce.UpdateDate = DateTime.Now; ce.EndDate = today.AddDays(14); ce.IsPayment = false; ce.CusTerm = 0; ce.UnitPrice = 0; ce.TotalCon = 0; ce.CusKind = 2; ce.Valid = true; ce.Mid = (maxCe == null ? "admin" : maxCe.Mid); ce.Defer = 0; ce.SendInterFace = 102; ce.BargainID = 0; ce.RoleID = 15; ce.EnFlag = 1; ce.CusSendAttribute = 1; ce.SendRank = 10; ce.ExtendID = Guid.NewGuid(); App_user user = ctx.App_user.Where(u => u.Tel == mobile).FirstOrDefault(); if (user != null) { user.applyCount++; } else { user = new App_user(); user.Tel = mobile; user.applyCount = 1; ctx.App_user.Add(user); } ctx.CustomerBases.Add(cb); ctx.CustomerExtend.Add(ce); ctx.SaveChanges(); tran.Complete(); } } sendSms(mobile, getMsg(mobile, pwd)); return(TrialError.OK); } catch { return(TrialError.SystemError); } } else { return(error); } } }