Пример #1
0
        private async Task <Consultant> CreateConsultantAsync(ConsultantModel model)
        {
            IFormFile formFile   = Request.Form.Files.FirstOrDefault();
            var       consultant = new Consultant
            {
                Name           = model.FullName,
                DateOfBirth    = DateTime.Parse(model.DateOfBirth),
                EmailAddress   = model.EmailAddress,
                StreetAddress  = model.StreetAddress,
                ZipCode        = int.Parse(model.ZipCode),
                City           = model.City,
                IsOnAssignment = model.IsOnAssignment,
                Skills         = model.Skills,
            };

            if (model.ConsultantId.HasValue)
            {
                consultant.ConsultantId = model.ConsultantId.Value;
            }

            if (formFile != null)
            {
                consultant.ConsultantImage = new ConsultantImage
                {
                    Data = await formFile.GetBufferAsync(),
                    Name = formFile.Name
                };
            }

            return(consultant);
        }
Пример #2
0
        /// <summary>
        /// 更新会籍顾问信息
        /// </summary>
        /// <param name="newUserModel">需要更新的会籍顾问信息</param>
        public ConsultantModel Update(ConsultantModel newConsultantModel)
        {
            try
            {
                Repository <consultant> consultantDal = _unitOfWork.GetRepository <consultant>();
                consultant consul = consultantDal.GetObjectByKey(newConsultantModel.Id).Entity;
                if (consul != null)
                {
                    consul.abbreviation    = newConsultantModel.abbreviation;
                    consul.name            = newConsultantModel.Name;
                    consul.commission_rate = newConsultantModel.CommissionRate;
                }
                _unitOfWork.AddAction(consul, DataActions.Update);
                _unitOfWork.Save();

                return(newConsultantModel);
            }
            catch (RepositoryException rex)
            {
                string msg    = rex.Message;
                string reason = rex.StackTrace;
                throw new FaultException <LCFault>
                          (new LCFault(msg), reason);
            }
            catch (Exception ex)
            {
                string msg    = ex.Message;
                string reason = ex.StackTrace;
                throw new FaultException <LCFault>
                          (new LCFault(msg), reason);
            }
        }
Пример #3
0
        /// <summary>
        /// 创建会籍顾问信息
        /// </summary>
        /// <param name="newUserModel">需要创建的会籍顾问信息</param>
        public ConsultantModel Add(ConsultantModel newConsultantModel)
        {
            try
            {
                consultant consul = new consultant();

                consul.abbreviation    = newConsultantModel.abbreviation;
                consul.name            = newConsultantModel.Name;
                consul.commission_rate = newConsultantModel.CommissionRate;

                _unitOfWork.AddAction(consul, DataActions.Add);
                _unitOfWork.Save();

                newConsultantModel.Id = consul.consultant_id;

                return(newConsultantModel);
            }
            catch (RepositoryException rex)
            {
                string msg    = rex.Message;
                string reason = rex.StackTrace;
                throw new FaultException <LCFault>
                          (new LCFault(msg), reason);
            }
            catch (Exception ex)
            {
                string msg    = ex.Message;
                string reason = ex.StackTrace;
                throw new FaultException <LCFault>
                          (new LCFault(msg), reason);
            }
        }
Пример #4
0
        public bool Insert(ConsultantModel consultantModel)
        {
            return(LogIfOperationFailed(() =>
            {
                Consultant consultant = ConsultantMapper.ConvertModelToEntity(consultantModel);
                _unitOfWork.ConsultantRepository.InsertOrUpdate(consultant);
                _unitOfWork.Commit();
                var existingProviderConsultant = _unitOfWork.ProviderConsultantRepository.GetAll.Where(m => m.ConsultantId == consultant.Id).ToList();
                foreach (var ProviderConsultant in existingProviderConsultant)
                {
                    _unitOfWork.ProviderConsultantRepository.Delete(ProviderConsultant.Id);
                }
                _unitOfWork.Commit();

                if (consultantModel.ConsultantProviderIds != null)
                {
                    foreach (var providerId in consultantModel.ConsultantProviderIds)
                    {
                        var providerConsultant = new ProviderConsultant();
                        providerConsultant.ConsultantId = consultant.Id;
                        providerConsultant.ProviderId = providerId;

                        _unitOfWork.ProviderConsultantRepository.InsertOrUpdate(providerConsultant);
                    }
                }
                _unitOfWork.Commit();
                return true;
            }, Resources.ExceptionInsertConsultant, consultantModel.Name));
        }
Пример #5
0
        public async Task <IActionResult> GetConsultantById(int id)
        {
            Consultant consultant = await _consultantService.GetConsultant(id);

            ConsultantModel model = CreateConsultantModel(consultant);

            return(Ok(model));
        }
Пример #6
0
        public async Task <IActionResult> UpdateConsultant([FromForm] ConsultantModel model)
        {
            Consultant consultant = await CreateConsultantAsync(model);

            await _consultantService.UpdateConsultant(consultant);

            return(Ok(model));
        }
Пример #7
0
 public bool Update(ConsultantModel consultantModel)
 {
     return(LogIfOperationFailed(() =>
     {
         Consultant consultant = ConsultantMapper.ConvertModelToEntity(consultantModel);
         _unitOfWork.ConsultantRepository.InsertOrUpdate(consultant);
         _unitOfWork.Commit();
         return true;
     }, Resources.ExceptionUpdateConsultant, consultantModel.Name));
 }
Пример #8
0
        public async Task <IActionResult> NewConsultant([FromForm] ConsultantModel model)
        {
            Consultant consultant = await CreateConsultantAsync(model);

            Consultant dbConsultant = await _consultantService.CreateConsultant(consultant);

            ConsultantModel newModel = CreateConsultantModel(dbConsultant);

            return(Ok(newModel));
        }
Пример #9
0
        public static Consultant ConvertModelToEntity(ConsultantModel consultantModel)
        {
            Consultant consultant = new Consultant();

            consultant.Id   = consultantModel.Id;
            consultant.Name = consultantModel.Name;
            //consultant.ProviderConsultant = consultantModel.ProviderConsultant;

            return(consultant);
        }
Пример #10
0
        public static ConsultantModel ConvertEntityToModel(Consultant consultant)
        {
            ConsultantModel consultantModel = new ConsultantModel();

            consultantModel.Id   = consultant.Id;
            consultantModel.Name = consultant.Name;
            consultantModel.Name = consultant.Name;
            consultantModel.ConsultantProviderIds = consultant.ProviderConsultant.Select(x => x.ProviderId).ToList();
            //consultantModel.ProviderConsultant = consultant...;

            return(consultantModel);
        }
 // POST api/provider
 public IHttpActionResult Post([FromBody] ConsultantModel consultant)
 {
     try
     {
         _consultantService.Insert(consultant);
         return(StatusCode(HttpStatusCode.NoContent));
     }
     catch (Exception ex)
     {
         return(InternalServerError());
     }
 }
Пример #12
0
        public ConsultantModel GetConsultant(int id)
        {
            return(LogIfOperationFailed(() =>
            {
                var consultantEntity = _unitOfWork.ConsultantRepository.Find(id);

                //ToDo:Need to implement Automapper

                ConsultantModel consultantModel = ConsultantMapper.ConvertEntityToModel(consultantEntity);

                return consultantModel;
            }, Resources.ExceptionGetConsultant, id));
        }
Пример #13
0
        private async void MoneyControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (this.gvConsultant.SelectedItem == null)
            {
                await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "请选择需要结算的会籍顾问!", MessageDialogStyle.Affirmative, null);

                return;
            }

            ConsultantModel selectConsultant = gvConsultant.SelectedItem as ConsultantModel;

            if (selectConsultant != null)
            {
                string strErrorMsg = string.Empty;
                try
                {
                    CheckConsultantMoneyWindow cmw = new CheckConsultantMoneyWindow();
                    cmw.ConsultantId   = selectConsultant.Id;
                    cmw.ConsultantName = selectConsultant.Name;
                    cmw.ShowDialog();
                    await bindConsultantList();
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                catch (Exception ex)
                {
                    strErrorMsg = ex.Message;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgError, "该会籍顾问费用结算失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);
                }
            }
        }
        // PUT api/provider/5
        public IHttpActionResult Put(int id, [FromBody] ConsultantModel consultant)
        {
            try
            {
                if (consultant.Id < 0)
                {
                    return(BadRequest());
                }

                _consultantService.Update(consultant);
                return(StatusCode(HttpStatusCode.NoContent));
            }
            catch (Exception ex)
            {
                return(InternalServerError());
            }
        }
Пример #15
0
        private ConsultantModel BuildModel(consultant consultantModule)
        {
            if (consultantModule == null)
            {
                return(null);
            }
            else
            {
                ConsultantModel consultantmodel = new ConsultantModel();
                consultantmodel.Id             = consultantModule.consultant_id;
                consultantmodel.Name           = consultantModule.name;
                consultantmodel.abbreviation   = consultantModule.abbreviation;
                consultantmodel.CommissionRate = consultantModule.commission_rate;

                return(consultantmodel);
            }
        }
Пример #16
0
        private async void UpdateConsultant_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ConsultantModel selectConsultant = gvConsultant.SelectedItem as ConsultantModel;

            if (selectConsultant != null)
            {
                string strErrorMsg = string.Empty;
                try
                {
                    EditConsultantWindow newConsultantWindow = new EditConsultantWindow();
                    newConsultantWindow.SelectConsultant = gvConsultant.SelectedItem as ConsultantModel;
                    newConsultantWindow.Om = OperationMode.EditMode;

                    if (newConsultantWindow.ShowDialog() == true)
                    {
                        await bindConsultantList();
                    }
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                catch (Exception ex)
                {
                    strErrorMsg = ex.Message;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgError, "更新会籍顾问信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);
                }
            }
        }
Пример #17
0
 /// <summary>
 /// 删除会籍顾问信息
 /// </summary>
 /// <param name="deleteUserModel">删除会籍顾问信息</param>
 public bool Delete(ConsultantModel deleteConsultantModel)
 {
     try
     {
         return(DeleteById(deleteConsultantModel.Id));
     }
     catch (RepositoryException rex)
     {
         string msg    = rex.Message;
         string reason = rex.StackTrace;
         throw new FaultException <LCFault>
                   (new LCFault(msg), reason);
     }
     catch (Exception ex)
     {
         string msg    = ex.Message;
         string reason = ex.StackTrace;
         throw new FaultException <LCFault>
                   (new LCFault(msg), reason);
     }
 }
Пример #18
0
        private ConsultantModel CreateConsultantModel(Consultant consultant)
        {
            var model = new ConsultantModel
            {
                ConsultantId   = consultant.ConsultantId,
                FullName       = consultant.Name,
                DateOfBirth    = consultant.DateOfBirth.ToString("yyyy-MM-dd"),
                Age            = consultant.DateOfBirth.GetAge(DateTime.Today),
                EmailAddress   = consultant.EmailAddress,
                StreetAddress  = consultant.StreetAddress,
                ZipCode        = consultant.ZipCode.ToString(),
                City           = consultant.City,
                IsOnAssignment = consultant.IsOnAssignment,
                Skills         = consultant.Skills
            };

            if (consultant.ConsultantImage != null)
            {
                model.ProfileImage = Convert.ToBase64String(consultant.ConsultantImage.Data);
            }
            return(model);
        }
Пример #19
0
        private async void BindConsultantInfo(ConsultantModel selectConsultant)
        {
            string strErrorMsg = string.Empty;

            try
            {
                if (selectConsultant != null)
                {
                    txtName.Text = selectConsultant.Name;
                    txtAbb.Text  = selectConsultant.abbreviation;
                }
            }
            catch (TimeoutException timeProblem)
            {
                strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
            }
            catch (FaultException <LCFault> af)
            {
                strErrorMsg = af.Detail.Message;
            }
            catch (FaultException unknownFault)
            {
                strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
            }
            catch (CommunicationException commProblem)
            {
                strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
            }
            catch (Exception ex)
            {
                strErrorMsg = ex.Message;
            }
            if (strErrorMsg != string.Empty)
            {
                await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "绑定会籍顾问信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);
            }
        }
Пример #20
0
        private async void DeleteConsultant_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (gvConsultant.SelectedItem == null)
            {
                await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "请选择需要删除的会籍顾问!", MessageDialogStyle.Affirmative, null);

                return;
            }

            MessageDialogResult delResult = await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "确定删除该会籍顾问信息吗?", MessageDialogStyle.AffirmativeAndNegative, null);

            if (delResult == MessageDialogResult.Affirmative)
            {
                ConsultantModel selectConsultant = gvConsultant.SelectedItem as ConsultantModel;

                if (selectConsultant != null)
                {
                    string strErrorMsg = string.Empty;
                    try
                    {
                        IAsyncProxy <IConsultantService> consultantServiceProxy = await Task.Run(() => ServiceHelper.GetConsultantService());

                        if (selectConsultant.Id != 0)
                        {
                            //删除已经存在于数据库的数据,对于没有存于数据库的,则事件处理完成时都会刷新列表,故不用处理
                            bool blIsSuccess = await consultantServiceProxy.CallAsync(c => c.DeleteById(selectConsultant.Id));

                            if (blIsSuccess == true)
                            {
                                await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "删除会籍顾问信息成功!", MessageDialogStyle.Affirmative, null);
                            }
                        }

                        await bindConsultantList();
                    }
                    catch (TimeoutException timeProblem)
                    {
                        strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                    }
                    catch (FaultException <LCFault> af)
                    {
                        strErrorMsg = af.Detail.Message;
                    }
                    catch (FaultException unknownFault)
                    {
                        strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                    }
                    catch (CommunicationException commProblem)
                    {
                        strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                    }
                    catch (Exception ex)
                    {
                        strErrorMsg = ex.Message;
                    }
                    if (strErrorMsg != string.Empty)
                    {
                        await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgError, "删除会籍顾问信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);
                    }
                }
            }
        }
Пример #21
0
        private async void btnOK_Click(object sender, RoutedEventArgs e)
        {
            #region 新增
            if (Om == OperationMode.AddMode)
            {
                string strErrorMsg = string.Empty;
                try
                {
                    ConsultantModel newConsultantModel = new ConsultantModel();
                    newConsultantModel.Name         = txtName.Text.Trim();
                    newConsultantModel.abbreviation = txtAbb.Text.Trim();

                    newConsultantModel = await consultantAyncProxy.CallAsync(c => c.Add(newConsultantModel));

                    this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "新增会籍顾问成功!");
                    this.DialogResult = true;
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "新增会籍顾问信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);
                }
            }

            #endregion

            #region 修改
            else
            {
                string strErrorMsg = string.Empty;
                try
                {
                    selectConsultant.abbreviation = txtAbb.Text;

                    selectConsultant = await consultantAyncProxy.CallAsync(c => c.Update(selectConsultant));

                    this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "修改会籍顾问信息成功!");
                    this.DialogResult = true;
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "修改会籍顾问信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);
                }
            }
            #endregion
        }