Ejemplo n.º 1
0
        public CustomJsonResult Edit(string operater, RopAgentMasterEdit rop)
        {
            CustomJsonResult result = new CustomJsonResult();


            using (TransactionScope ts = new TransactionScope())
            {
                var user = CurrentDb.SysAgentUser.Where(m => m.Id == rop.Id).FirstOrDefault();

                if (!string.IsNullOrEmpty(rop.Password))
                {
                    user.PasswordHash = PassWordHelper.HashPassword(rop.Password);
                }

                user.FullName    = rop.FullName;
                user.Email       = rop.Email;
                user.PhoneNumber = rop.PhoneNumber;
                user.IsDisable   = rop.IsDisable;
                user.MendTime    = DateTime.Now;
                user.Mender      = operater;

                if (string.IsNullOrEmpty(user.YbInsureSign))
                {
                    user.YbInsureSign = YbInsUtil.GetSign(user.Id, user.Id, user.PhoneNumber, user.FullName);
                }

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功");
            }


            return(result);
        }
Ejemplo n.º 2
0
        public CustomJsonResult Add(string operater, string agentId, RopUserAdd rop)
        {
            var result = new CustomJsonResult();

            if (string.IsNullOrEmpty(rop.UserName))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "用户名不能为空"));
            }

            if (string.IsNullOrEmpty(rop.Password))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "密码不能为空"));
            }

            var isExistUserName = CurrentDb.SysUser.Where(m => m.UserName == rop.UserName).FirstOrDefault();

            if (isExistUserName != null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("该用户名({0})已被使用", rop.UserName)));
            }



            using (TransactionScope ts = new TransactionScope())
            {
                var pAgentUser = CurrentDb.SysAgentUser.Where(m => m.Id == operater).FirstOrDefault();

                var agentUser = new SysAgentUser();
                agentUser.Id            = GuidUtil.New();
                agentUser.PId           = pAgentUser.Id;
                agentUser.UserName      = rop.UserName;
                agentUser.FullName      = rop.FullName;
                agentUser.PasswordHash  = PassWordHelper.HashPassword(rop.Password);
                agentUser.Email         = rop.Email;
                agentUser.PhoneNumber   = rop.PhoneNumber;
                agentUser.BelongSite    = Enumeration.BelongSite.Agent;
                agentUser.IsDelete      = false;
                agentUser.IsDisable     = false;
                agentUser.IsMaster      = false;
                agentUser.AgentId       = pAgentUser.AgentId;
                agentUser.Depth         = pAgentUser.Depth + 1;
                agentUser.Creator       = operater;
                agentUser.CreateTime    = DateTime.Now;
                agentUser.RegisterTime  = DateTime.Now;
                agentUser.SecurityStamp = Guid.NewGuid().ToString().Replace("-", "");
                agentUser.YbInsureSign  = YbInsUtil.GetSign(agentUser.Id, agentUser.Id, agentUser.PhoneNumber, agentUser.FullName);
                CurrentDb.SysAgentUser.Add(agentUser);
                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "新建成功");
            }

            return(result);
        }