コード例 #1
0
        public async Task <LogicResult> PostTherapist(TherapistDetail therapist)
        {
            var unitofwork = _repositoryHelper.GetUnitOfWork();
            var repo       = _repositoryHelper.GetRepository <ITherapistRepository>(unitofwork);

            try
            {
                //var md5Pass = CreateMD5(therapist.passWord);

                var staff = new Staff();

                //{
                //    passWord=md5Pass,
                //    Gender=therapist.Gender,
                //    Phone=therapist.Phone,
                //    Email=therapist.Email,
                //    userName=therapist.userName,
                //    Name=therapist.Name,
                //    DoB=therapist.DoB,
                //    Possition=therapist.Possition,
                //};
                //
                //therapist.passWord = md5Pass;
                staff = _mapper.Map <Staff>(therapist);

                repo.Create(staff);

                var result = await unitofwork.SaveChangesAsync();

                if (!result)
                {
                    return(new LogicResult()
                    {
                        IsSuccess = false, message = Validation.ServerError
                    });
                }

                return(new LogicResult()
                {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new LogicResult()
                {
                    IsSuccess = false, message = Validation.ServerError
                });
            }
        }
コード例 #2
0
        public async Task <LogicResult> PutTherapist(TherapistDetail therapsit)
        {
            var unitofwork = _repositoryHelper.GetUnitOfWork();
            var repo       = _repositoryHelper.GetRepository <ITherapistRepository>(unitofwork);

            try
            {
                var _therapsit = _mapper.Map <Staff>(therapsit);

                var fieldsToUpdate = new string[]
                {
                    nameof(TherapistDetail.Name),
                    nameof(TherapistDetail.Phone),
                    nameof(TherapistDetail.passWord),
                    nameof(TherapistDetail.Gender),
                    nameof(TherapistDetail.DoB),
                    nameof(TherapistDetail.Decription),
                    nameof(TherapistDetail.Avatar),
                    nameof(TherapistDetail.Experience),
                    nameof(TherapistDetail.userName)
                };

                repo.Update(_therapsit, fieldsToUpdate);
                var result = await unitofwork.SaveChangesAsync();

                if (!result)
                {
                    return(new LogicResult()
                    {
                        IsSuccess = false, message = Validation.ServerError
                    });
                }
                return(new LogicResult()
                {
                    IsSuccess = true
                });
            }
            catch
            {
                return(new LogicResult()
                {
                    IsSuccess = false, message = Validation.ServerError
                });
            }
        }
コード例 #3
0
        public async Task <HttpResponseMessage> CreateTherapist(TherapistDetail therapist)
        {
            var messageData = CreateMessageData($"therapist");

            if (!ModelState.IsValid)
            {
                return(CreateValidationErrorResponse(messageData, new ValidationResult(Validation.InvalidParameters)));
            }

            var result = await _therapistService.PostTherapist(therapist);

            if (!result.IsSuccess)
            {
                return(CreateSystemErrorResponse(messageData));
            }

            return(CreateOkResponse(messageData, therapist));
        }