public async Task <IActionResult> Me() { MeVM vm = new MeVM(); Menber menber = null; ViewBag.headerUrl = HttpContext.Session.GetString("headimgurl"); try { var weChatOpenId = HttpContext.Session.GetString("OpenId"); menber = await _context.Menbers.FirstOrDefaultAsync(x => x.WeChatOpenId == weChatOpenId); if (menber == null) { menber = new Menber(); menber.Username = HttpContext.Session.GetString("nickname"); menber.WeChatOpenId = weChatOpenId; _context.Add(menber); _context.SaveChanges(); ViewBag.headerUrl = HttpContext.Session.GetString("headimgurl"); return(RedirectToAction("ModifPhoneNumber", "wechat")); } else { menber.Username = HttpContext.Session.GetString("nickname"); _context.Update(menber); _context.SaveChanges(); } vm.Balance = (decimal)(menber.AccountSum * 0.01);//转化为元 vm.IntegralSum = menber.IntegralSum; vm.Username = menber.Username; vm.PhoneNo = string.IsNullOrEmpty(menber.PhoneNumber) ? "无" : menber.PhoneNumber; vm.OrderSum = await _context.Orders.Where(x => x.OwnerId == menber.Id).CountAsync(); } catch (Exception ex) { RCLog.Error(this, ex.ToString()); } return(View(vm)); }
public MeView() { InitializeComponent(); BindingContext = vm = new MeVM(); }