public Task <Unit> Handle(CreateOneCustomerCommand request, CancellationToken cancellationToken)
        {
            // 命令验证
            if (!request.IsValid())
            {
                // 错误信息收集
                NotifyValidationErrors(request);//主要为验证的信息
                // 返回,结束当前线程
                return(Task.FromResult(new Unit()));
            }

            //依据Oid查询Mecury用户的信息
            var existingOldCustomer = _userInformationRepository.GetUserByUserGuid(request.OID);

            //验证手机号是否已经注册过
            var existingCustomer = _customerRepository.GetByCellphone(existingOldCustomer.PhoneNumber);

            if (existingCustomer != null)
            {
                //引发错误事件
                Bus.RaiseEvent(new DomainNotification("", "用户手机号已注册,无法重复注册!"));
                return(Task.FromResult(new Unit()));
            }

            //新增客户
            var customerAddress = new CustomerAddress(request.Province, request.City);
            var customer        = new Customer(
                request.OID,
                request.UserName,
                request.Sex,
                request.Age,
                customerAddress,
                existingOldCustomer.PhoneNumber,
                request.InitHeight,
                request.InitWeight,
                request.AgenterOid,
                request.SupporterOid,
                request.LastOperaterOid,
                DateTime.Now,
                0
                );

            _customerRepository.Add(customer);

            //新增客户工作信息
            var customerJob = new CustomerJob(Guid.NewGuid(), new Job(request.JobName, request.JobStrength), customer.OID);

            _customerJobRepository.Add(customerJob);

            //新增客户服务信息
            var customerService = new CustomerService(Guid.NewGuid(), customer.OID, request.ServiceOid, 0);

            _customerServiceRepository.Add(customerService);

            if (Commit())
            {
                // 提交成功后,这里可以发布领域事件,比如短信通知
            }
            return(Task.FromResult(new Unit()));
        }
Esempio n. 2
0
 public SystemInitEvent(IMpqApi mpqApi, IWebHost webHost, IMahuaApi mahuaApi, JobConfigService jobConfigService,
                        CustomerJob customerJob)
 {
     this._mpqApi      = mpqApi;
     _webHost          = webHost;
     _mahuaApi         = mahuaApi;
     _jobConfigService = jobConfigService;
     _customerJob      = customerJob;
 }
Esempio n. 3
0
        /// <summary>
        /// 报名工作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task JoinJob(JoinJobInput input)
        {
            var job = await _jobRepository.FirstOrDefaultAsync(c => c.Id == input.JobId);

            if (job == null)
            {
                throw new UserFriendlyException("该工作不存在");
            }
            var count = await _myJobRepository.CountAsync(c =>
                                                          c.CustomerId == input.CustomerId && c.JobId == input.JobId);

            if (count > 0)
            {
                throw new UserFriendlyException("已报名该工作不可重复报名");
            }
            var model = new CustomerJob()
            {
                CustomerId = input.CustomerId,
                JobId      = input.JobId,
                CreatorId  = job.CreatorId
            };
            await _myJobRepository.InsertAsync(model);
        }
        public async Task <dynamic> AssignJob(AssignJobRequest assignJobRequest)
        {
            var transaction = await _jobContext.Database.BeginTransactionAsync();

            try
            {
                var customerId = _jobContext.Customers.Where(x => x.CustomerCode == assignJobRequest.CustomerCode).Select(x => x.Id).FirstOrDefault();
                if (customerId < 1)
                {
                    throw new InvalidOperationException($"CustomerCode:{assignJobRequest.CustomerCode} bulunamadı !");
                }

                var jobId = _jobContext.Jobs.Where(x => x.Code == assignJobRequest.JobCode).Select(x => x.Id).FirstOrDefault();
                if (jobId < 1)
                {
                    throw new InvalidOperationException($"JobCode:{assignJobRequest.JobCode} bulunamadı !");
                }

                var customerJob = new CustomerJob()
                {
                    CustomerId  = customerId,
                    JobId       = jobId,
                    Cron        = assignJobRequest.CronExp,
                    StartDate   = assignJobRequest.StartDate,
                    EndDate     = assignJobRequest.EndDate,
                    Active      = 1,
                    CreatedBy   = 1, //TODO ?
                    CreatedTime = DateTime.Now
                };

                _jobContext.CustomerJob.Add(customerJob);
                var res = await _jobContext.SaveChangesAsync();

                if (res < 1)
                {
                    var exp = new InvalidOperationException("CustomerJob -> Save Error");
                }

                if (assignJobRequest.JobParameters?.Count > 0)
                {
                    foreach (var jobItem in assignJobRequest.JobParameters)
                    {
                        var customerJobParam = new CustomerJobParameter()
                        {
                            CustomerJobId = customerJob.Id,
                            ParamSource   = jobItem.ParamSource,
                            ParamKey      = jobItem.ParamKey,
                            ParamValue    = jobItem.ParamValue,
                            Active        = 1,
                            CreatedBy     = 1, //TODO ?
                            CreatedTime   = DateTime.Now
                        };

                        _jobContext.CustomerJobParameter.Add(customerJobParam);
                    }
                }


                if (assignJobRequest.JobSubscriberItems?.Count > 0)
                {
                    foreach (var jobSubsItem in assignJobRequest.JobSubscriberItems)
                    {
                        var customerJobSubsc = new CustomerJobSubscriber()
                        {
                            CustomerJobId  = customerJob.Id,
                            Subscriber     = jobSubsItem.Subscriber,
                            SubscriberType = jobSubsItem.SubscriberType,
                            Description    = jobSubsItem.Description,
                            Active         = 1,
                            CreatedBy      = 1, //TODO ?
                            CreatedTime    = DateTime.Now
                        };

                        _jobContext.CustomerJobSubscribers.Add(customerJobSubsc);
                    }
                }

                if (assignJobRequest.JobParameters?.Count > 0 || assignJobRequest.JobSubscriberItems?.Count > 0)
                {
                    res = await _jobContext.SaveChangesAsync();

                    if (res < 1)
                    {
                        var exp = new InvalidOperationException("CustomerJobParameter -> Save Error");
                    }
                }

                await transaction.CommitAsync();

                return(Helper.ReturnOk(customerJob.Id));
            }
            catch (Exception ex)
            {
                try
                {
                    await transaction.RollbackAsync();
                }
                catch (Exception)
                {
                }

                BusinessLogger.Log(ConstantHelper.JobLog, "AddHistory", exception: ex, extraParams: new Dictionary <string, object>()
                {
                    { "AssignJobRequest", assignJobRequest },
                    { "RepositoryName", this.GetType().Name }
                });

                return(Helper.ReturnError(ex));
            }
        }
Esempio n. 5
0
 public void Update(CustomerJob entity)
 {
     _CustomerJobDal.Update(entity);
 }
Esempio n. 6
0
 public void Delete(CustomerJob entity)
 {
     _CustomerJobDal.Delete(entity);
 }
Esempio n. 7
0
 public void Create(CustomerJob entity)
 {
     _CustomerJobDal.Create(entity);
 }
Esempio n. 8
0
 private void AllJobsListView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
 {
     jobselected = e.ItemData as CustomerJob;
 }