コード例 #1
0
        public void TextInitialize()
        {
            var kernel = AssemblyConfiguration.Kernel;

            _createScheduleCommand = kernel.Get <CreateScheduleCommand>();
            _sut = kernel.Get <GetCurrentScheduleQuery>();
        }
コード例 #2
0
        public void ShouldRequireMinimumFields()
        {
            var command = new CreateScheduleCommand();

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <ValidationException>();
        }
コード例 #3
0
        public IHttpActionResult PostSchedule([FromBody] CreateScheduleCommand command)
        {
            var response         = _mediator.Send(command);
            var filteredResponse = Mapper.Map <ScheduleResult>(response);

            return(Ok(filteredResponse));
        }
コード例 #4
0
        public async Task ShouldUpdateSchedule()
        {
            var userId = await RunAsDefaultUserAsync();

            var command = new CreateScheduleCommand
            {
                Title        = "Tasks",
                Note         = "Note",
                ScheduleType = ScheduleType.Daily,
                UserId       = "1"
            };

            var itemId = await SendAsync(command);

            var updateCommand = new UpdateScheduleCommand
            {
                Id    = itemId,
                Title = "Updated Item Title"
            };

            await SendAsync(command);

            var item = await FindAsync <Schedule>(itemId);

            item.Title.Should().Be(updateCommand.Title);
            item.LastModifiedBy.Should().NotBeNull();
            item.LastModifiedBy.Should().Be(userId);
            item.LastModified.Should().NotBeNull();
            item.LastModified.Should().BeCloseTo(DateTime.Now, 1000);
        }
コード例 #5
0
        public async Task <ScheduleResponseModel> PostSchedule(
            [FromForm] ScheduleRequestModel model,
            CancellationToken cancellationToken
            )
        {
            cancellationToken.ThrowIfCancellationRequested();

            var command = new CreateScheduleCommand(
                model.SubjectId,
                model.TeacherId,
                model.StartTime,
                model.Duration,
                model.LessonType,
                model.AudienceNumber
                );

            var scheduleId = await _mediator.Send(command, cancellationToken);

            var query = new FindScheduleByIdQuery(scheduleId);

            var schedule = await _mediator.Send(query, cancellationToken);

            var response = _mapper.Map <ScheduleResponseModel>(schedule);

            return(response);
        }
コード例 #6
0
        public void TestInitialize()
        {
            var commandFactory = AssemblyConfiguration.Kernel.Get <CommandFactory>();
            var queryFactory   = AssemblyConfiguration.Kernel.Get <QueryFactory>();

            _mapper = AssemblyConfiguration.Kernel.Get <IMapper>();
            _createScheduleCommand = commandFactory.GetInstance <CreateScheduleCommand>();
            _getScheduleQuery      = queryFactory.GetInstance <GetSchedulesQuery>();
            _sut = commandFactory.GetInstance <DeleteScheduleCommand>();
        }
コード例 #7
0
        public async Task <Response> CreateSchedule(CreateScheduleCommand schedule)
        {
            var response = await PostAsync <CreateScheduleCommand>(baseurl, schedule);


            if (response.IsSuccessStatusCode)
            {
                return(new Response(true));
            }
            return(new Response(false));
        }
コード例 #8
0
        public async Task <IActionResult> Post([FromBody] CreateScheduleRequest request)
        {
            var command = new CreateScheduleCommand(request.Day, request.Hour, request.CustomerId, request.ServiceId);
            var result  = await createScheduleService.Process(command);

            return(Ok(new ApiReturnItem <ScheduleResult>
            {
                Item = result,
                Success = true
            }));
        }
コード例 #9
0
        public void TestInitialize()
        {
            var commandFactory = AssemblyConfiguration.Kernel.Get <CommandFactory>();
            var queryFactory   = AssemblyConfiguration.Kernel.Get <QueryFactory>();

            _getCurrentScheduleQuery = queryFactory.GetInstance <GetCurrentScheduleQuery>();
            _getTaskQuery            = queryFactory.GetInstance <GetTasksQuery>();
            _createTaskCommand       = commandFactory.GetInstance <CreateTaskCommand>();
            _createScheduleCommand   = commandFactory.GetInstance <CreateScheduleCommand>();
            _sut = commandFactory.GetInstance <TrackWorkTimeCommand>();
        }
コード例 #10
0
        public void Test_CreateScheduleCommand_Create()
        {
            var cmdHandler = new CreateScheduleCommandHandler(db);
            var cmd        = new CreateScheduleCommand {
                Title = "Title", Line = "Line", Date = DateTime.Now
            };
            var cancel    = new CancellationToken();
            var cmdResult = cmdHandler.Handle(cmd, cancel);
            var rslt      = cmdResult.Result;

            Assert.IsTrue(rslt != null);
        }
コード例 #11
0
ファイル: ScheduleController.cs プロジェクト: mjknowles/skej
        public async Task <IActionResult> Post([FromBody] CreateScheduleCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            bool commandResult = false;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var requestCancelOrder = new IdentifiedCommand <CreateScheduleCommand, bool>(command, guid);
                commandResult = await _mediator.Send(requestCancelOrder);
            }

            return(commandResult ? (IActionResult)Ok() : (IActionResult)BadRequest());
        }
コード例 #12
0
        public async Task ShouldGetOnePlanForUser()
        {
            var userId = "10";

            var command = new CreateScheduleCommand
            {
                Title        = "Tasks",
                Note         = "Note",
                ScheduleType = ScheduleType.Daily,
                UserId       = userId
            };

            var itemId = await SendAsync(command);

            var query = new GetSchedulesQuery();

            query.UserId = userId;

            var result = await SendAsync(query);

            result.Lists.Should().HaveCount(1);
        }
コード例 #13
0
        public async Task ShouldDeleteSchedule()
        {
            var command = new CreateScheduleCommand
            {
                Title        = "Tasks",
                Note         = "Note",
                ScheduleType = ScheduleType.Daily,
                UserId       = "1"
            };


            var itemId = await SendAsync(command);

            await SendAsync(new DeleteScheduleCommand
            {
                Id = itemId
            });

            var list = await FindAsync <Schedule>(itemId);

            list.Should().BeNull();
        }
コード例 #14
0
 public async Task<IActionResult> Create([FromBody]CreateScheduleCommand command)
 {
     return Ok(await Mediator.Send(command));
 }
コード例 #15
0
 public async Task <ActionResult <int> > Create(CreateScheduleCommand command)
 {
     return(await Mediator.Send(command));
 }
コード例 #16
0
        public async Task <BooleanResult> Post([FromBody] ScheduleInputModel input)
        {
            var command = new CreateScheduleCommand(input, UCenterUser);

            return(await _mediator.Send(command));
        }
コード例 #17
0
        public void TestInitialize()
        {
            var factory = AssemblyConfiguration.Kernel.Get <CommandFactory>();

            _sut = factory.GetInstance <CreateScheduleCommand>();
        }
コード例 #18
0
        public async Task <IActionResult> Create([FromBody] CreateScheduleCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
コード例 #19
0
        public Task <BaseResponse> Create(CreateScheduleRequest request)
        {
            var response = new BaseResponse();

            try
            {
                #region Tao dữ liệu routes

                var idsInvoice = new List <int>();

                List <ScheduleCommand.Route> lstRoute = new List <ScheduleCommand.Route>();
                foreach (var route in request.Routes)
                {
                    // lay du lieu customer ung voi 1 route
                    List <ScheduleCommand.CustomerInfo> customerInfos = new List <ScheduleCommand.CustomerInfo>();
                    route.Customers.ForEach(x =>
                    {
                        idsInvoice.AddRange(x.Invoices);
                        ScheduleCommand.CustomerInfo customerInfo = new ScheduleCommand.CustomerInfo()
                        {
                            CustomerID = x.CustomerID,
                            Invoices   = string.Join(',', x.Invoices),
                            Lat        = x.Address.Lat.Value.ToString(),
                            Lng        = x.Address.Lng.Value.ToString(),
                            Status     = x.Status,
                            Weight     = x.Weight
                        };
                        customerInfos.Add(customerInfo);
                    });

                    ScheduleCommand.Route routeData = new ScheduleCommand.Route()
                    {
                        EstimatedDistance = route.EstimatedDistance,
                        EstimatedDuration = route.EstimatedDuration,
                        DepotLat          = route.Depot.Lat.Value.ToString(),
                        DepotAddress      = route.Depot.Address,
                        DepotLng          = route.Depot.Lng.Value.ToString(),
                        DriverID          = route.DriverID,
                        WarehouseId       = route.Depot.WarehouseId,
                        Weight            = route.Weight.Value,
                        Status            = route.Status.Value,
                        CustomerInfos     = customerInfos
                    };

                    lstRoute.Add(routeData);
                }
                #endregion

                CreateScheduleCommand createCommand = new CreateScheduleCommand()
                {
                    EstimatedDistance = request.EstimatedDistance,
                    EstimatedDuration = request.EstimatedDuration,
                    Name = request.Name,
                    Note = request.Note,
                    NumberOfCustomers = request.NumberOfCustomers,
                    Weight            = request.Weight,
                    Status            = request.Status,
                    RouteManagerType  = request.RouteManagerType,
                    DeliveredAt       = DateTime.ParseExact(request.Name, "dd-MM-yyyy", null),
                    Routes            = lstRoute
                };
                var result = _bus.SendCommand(createCommand);

                Task <object> status   = result as Task <object>;
                bool          isCreate = (bool)status.Result;
                if (isCreate)
                {
                    var  ipValue          = "192.168.43.51";
                    IBus rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(
                        rabbit =>
                    {
                        IRabbitMqHost rabbitMqHost = rabbit.Host(new Uri($"rabbitmq://{ipValue}/"), settings =>
                        {
                            settings.Username("tuandv");
                            settings.Password("tuandv");
                        });
                    }
                        );

                    var invoices = _invoiceService.GetInvoices(idsInvoice);
                    foreach (var item in invoices)
                    {
                        rabbitBusControl.Publish <InvoiceReadModel>(item);
                    }
                }

                return(Task.FromResult(new BaseResponse
                {
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }