示例#1
0
        public static void GenerateStartupInfo(ICompanyRepository companyRepo, IOfficeRepository officeRepo)
        {
            var company1 = new Company()
            {
                Id        = Guid.NewGuid(),
                Name      = "The Big Great Company",
                CEO       = "Peter Johnson",
                OfficeIds = new List <Guid>()
            };

            var office1 = new Office()
            {
                Id           = Guid.NewGuid(),
                BuildingName = "Building Numer One",
                Street       = "Downstreet",
                HouseNumber  = 1,
                City         = "Boston",
            };

            company1.OfficeIds.Add(office1.Id);
            companyRepo.Add(company1);
            officeRepo.Add(office1);

            var company2 = new Company()
            {
                Id        = Guid.NewGuid(),
                Name      = "The Small Company",
                CEO       = "Jan Janssen",
                OfficeIds = new List <Guid>()
            };

            companyRepo.Add(company2);
        }
示例#2
0
        public IHttpActionResult PostOffice(Office Office)
        {
            if (!ModelState.IsValid)
            {
                return(ApiBadRequest(null, ModelState));
            }

            var entity = _officeRepository.Add(Office);

            return(ApiCreated(entity));
        }
示例#3
0
        public IActionResult Post(string values)
        {
            var model = new Office();

            JsonConvert.PopulateObject(values, model);

            if (!TryValidateModel(model))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }

            _officeRepo.Add(model);

            return(_uow.Commit() ? Ok() : StatusCode(StatusCodes.Status500InternalServerError));
        }
        public override void Handle(AddCompanyWithOfficeCommand command)
        {
            var office = new Office()
            {
                Id           = Guid.NewGuid(),
                BuildingName = command.BuildingName,
                Street       = command.Street,
                HouseNumber  = command.HouseNumber,
                City         = command.City
            };
            var company = new Company()
            {
                Id   = Guid.NewGuid(),
                Name = command.CompanyName,
                CEO  = command.CEO,
            };

            company.OfficeIds = new List <Guid>();
            company.OfficeIds.Add(office.Id);

            _companyRepository.Add(company);
            _officeRepository.Add(office);
        }
示例#5
0
        public async Task <Office> AddOffice(Office office)
        {
            var addedEntity = await _officeRepository.Add(OfficeMapper.Map(office));

            return(OfficeMapper.Map(addedEntity));
        }
示例#6
0
        public Task <Unit> Handle(CreateOfficeCommand request, CancellationToken cancellationToken)
        {
            try
            {
                // 命令验证
                if (!request.IsValid())
                {
                    // 错误信息收集
                    NotifyValidationErrors(request);
                    return(Task.FromResult(new Unit()));
                }
                // 实例化领域模型,这里才真正的用到了领域模型
                // 注意这里是通过构造函数方法实现

                Office office = new Office(request.Id,
                                           request.OfficeName.Trim(),
                                           request.OfficePhone?.Trim(),
                                           request.OfficeCode?.Trim(),
                                           request.OfficeType,
                                           request.ParentId,
                                           request.ParentIds?.Trim(),
                                           request.CreateBy,
                                           request.CreateDate,
                                           request.DelFlag,
                                           request.Remark?.Trim(),
                                           request.UpdateDate,
                                           request.UpdateBy);
                // 判断组织机构编码或名称是否存在
                // 这些业务逻辑,当然要在领域层中(领域命令处理程序中)进行处理
                if (!string.IsNullOrWhiteSpace(request.OfficeCode) && _officeRepository.GetAll(x => x.OfficeCode.Equals(request.OfficeCode)).Any())
                {
                    _bus.RaiseEvent(new DomainNotification("", "组织机构编码已经存在!"));
                    return(Task.FromResult(new Unit()));
                }
                if (!string.IsNullOrWhiteSpace(request.OfficeName) && _officeRepository.GetAll(x => x.OfficeName.Equals(request.OfficeName)).Any())
                {
                    _bus.RaiseEvent(new DomainNotification("", "组织机构名称已经存在!"));
                    return(Task.FromResult(new Unit()));
                }
                _officeRepository.Add(office);
                // 统一提交
                if (Commit())
                {
                    OfficeCreatedEvent officeCreatedEvent = new OfficeCreatedEvent(request.Id,
                                                                                   request.OfficeName.Trim(),
                                                                                   request.OfficePhone?.Trim(),
                                                                                   request.OfficeCode?.Trim(),
                                                                                   request.OfficeType,
                                                                                   request.ParentId,
                                                                                   request.ParentIds?.Trim(),
                                                                                   request.CreateBy,
                                                                                   request.CreateDate,
                                                                                   request.DelFlag,
                                                                                   request.Remark?.Trim(),
                                                                                   request.UpdateDate,
                                                                                   request.UpdateBy);
                    _bus.RaiseEvent(officeCreatedEvent);
                }
            }
            catch (Exception e)
            {
                _bus.RaiseEvent(new DomainNotification("", $"系统异常,发生未知错误:{e.Message}"));
            }
            return(Task.FromResult(new Unit()));
        }
示例#7
0
 public int Add(Office officeModel)
 {
     return(_officeRepository.Add(officeModel));
 }
示例#8
0
        public async Task <Office> Add(Office office)
        {
            var data = await _officeRepository.Add(OfficeMapper.Map(office));

            return(office);
        }
示例#9
0
        public IActionResult Create([FromBody] Office newentry)
        {
            var result = _repository.Add(newentry);

            return(Helper.CheckResult(result));
        }