Exemplo n.º 1
0
        public IActionResult AddNewTherapist([FromBody] AddNewTherapistRequestDto requestDto)
        {
            if (requestDto.ClassifyGuids.Count() <= 0)
            {
                return(Failed(ErrorCode.Empty, "所属大类未选择"));
            }

            if (requestDto.Tag?.Count() <= 0)
            {
                return(Failed(ErrorCode.Empty, "擅长需填写"));
            }

            if (string.Join("", requestDto.Tag).Length > 300)
            {
                return(Failed(ErrorCode.Empty, "擅长超过最大长度限制"));
            }

            if (requestDto.MerchantProjectGuidList.Count() <= 0)
            {
                return(Failed(ErrorCode.Empty, "服务项目未选择"));
            }

            if (!string.IsNullOrEmpty(requestDto.Introduction))
            {
                if (requestDto.Introduction.Length > 500)
                {
                    return(Failed(ErrorCode.Empty, "个人简介超过最大长度限制"));
                }
            }

            var therapistBiz = new TherapistBiz();

            var IsTherapistPhoneExist = therapistBiz.IsTherapistPhoneExist(requestDto.TherapistPhone);

            if (IsTherapistPhoneExist)
            {
                return(Failed(ErrorCode.UserData, "该手机号已注册!"));
            }

            var therapistGuid = Guid.NewGuid().ToString("N");

            var tModel = new TherapistModel()
            {
                TherapistGuid     = therapistGuid,
                TherapistName     = requestDto.TherapistName,
                JobTitle          = requestDto.JobTitle,
                MerchantGuid      = UserID,
                PortraitGuid      = requestDto.PortraitGuid,
                TherapistPhone    = requestDto.TherapistPhone,
                TherapistPassword = CryptoHelper.AddSalt(therapistGuid, requestDto.TherapistPassword),
                Introduction      = requestDto.Introduction,
                Tag             = JsonConvert.SerializeObject(requestDto.Tag),
                CreatedBy       = UserID,
                CreationDate    = DateTime.Now,
                LastUpdatedBy   = UserID,
                LastUpdatedDate = DateTime.Now
            };

            var tpModelList = requestDto.MerchantProjectGuidList.Distinct().Select(d => new TherapistProjectModel()
            {
                TherapistProjectGuid = Guid.NewGuid().ToString("N"),
                TherapistGuid        = tModel.TherapistGuid,
                ProjectGuid          = d,
                CreatedBy            = UserID,
                CreationDate         = DateTime.Now,
                LastUpdatedBy        = UserID,
                LastUpdatedDate      = DateTime.Now,
                Enable = true
            }).ToList();

            var classifyModels = requestDto.ClassifyGuids.Distinct().Select(d => new MerchantTherapistClassifyModel()
            {
                TherapistClassifyGuid = Guid.NewGuid().ToString("N"),
                TherapistGuid         = tModel.TherapistGuid,
                ClassifyGuid          = d,
                CreatedBy             = UserID,
                CreationDate          = DateTime.Now,
                LastUpdatedBy         = UserID,
                LastUpdatedDate       = DateTime.Now,
                Enable  = true,
                OrgGuid = ""
            }).ToList();

            var response = therapistBiz.AddNewTherapist(tModel, tpModelList, classifyModels);

            return(Success(response));
        }