Example #1
0
        public async Task <IHttpActionResult> Login(string appKey, string account)
        {
            var user = new IM_User();

            using (var db = new ModelAC())
            {
                user = db.IM_User.SingleOrDefault(p => p.App_Id == new Guid(appKey) && p.UserId == account);
            }

            if (user != null)
            {
                var userInfo = new
                {
                    Account = user.UserId,
                    Name    = user.Name,
                    Img     = getSITE_URL() + "/content/useravatar/mine_001.png"
                };
                var loginResult = new LoginResult {
                    Status = true, Msg = "验证通过.", User = userInfo
                };
                return(Ok(loginResult));
            }
            else
            {
                var loginResult = new LoginResult {
                    Status = false, Msg = "没有账户信息."
                };
                return(Ok(loginResult));
            }
        }
        public async Task <IHttpActionResult> Add(Add_I model)
        {
            var appKey = model.appKey;
            var users  = model.users;

            var       db_result = 0;
            var       oldList   = new List <IM_User>();
            var       newList   = new List <IM_User>();
            ApiResult apiResult = null;

            #region 新增用户
            foreach (var user in users)
            {
                var oldUser = GetImUser(appKey, user.Account);

                if (oldUser != null)
                {
                    oldList.Add(oldUser);
                }
                else
                {
                    var newUser = new IM_User();
                    newUser.App_Id      = appKey;
                    newUser.UserId      = user.Account;
                    newUser.Name        = user.Name;
                    newUser.PortraitUri = "/content/useravatar/public_001.png";
                    newList.Add(newUser);
                }
            }
            db.IM_User.AddRange(newList);

            db_result = await db.SaveChangesAsync();

            #endregion

            if (db_result == 0)
            {
                apiResult = new ApiResult()
                {
                    Status = false, Msg = "新增账户数:0"
                };
            }
            else
            {
                apiResult = new ApiResult()
                {
                    Status = true,
                    Msg    = "新增账户数:" + db_result,
                    Body   = newList.Select(p => new I_User
                    {
                        Account = p.UserId,
                        Name    = p.Name
                    })
                };
            }

            return(Ok(apiResult));
        }