コード例 #1
0
        public async Task<HttpResponseMessage> PostInitialize([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            Guid uuid = postParameter.uuid;
            if (string.IsNullOrEmpty(openid) && uuid == Guid.Empty)
            {
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByUuidAsync(uuid);
                if (userinfo == null)
                {
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);

                VisitBetweenUser newVisitor = new VisitBetweenUser() { UserGuest_uuid = userUuid, UserHost_uuid = uuid, VisitTime = DateTime.Now };
                await userRepository.AddVisitBetweenUser(newVisitor);

                userinfo.NumOfContacts = await userRepository.GetUserContactNumber(uuid);
                userinfo.NumOfVisitor = await userRepository.GetUserVisitorNumber(uuid);
                userinfo.NumOfFavorite = await userRepository.GetuserFavoriteNumber(uuid);
                userinfo.IsContact = await userRepository.IsUserContact(userUuid, uuid);
                userinfo.IsFavorite = (await userRepository.IsUserFavorite(userUuid, uuid)).ToString();
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, userinfo, HttpStatusCode.OK, customStatus.Success);
            }
        }
コード例 #2
0
ファイル: ChatController.cs プロジェクト: amwtke/bkwecaht
        public async Task<HttpResponseMessage> PostChatCenterInitialize([FromBody]BaseParameter postParameter)
        {
            string openid = postParameter.openID;
            if(string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            using(UserRepository userRepository = new UserRepository())
            {
                var uuid = await userRepository.GetUserUuidByOpenid(openid);
                var sessions = await MessageRedisOp.GetSessionsTimeStampByUuid(uuid.ToString().ToUpper(), Order.Descending, 0, -1);
                List<Tuple<double, UserInfo, string>> ChatCenterList = new List<Tuple<double, UserInfo, string>>();
                foreach(var s in sessions)
                {
                    double unreadNum = await MessageRedisOp.GetUnreadScore(uuid.ToString().ToUpper(), s.Key);
                    List<string> uuidPair = await MessageRedisOp.GetUUidsBySessionId(s.Key);
                    string userUuid = uuidPair[0] == uuid.ToString().ToUpper() ? uuidPair[1] : uuidPair[0];

                    Guid userGUID;
                    if(!Guid.TryParse(userUuid, out userGUID) || userGUID.Equals(Guid.Empty))
                        continue;
                    UserInfo toUser = await userRepository.GetUserInfoByUuidAsync(userGUID);

                    var latestMessage = await WeChatReceiveHelper.GetFirstMessagesFromRedis(uuid.ToString().ToUpper(), userUuid.ToUpper());
                    ChatCenterList.Add(Tuple.Create(unreadNum, toUser, latestMessage));
                }
                return WebApiHelper.HttpRMtoJson(ChatCenterList, HttpStatusCode.OK, customStatus.Success);
            }
        }
コード例 #3
0
ファイル: NoticeController.cs プロジェクト: amwtke/bkwecaht
        public async Task<HttpResponseMessage> PostChatInitialize([FromBody]BaseParameter postParameter)
        {
            string openid = postParameter.openID;
            int pageIndex = postParameter.pageIndex;
            if(string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using(UserRepository userRepository = new UserRepository())
            {
                var user = await userRepository.GetUserUuidByOpenid(openid);
                if(user == null)
                {
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
                }
                var noticeList = await WeChatNoticeReceiveHelper.GetNotice(user, pageIndex);

                if(noticeList != null)
                    foreach(var n in noticeList)
                    {
                        if(n != null)
                            n.RelationObj = await userRepository.GetUserInfoByUuidAsync(n.RelationID_uuid);
                    }

                return WebApiHelper.HttpRMtoJson(Tuple.Create(user, noticeList), HttpStatusCode.OK, customStatus.Success);
            }
        }
コード例 #4
0
ファイル: NoticeController.cs プロジェクト: amwtke/bkwecaht
        public async Task<HttpResponseMessage> PostChatCenterInitialize([FromBody]BaseParameter postParameter)
        {
            string openid = postParameter.openID;
            if(string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            using(UserRepository userRepository = new UserRepository())
            {
                var uuid = await userRepository.GetUserUuidByOpenid(openid);

                double unreadNum = await NoticeRedisOp.GetUnreadScore(uuid);
                var latestNotice = await WeChatNoticeReceiveHelper.GetFirstNoticeFromRedis(uuid);
                if(latestNotice != null)
                    latestNotice.RelationObj = await userRepository.GetUserInfoByUuidAsync(latestNotice.RelationID_uuid);
                return WebApiHelper.HttpRMtoJson(Tuple.Create(unreadNum, latestNotice), HttpStatusCode.OK, customStatus.Success);
            }
        }
コード例 #5
0
ファイル: MyIndexController.cs プロジェクト: amwtke/bkwecaht
 public async Task<HttpResponseMessage> PostInitializeMyContact([FromBody]LoginParameter postParameter)
 {
     string openid = postParameter.openID;
     int pageIndex = postParameter.pageIndex;
     int pageSize = postParameter.pageSize;
     if (string.IsNullOrEmpty(openid) || pageSize == 0)
     {
         return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
     }
     using (UserRepository userRepository = new UserRepository())
     {
         var userUuid = await userRepository.GetUserUuidByOpenid(openid);
         if(userUuid == Guid.Empty)
         {
             return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
         }
         var uclist = await userRepository.GetUserContact(userUuid, pageIndex, pageSize);
         return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, uclist, HttpStatusCode.OK, customStatus.Success);
     }
 }
コード例 #6
0
        public async Task<HttpResponseMessage> PostInitializeMyRecords([FromBody]LoginParameter postParameter)
        {
            string openid = postParameter.openID;
            if(string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            using(UserRepository userRepository = new UserRepository())
            {
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);
                if(userUuid == Guid.Empty)
                {
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                else
                {
                    List<UserSkill> userSkillList = await userRepository.GetUserRecords(new UserSkill() { AccountEmail_uuid = userUuid });
                    List<UserCourse> userCourseList = await userRepository.GetUserRecords(new UserCourse() { AccountEmail_uuid = userUuid });
                    List<UserEducation> userEducationList = await userRepository.GetUserRecords(new UserEducation() { AccountEmail_uuid = userUuid });
                    List<UserExperience> userExperienceList = await userRepository.GetUserRecords(new UserExperience() { AccountEmail_uuid = userUuid });
                    int userArticleNumber = await userRepository.GetUserRecordsNumber(new UserArticle() { AccountEmail_uuid = userUuid });
                    int visitorsBeenToNumber = await userRepository.GetVisitorBeenToNumber(userUuid);
                    List<UserInfo> visitorsBeenTo = await userRepository.GetVisitorBeenTo(userUuid, 6);
                    Dictionary<string,object> tempResult = new Dictionary<string, object>();
                    tempResult.Add("userSkillList", userSkillList);
                    tempResult.Add("userCourseList", userCourseList);
                    tempResult.Add("userEducationList", userEducationList);
                    tempResult.Add("userExperienceList", userExperienceList);
                    tempResult.Add("userArticleNumber", userArticleNumber);
                    tempResult.Add("visitorsBeenToNumber", visitorsBeenToNumber);
                    tempResult.Add("visitorsBeenToTopSix", visitorsBeenTo);
                    return WebApiHelper.HttpRMtoJson(tempResult, HttpStatusCode.OK, customStatus.Success);
                }

            }
        }
コード例 #7
0
ファイル: ChatController.cs プロジェクト: amwtke/bkwecaht
 public async Task<HttpResponseMessage> IsThereUnredMessage([FromBody]BaseParameter postParameter)
 {
     string openid = postParameter.openID;
     if(string.IsNullOrEmpty(openid))
     {
         return WebApiHelper.HttpRMtoJson("没有传openid", HttpStatusCode.OK, customStatus.InvalidArguments);
     }
     using(UserRepository userRepository = new UserRepository())
     {
         var userUuid = await userRepository.GetUserUuidByOpenid(openid);
         if(userUuid.Equals(Guid.Empty))
         {
             return WebApiHelper.HttpRMtoJson("没有取到uuid,openid=" + openid, HttpStatusCode.OK, customStatus.Fail);
         }
         else
         {
             bool flag = await MessageRedisOp.IsGetUnredScore(userUuid.ToString().ToUpper());
             return WebApiHelper.HttpRMtoJson(flag, HttpStatusCode.OK, customStatus.Success);
         }
     }
 }
コード例 #8
0
ファイル: ChatController.cs プロジェクト: amwtke/bkwecaht
        public async Task<HttpResponseMessage> PostSendChat([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            Guid uuid = postParameter.uuid;
            string textMsg = postParameter.textMsg;
            if(string.IsNullOrEmpty(openid) || uuid == Guid.Empty || string.IsNullOrEmpty(textMsg))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using(UserRepository userRepository = new UserRepository())
            {
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);
                var result = await WeChatSendMQHelper.SendMessage(userUuid.ToString().ToUpper(), uuid.ToString().ToUpper(), textMsg);
                if(result)
                {
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
                }
                else
                {
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
                }
            }
        }
コード例 #9
0
        protected virtual async Task<ActionResult> WeixinCallback(string code, string state, string redirectUrl)
        {
            try
            {
                if (code == null)
                    return Content("code是空!");
                //LogHelper.LogInfoAsync(typeof(WeChatCallBackController), @"1\code=" + code);

                var config = BK.Configuration.BK_ConfigurationManager.GetConfig<WeixinConfig>();
                bool Isbinded = true;

                var openid = await WXAuthHelper.GetOpenIdWXCallBackAsync(config.WeixinAppId, config.WeixinAppSecret, code, async delegate (OAuthAccessTokenResult result)
                {
                    //是否需要绑定账号

                    using (UserRepository userRepository = new UserRepository())
                    {
                        //如果OPenid绑定了,就不需要再向微信请求userinfo的信息了.
                        //如果没有绑定,则需要刷新accesstoken,然后请求userinfo;并将userinfo存入redis。
                        Isbinded = await userRepository.IsUserOpenidExist(result.openid);
                    }

                    if (!Isbinded)
                        //如果没有绑定就要存储token信息
                        await WeChatCallBackControllerHelper.SaveOAuthUserTokenAsync(result);
                    return !Isbinded;//如果绑定了就不需要获取userinfo信息了
                }, async delegate (OAuthUserInfo user)
                {
                    //如果需要绑定用户信息则,此处存储用户信息
                    return await WeChatCallBackControllerHelper.SaveOAuthUserInfoToRedis(user);
                });

                //再次判断是否需要绑定

                //存入cookie供前端代码调用
                Response.Cookies["openid"].Value = openid;
                Response.Cookies["openid"].Expires = DateTime.Now.AddYears(1);


                //如果是tester则不管怎么样都要去注册。
                //可以通过wechat.51science.cn/weixinapi/addtester/?openid=xxx来添加
                //wechat.51science.cn/weixinapi/rmtester/?openid=xxx删除
                bool isToRegister = !Isbinded || await WXAuthHelper.IsTester(openid);
                if (!isToRegister)
                {
                    //记录用户行为
                    await UserLoginBehaviorOp.AddLoginCountAsync(openid);
                    await UserLoginBehaviorOp.AddUpdateLastLoginTimeAsync(openid);
                    //跳转到个人主页
                    using (UserRepository userRepository = new UserRepository())
                    {
                        //存入uuid
                        Response.Cookies["uuid"].Value = (await userRepository.GetUserUuidByOpenid(openid)).ToString();
                        Response.Cookies["uuid"].Expires = DateTime.Now.AddYears(1);
                    }
                    return Redirect(redirectUrl);
                }
                else
                {
                    // login页面 
                    return Redirect(LOGIN_PAGE_URL);
                }

            }
            catch (Exception ex)
            {
                LogHelper.LogErrorAsync(typeof(MVCNeedWeixinCallBackBaseController), ex);
                return Content(ex.ToString());
            }
        }
コード例 #10
0
        public async Task<HttpResponseMessage> PostInitializeUserPatent([FromBody]UserRecordsParameter postParameter)
        {
            string openid = postParameter.openID;
            long id = postParameter.id;
            int pageIndex = postParameter.pageIndex;
            int pageSize = postParameter.pageSize;

            if(string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using(UserRepository userRepository = new UserRepository())
            {
                dynamic resultList;
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);
                if(id != 0)
                {
                    resultList = null;
                    //resultList = await userRepository.GetUserRecordsById<UserPatent>(id);
                }
                else if(pageIndex != 0 && pageSize != 0)
                {
                    resultList = await userRepository.GetUserRecords(new UserPatent() { AccountEmail_uuid = userUuid }, pageIndex, pageSize);
                }
                else
                {
                    resultList = await userRepository.GetUserRecords(new UserPatent() { AccountEmail_uuid = userUuid });
                }
                return WebApiHelper.HttpRMtoJson(resultList, HttpStatusCode.OK, customStatus.Success);
            }


        }
コード例 #11
0
        public async Task<HttpResponseMessage> PostDeleteUserRecordsById([FromBody]UserRecordsParameter postParameter)
        {
            string openid = postParameter.openID;
            if(string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using(UserRepository userRepository = new UserRepository())
            {
                dynamic input = null;
                Guid uuid = await userRepository.GetUserUuidByOpenid(openid);
                if(uuid == Guid.Empty)
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);

                foreach(System.Reflection.PropertyInfo pi in postParameter.GetType().GetProperties())
                {
                    if(pi.PropertyType.BaseType.Equals(typeof(DBModelBase)) && pi.GetValue(postParameter) != null)
                    {
                        input = Convert.ChangeType(pi.GetValue(postParameter), pi.PropertyType);
                        break;
                    }
                }
                if(input == null)
                {
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
                }
                if(uuid != input.AccountEmail_uuid)
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Forbidden);

                if(await userRepository.DeleteUserRecordsById(input))
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
                else
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
            }
        }
コード例 #12
0
        public async Task<HttpResponseMessage> PostGetInterests([FromBody]BaseParameter postParameter)
        {
            string openid = postParameter.openID;
            if (string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userRepository = new UserRepository())
            {
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);
                if (userUuid == Guid.Empty)
                {
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                else
                {
                    UserInfo userinfo = await userRepository.GetUserInfoByOpenid(openid);
                    //研究兴趣
                    string researchField = userinfo.Interests;
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, researchField, HttpStatusCode.OK, customStatus.Success);
                }
            }
        }
コード例 #13
0
        public async Task<HttpResponseMessage> PostUpdateResearchField([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(postParameter.textMsg))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            using (UserRepository userRepository = new UserRepository())
            {
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);
                if (userUuid == Guid.Empty)
                {
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                else
                {
                    UserInfo userinfo = await userRepository.GetUserInfoByOpenid(openid);

                    //更新研究兴趣
                    userinfo.Interests = postParameter.textMsg;
                    bool flag = await userRepository.SaveUserInfo(userinfo);
                    if(flag)
                        return WebApiHelper.HttpRMtoJson(flag, HttpStatusCode.OK, customStatus.Success);
                    else
                        return WebApiHelper.HttpRMtoJson("没有保存成功", HttpStatusCode.OK, customStatus.Fail);
                }
            }
        }
コード例 #14
0
ファイル: NoticeController.cs プロジェクト: amwtke/bkwecaht
 public async Task<HttpResponseMessage> PostIsThereUnreadNotice([FromBody]BaseParameter postParameter)
 {
     string openid = postParameter.openID;
     if (string.IsNullOrEmpty(openid))
     {
         return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
     }
     using (UserRepository userRepository = new UserRepository())
     {
         var userUuid = await userRepository.GetUserUuidByOpenid(openid);
         if (userUuid.Equals(Guid.Empty))
         {
             return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
         }
         else
         {
             bool flag = await NoticeRedisOp.GetUnreadScore(userUuid) > 0;
             return WebApiHelper.HttpRMtoJson(flag, HttpStatusCode.OK, customStatus.Success);
         }
     }
 }
コード例 #15
0
        public async Task<HttpResponseMessage> PostInitializeProfessorRecords([FromBody]BaseParameter postParameter)
        {
            string openid = postParameter.openID;
            if (string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            using (UserRepository userRepository = new UserRepository())
            {
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);
                if (userUuid == Guid.Empty)
                {
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                else
                {
                    Dictionary<string, object> tempResult = new Dictionary<string, object>();

                    UserInfo userinfo = await userRepository.GetUserInfoByOpenid(openid);
                    //研究兴趣
                    string researchField = userinfo.Interests;
                    tempResult.Add("yjly", researchField);


                    //学术地位
                    List<UserAcademic> userAcademicList = await userRepository.GetUserRecords(new UserAcademic { AccountEmail_uuid = userUuid });
                    List<string> acadmeicList =  RepositoryHelper.ConvertUserAcademicToString(userAcademicList);
                    tempResult.Add("xsdw", Tuple.Create("UserAcademic", acadmeicList));

                    //项目资助
                    List<UserAwards> userAwardList = await userRepository.GetUserRecords(new UserAwards() { AccountEmail_uuid = userUuid });

                    tempResult.Add("zzxm", Tuple.Create("UserAwards", userAwardList));

                    //教育经历
                    List<UserEducation> userEducationList = await userRepository.GetUserRecords(new UserEducation() { AccountEmail_uuid = userUuid });
                    tempResult.Add("jyjl", Tuple.Create("UserEducation", userEducationList));

                    //工作经历
                    List<UserExperience> userExperienceList = await userRepository.GetUserRecords(new UserExperience() { AccountEmail_uuid = userUuid });
                    tempResult.Add("gzjl", Tuple.Create("UserExperience", userExperienceList));

                    //论文数
                    int userArticleNumber = await userRepository.GetUserRecordsNumber(new UserArticle() { AccountEmail_uuid = userUuid });
                    tempResult.Add("lws", Tuple.Create("UserArticle", userArticleNumber));

                    //专利数
                    int userPatendNumber = await userRepository.GetUserRecordsNumber(new UserPatent() { AccountEmail_uuid = userUuid });
                    tempResult.Add("zls", Tuple.Create("UserPatent", userPatendNumber));

                    //访问过我的人还访问过谁
                    int visitorsBeenToNumber = await userRepository.GetVisitorBeenToNumber(userUuid);
                    List<UserInfo> visitorsBeenTo = await userRepository.GetVisitorBeenTo(userUuid, 6);

                    tempResult.Add("visitorsBeenToNumber", visitorsBeenToNumber);
                    tempResult.Add("visitorsBeenToTopSix", visitorsBeenTo);
                    return WebApiHelper.HttpRMtoJson(tempResult, HttpStatusCode.OK, customStatus.Success);
                }

            }
        }
コード例 #16
0
        public async Task<HttpResponseMessage> PostDeleteFavorite([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            Guid uuid = postParameter.uuid;
            if (string.IsNullOrEmpty(openid) || uuid == Guid.Empty)
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userRepository = new UserRepository())
            {
                Guid myuuid = await userRepository.GetUserUuidByOpenid(openid);
                user_favorite uf = new user_favorite() { user_account_uuid = myuuid, user_fav_account_uuid = uuid, add_time = DateTime.Now };
                var result = await userRepository.DeleteUserFavorite(uf);
                if (result)
                {
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
                }
                else
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
            }
        }
コード例 #17
0
 public async Task<HttpResponseMessage> PostDeleteContact([FromBody]DualParameter postParameter)
 {
     string openid = postParameter.openID;
     Guid uuid = postParameter.uuid;
     if (string.IsNullOrEmpty(openid) || uuid == Guid.Empty)
     {
         return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
     }
     using (UserRepository userRepository = new UserRepository())
     {
         Guid myuuid = await userRepository.GetUserUuidByOpenid(openid);
         var result = await userRepository.DeleteUserContact(uuid, myuuid);
         if (result)
         {
             return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.Success);
         }
         else
             return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
     }
 }
コード例 #18
0
 public async Task<HttpResponseMessage> PostAddContact([FromBody]DualParameter postParameter)
 {
     string openid = postParameter.openID;
     Guid uuid = postParameter.uuid;
     if (string.IsNullOrEmpty(openid) || uuid == Guid.Empty)
     {
         return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
     }
     using (UserRepository userRepository = new UserRepository())
     {
         Guid myuuid = await userRepository.GetUserUuidByOpenid(openid);
         UserContacts uc1 = new UserContacts() { AccountEmail_uuid = myuuid, ConAccount_uuid = uuid, RequestUser_uuid = myuuid, AddTime = DateTime.Now };
         UserContacts uc2 = new UserContacts() { AccountEmail_uuid = uuid, ConAccount_uuid = myuuid, RequestUser_uuid = myuuid, AddTime = DateTime.Now };
         var result = await userRepository.AddUserContact(uc1, uc2);
         if (result)
         {
             return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.Success);
         }
         else
             return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.AccountExist);
     }
 }
コード例 #19
0
        public async Task<HttpResponseMessage> PostGetObjects([FromBody]UserRecordsParameter postParameter)
        {
            string openid = postParameter.openID;
            string typeid = postParameter.typeid;

            int pageIndex = postParameter.pageIndex;
            int pageSize = postParameter.pageSize;
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(typeid) || RecordFactory.GetTypeById(typeid)== null)
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            
            using (UserRepository userRepository = new UserRepository())
            {
                //获取uuid
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);
                if(userUuid.Equals(Guid.Empty))
                    return WebApiHelper.HttpRMtoJson("Error:uuid is empty", HttpStatusCode.OK, customStatus.InvalidArguments);

                //获取对象
                Type t = RecordFactory.GetTypeById(typeid);
                if(t.GetInterface("IDBModelWithID")== null)
                {
                    return WebApiHelper.HttpRMtoJson("Error:类型错误:"+"type:"+t.ToString()+ "。不是IDBModelWithID的接口!", HttpStatusCode.OK, customStatus.InvalidArguments);
                }
                dynamic input = t.Assembly.CreateInstance(t.FullName) as IDBModelWithID;
                input.AccountEmail_uuid = userUuid;

                if (input.Id != 0)
                {
                    input = await userRepository.GetUserRecordsById(input);
                }
                else if (pageIndex != 0 && pageSize != 0)
                {
                    input = await userRepository.GetUserRecords(input, pageIndex, pageSize);
                }
                else
                {
                    input = await userRepository.GetUserRecords(input);
                }

                return WebApiHelper.HttpRMtoJson(input, HttpStatusCode.OK, customStatus.Success);
            }
        }
コード例 #20
-1
ファイル: BaseController.cs プロジェクト: amwtke/bkwecaht
 protected async Task<Guid> getUUidByOpenIdAsync(string openId)
 {
     using (UserRepository r = new UserRepository())
     {
         return await r.GetUserUuidByOpenid(openId);
     }
 }