Exemplo n.º 1
0
        public ActionResult Login(LoginRequestViewModel model)
        {
            var loginResult = _userRegistrationService.ValidateUser(model.LoginName, model.Password);

            if (loginResult == Core.Domain.Users.UserLoginResults.Successful)
            {
                var user = this._userService.GetUserByLoginName(model.LoginName);
                _authenticationService.SignIn(user, model.RememberMe);

                var usermodel = new UserViewModel()
                {
                    FirstName    = user.FirstName,
                    LastName     = user.LastName,
                    Email        = user.Email,
                    IsAdmin      = user.IsAdmin,
                    Language     = user.Language,
                    LoginName    = user.LoginName,
                    Phone        = user.Phone,
                    OpenId       = user.OpenId,
                    QQ           = user.QQ,
                    Sex          = user.Sex,
                    Address      = user.Address,
                    Married      = user.Married == null ? false : user.Married.Value,
                    Education    = user.Education,
                    IdentityCard = user.IdentityCard
                };
                return(Json(ResponseMessageExt.Success("", usermodel)));
            }
            else
            {
                return(Json(ResponseMessageExt.Failed(loginResult.ToString())));
            }
        }
Exemplo n.º 2
0
 public ResponseMessageExt DestroyQuestionBank(object obj)
 {
     if (obj is JObject)
     {
         JObject jobj = obj as JObject;
         var     id   = jobj.GetValue("id").ToInt();
         if (id <= 0)
         {
             return(ResponseMessageExt.Failed("参数错误!"));
         }
         this._questionBankService.DeleteQuestionBank(id);
     }
     else if (obj is JArray)
     {
         JArray jarray = obj as JArray;
         foreach (JObject jobj in jarray)
         {
             var id = jobj.GetValue("id").ToInt();
             if (id <= 0)
             {
                 return(ResponseMessageExt.Failed("参数错误!"));
             }
             this._questionBankService.DeleteQuestionBank(id);
         }
     }
     return(ResponseMessageExt.Success());
 }
Exemplo n.º 3
0
 public ResponseMessageExt UpdateQuestionBank(object obj)
 {
     if (obj is JObject)
     {
         JObject      jobj        = obj as JObject;
         var          qbviewmodel = jobj.ToObject <QuestionBankViewModel>();
         QuestionBank qbmodel     = this._questionBankService.GetQuestionBankById(qbviewmodel.id.ToInt());
         if (qbmodel == null)
         {
             return(ResponseMessageExt.Failed("参数错误!"));
         }
         CommonHelper.UpdateT <QuestionBank>(qbmodel, jobj);
         if (qbviewmodel.userattributes != null && qbviewmodel.userattributes.Length > 0)
         {
             string[] tmpArray = qbviewmodel.userattributes.Split(',');
             foreach (var item in tmpArray)
             {
                 int tmpid = item.ToInt();
                 if (qbmodel.UserAttributeList.Any(x => x.Id == tmpid))
                 {
                     continue;
                 }
                 var ua = this._userAttributeService.Get(tmpid);
                 qbmodel.UserAttributeList.Add(ua);
             }
         }
         this._questionBankService.UpdateQuestionBank(qbmodel);
     }
     else if (obj is JArray)
     {
         JArray jarray = obj as JArray;
         foreach (JObject jobj in jarray)
         {
             var          qbviewmodel = jobj.ToObject <QuestionBankViewModel>();
             QuestionBank qbmodel     = this._questionBankService.GetQuestionBankById(qbviewmodel.id.ToInt());
             if (qbmodel == null)
             {
                 return(ResponseMessageExt.Failed("参数错误!"));
             }
             CommonHelper.UpdateT <QuestionBank>(qbmodel, jobj);
             if (qbviewmodel.userattributes != null && qbviewmodel.userattributes.Length > 0)
             {
                 string[] tmpArray = qbviewmodel.userattributes.Split(',');
                 foreach (var item in tmpArray)
                 {
                     int tmpid = item.ToInt();
                     if (qbmodel.UserAttributeList.Any(x => x.Id == tmpid))
                     {
                         continue;
                     }
                     var ua = this._userAttributeService.Get(tmpid);
                     qbmodel.UserAttributeList.Add(ua);
                 }
             }
             this._questionBankService.UpdateQuestionBank(qbmodel);
         }
     }
     return(ResponseMessageExt.Success());
 }
Exemplo n.º 4
0
 public ActionResult CheckLogin()
 {
     if (this._workContext.CurrentUser == null)
     {
         return(Json(ResponseMessageExt.Failed()));
     }
     return(Json(ResponseMessageExt.Success()));
 }
Exemplo n.º 5
0
        public ResponseMessageExt RequestUserAnswer(RequestUserAnswerRequestModel model)
        {
            if (model.questionbankid == 0 || model.userids == null || model.userids.Length == 0)
            {
                return(ResponseMessageExt.Failed("参数错误!"));
            }

            var questionbank = this._questionBankService.GetQuestionBankById(model.questionbankid);

            if (questionbank == null)
            {
                return(ResponseMessageExt.Failed("参数错误!"));
            }
            if (string.IsNullOrEmpty(questionbank.ResponseKeyWords))
            {
                return(ResponseMessageExt.Failed("没有唤醒语句!"));
            }

            StringBuilder sbulder = new StringBuilder();
            string        msg     = WXinConfig.InvitationText.Replace("{title}", questionbank.Title).Replace("{responsekeywords}", questionbank.ResponseKeyWords.Split('|')[0]);

            foreach (var userid in model.userids)
            {
                var user = this._userService.GetUserById(userid);
                if (user == null || string.IsNullOrEmpty(user.OpenId))
                {
                    continue;
                }
                try
                {
                    var result = Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(WXinConfig.WeixinAppId, user.OpenId, msg);
                    if (result.errcode != Senparc.Weixin.ReturnCode.请求成功)
                    {
                        sbulder.AppendLine($"【{user.UserName}】消息发送失败,{result.errmsg}");
                    }
                }
                catch (Exception ex)
                {
                    sbulder.AppendLine($"【{user.UserName}】消息发送失败,{ex.Message}");
                    this._logger.Warning("推送消息发送失败。", ex, user);
                }
            }
            if (sbulder.Length == 0)
            {
                return(ResponseMessageExt.Success());
            }
            return(ResponseMessageExt.Failed(sbulder.ToString()));
        }
Exemplo n.º 6
0
 public ResponseMessageExt Discard(UserAnswerDiscardRequestModel model)
 {
     if (model == null || model.ids.Length == 0)
     {
         return(ResponseMessageExt.Failed("参数错误"));
     }
     foreach (var id in model.ids)
     {
         var useranswer = this._userAnswerService.GetUserAnswerById(id);
         if (useranswer == null)
         {
             continue;
         }
         useranswer.UserAnswerStatus = Core.Domain.Custom.UserAnswerStatus.已作废;
         this._userAnswerService.Save(useranswer);
     }
     return(ResponseMessageExt.Success());
 }