コード例 #1
0
        public Task <object> Handle(EditDriverCommand command, CancellationToken cancellationToken)
        {
            Driver driver = new Driver(
                id: command.Id,
                name: new Model.ValueObject.Name(command.Name),
                code: new Model.ValueObject.Code(command.Code),
                phoneNumber: new Model.ValueObject.PhoneNumber(command.PhoneNumber),
                status: new Model.ValueObject.Status(command.Status),
                address: new Model.ValueObject.Address(
                    city: command.City,
                    country: command.Country,
                    district: command.District,
                    street: command.Street,
                    streetNumber: command.StreetNumber
                    ),
                dateOfBirth: new Model.ValueObject.Day(Convert.ToDateTime(command.DoB)),
                cardNumber: new Model.ValueObject.CardNumber(command.IDCardNumber),
                note: new Model.ValueObject.Note(command.Note),
                sex: new Model.ValueObject.Sex(command.Sex),
                startDate: new Model.ValueObject.Day(Convert.ToDateTime(command.StartDate)),
                userID: new Model.ValueObject.Identity(command.UserID),
                vehicleTypeID: new Model.ValueObject.VehicleTypeID(String.Join(',', command.VehicleTypeIDs))
                );

            var driverModel = _driverRepository.Update(driver);

            //_bus.RaiseEvent(new DomainNotification("", "Create successfully!!", TypeNotification.Success));
            return(Task.FromResult(driverModel as object));
        }
コード例 #2
0
        public Task <CreateDriverResponse> Update(int id, CreateDriverRequest request)
        {
            var response = new CreateDriverResponse();

            try
            {
                EditDriverCommand vehicleCommand = new EditDriverCommand
                {
                    Id             = id,
                    City           = request.Driver.Address.City,
                    Country        = request.Driver.Address.Country,
                    District       = request.Driver.Address.District,
                    Street         = request.Driver.Address.Street,
                    StreetNumber   = request.Driver.Address.StreetNumber,
                    Code           = request.Driver.Code,
                    Name           = request.Driver.Name,
                    Note           = request.Driver.Note,
                    PhoneNumber    = request.Driver.PhoneNumber,
                    Sex            = request.Driver.Sex,
                    Status         = request.Driver.Status,
                    IDCardNumber   = request.Driver.IDCardNumber,
                    DoB            = DateTime.ParseExact(request.Driver.DoB, "dd/MM/yyyy", null),
                    StartDate      = DateTime.ParseExact(request.Driver.StartDate, "dd/MM/yyyy", null),
                    VehicleTypeIDs = String.Join(',', request.Driver.VehicleTypeIDs.OrderBy(x => x))
                };

                var           result = _bus.SendCommand(vehicleCommand);
                Task <object> status = result as Task <object>;
                var           driver = (DriverModel)status.Result;
                return(Task.FromResult(new CreateDriverResponse
                {
                    Data = driver.Id,
                    Message = "",
                    Success = true
                }));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(new CreateDriverResponse
                {
                    Message = ex.Message,
                    Success = false
                }));
            }
        }