コード例 #1
0
        public ActionResult RegisterModel(UserDTO model)
        {
            string msg = "";

            Validate(model);
            if (ModelState.IsValid)
            {
                UserDTO userParanmodel      = UserServer.GetModelCode(model.ParentCode);    //查询父级信息
                UserDTO userRecommendnmodel = UserServer.GetModelCode(model.RecommendCode); //查询推荐人信息
                if (userParanmodel != null && userRecommendnmodel != null)
                {
                    model.ParentID        = int.Parse(userParanmodel.ID.ToString());
                    model.Layer           = userParanmodel.Layer + 1;
                    model.AgentsID        = 0;
                    model.Emoney          = 0;
                    model.BonusAccount    = 0;
                    model.AllBonusAccount = 0;
                    model.StockAccount    = 0;
                    model.StockMoney      = 0;
                    model.User003         = 0;
                    model.ShopAccount     = 0;
                    model.LeftScore       = 0;
                    model.LeftNewScore    = 0;
                    model.LeftBalance     = 0;
                    model.CenterScore     = 0;
                    model.CenterNewScore  = 0;
                    model.CenterBalance   = 0;
                    model.RightScore      = 0;
                    model.RightNewScore   = 0;
                    model.RightBalance    = 0;
                    model.IsOpend         = 0;
                    model.IsLock          = 0;
                    model.IsAgent         = 0;
                    model.BillCount       = 0;
                    model.RecommendGenera = userRecommendnmodel.RecommendGenera + 1;
                    model.RecommendID     = int.Parse(userRecommendnmodel.ID.ToString());
                    model.RegMoney        = 0;
                    model.RegTime         = DateTime.Now;
                    model.CreateTime      = DateTime.Now;
                    model.Password        = CommonHelper.GetMD5(model.Password);
                    long Id = UserServer.Add(model);
                    if (Id > 0)
                    {
                        model.ID            = Id;
                        model.UserPath      = userParanmodel.UserPath + "-" + Id;
                        model.RecommendPath = userRecommendnmodel.RecommendPath + "-" + Id;
                        UserServer.UpdatePath(model);
                        msg = "注册成功";
                    }
                    else
                    {
                        msg = "注册失败";
                    }
                }
                else
                {
                    msg = "推荐人不存在或安置会员不存在";
                }
            }
            else
            {
                string error = string.Empty;
                foreach (var key in ModelState.Keys)
                {
                    var state = ModelState[key];
                    if (state.Errors.Any())
                    {
                        error = state.Errors.First().ErrorMessage;
                        break;
                    }
                }
                msg = error;
            }

            return(Content("<script>alert('" + msg + "');window.location='/Team/Register';</script>"));
        }