示例#1
0
        public object Get()
        {
            var wechatuser = _weChatUserService.GetWeChatUser(HttpContext.Current.User.Identity.GetUser().Id);

            Mapper.Reset();
            Mapper.CreateMap <MangoCard, MangoCardModel>().ForMember(n => n.HtmlCode, opt => opt.Ignore());
            Mapper.CreateMap <CardType, CardTypeModel>()
            .ForMember(n => n.MangoCardModels, opt => opt.MapFrom(src => src.MangoCards));
            return
                (wechatuser.MangoCards.Where(n => !n.IsDeleted)
                 .GroupBy(n => n.CardType)
                 .Select(n => n.Key)
                 .Select(Mapper.Map <CardType, CardTypeModel>));
        }
        public object Post(LoginLogModel model)
        {
            if (model.WeChatUserModel.OpenId != null)
            {
                var wecharuser = _weChatUserService.GetWeChatUser(model.WeChatUserModel.OpenId);
                if (wecharuser == null)
                {
                    wecharuser = new WeChatUser
                    {
                        Id         = Guid.NewGuid(),
                        OpenId     = model.WeChatUserModel.OpenId,
                        NickName   = model.WeChatUserModel.NickName,
                        Gender     = (Gender)model.WeChatUserModel.Gender,
                        Language   = model.WeChatUserModel.Language,
                        City       = model.WeChatUserModel.City,
                        Province   = model.WeChatUserModel.Province,
                        Headimgurl = model.WeChatUserModel.Headimgurl
                    };
                    _weChatUserService.Insert(wecharuser);
                }
                else
                {
                    wecharuser.OpenId     = model.WeChatUserModel.OpenId;
                    wecharuser.NickName   = model.WeChatUserModel.NickName;
                    wecharuser.Gender     = (Gender)model.WeChatUserModel.Gender;
                    wecharuser.Language   = model.WeChatUserModel.Language;
                    wecharuser.City       = model.WeChatUserModel.City;
                    wecharuser.Province   = model.WeChatUserModel.Province;
                    wecharuser.Headimgurl = model.WeChatUserModel.Headimgurl;
                    _weChatUserService.Update();
                }
                var loginLogId = Guid.NewGuid();
                if (_loginLogService.GetLoginLog(model.State) == null)
                {
                    _loginLogService.Insert(new LoginLog
                    {
                        Id            = loginLogId,
                        State         = model.State,
                        CreateTime    = DateTime.Now,
                        WeChatUser_Id = wecharuser.Id
                    });
                    model.CreateTime = DateTime.Now;
                    model.Id         = loginLogId;
                }

                return(model);
            }
            return(null);
        }