Example #1
0
        public Result CreateEngineer(string account, string accountName, string password, string phoneNo, string mailAddress, string weChatAccount)
        {
            //  LogHelper.WriteLog(GetType()).Info("CreateEngineer");
            Result result = new Result();

            try
            {
                result.IsOK = true;
                if (string.IsNullOrEmpty(account))
                {
                    result.IsOK        = false;
                    result.Description = "注册账号不能为空";
                    return(result);
                }
                if (string.IsNullOrEmpty(accountName))
                {
                    result.IsOK        = false;
                    result.Description = "注册账号名称不能为空";
                    return(result);
                }
                if (string.IsNullOrEmpty(password))
                {
                    result.IsOK        = false;
                    result.Description = "注册账号密码不能为空";
                    return(result);
                }
                if (string.IsNullOrEmpty(mailAddress))
                {
                    result.IsOK        = false;
                    result.Description = "注册邮箱账号不能为空";
                    return(result);
                }
                if (string.IsNullOrEmpty(weChatAccount))
                {
                    result.IsOK        = false;
                    result.Description = "注册微信账号不能为空";
                    return(result);
                }
                PCBEntities      pCBEntities  = new PCBEntities();
                PCB_EngineerInfo engineerInfo = pCBEntities.PCB_EngineerInfo.FirstOrDefault(p => p.Account == account || p.MailAddress == mailAddress);
                if (engineerInfo != null || engineerInfo != default(PCB_EngineerInfo))
                {
                    if (engineerInfo.StateCode)
                    {
                        if (engineerInfo.Account == account)
                        {
                            result.Description = "用户" + account + "已经存在";
                        }
                        if (engineerInfo.MailAddress == mailAddress)
                        {
                            result.Description = "邮箱" + mailAddress + "已经存在";
                        }
                        result.IsOK = false;
                        return(result);
                    }
                    else
                    {
                        TimeSpan UseTime = DateTime.Now - engineerInfo.CreateDateTime;
                        if (UseTime.TotalSeconds <= 60)
                        {
                            result.Description = "已经提交申请,请勿重复操作";
                            result.IsOK        = false;
                            return(result);
                        }
                        else //超过60s删除预注册信息
                        {
                            pCBEntities.DeleteObject(engineerInfo);
                        }
                    }
                }
                engineerInfo                = new PCB_EngineerInfo();
                engineerInfo.EngineerID     = System.Guid.NewGuid();
                engineerInfo.Account        = account;
                engineerInfo.Password       = password;
                engineerInfo.AccountName    = accountName;
                engineerInfo.MailAddress    = mailAddress;
                engineerInfo.PhoneNo        = phoneNo;
                engineerInfo.WeChatAccount  = weChatAccount;
                engineerInfo.CreateDateTime = DateTime.Now;
                engineerInfo.StateCode      = false;
                pCBEntities.AddToPCB_EngineerInfo(engineerInfo);

                result = Common.Common.SendMail(mailAddress, engineerInfo.CreateDateTime.ToString());
                if (!result.IsOK)
                {
                    return(result);
                }
                result.IsOK = Convert.ToBoolean(pCBEntities.SaveChanges());
                if (!result.IsOK)
                {
                    result.Description = "注册账号失败";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.InnerException.Message;
            }
            return(result);
        }