Пример #1
0
        public async Task <DepartmentProjection> CreateDepartment([FromBody] CreateDepartmentDTO input)
        {
            var command = new CreateDepartmentCommand(input);
            var result  = await _commandDispatcher.Execute(command);

            return(result);
        }
Пример #2
0
 public async Task Post(ContactMessageDto contactMessage)
 {
     var command = new SendContactMessageCommand {
         ContactMessage = contactMessage
     };
     await _commandDispatcher.Execute(command);
 }
Пример #3
0
        public async Task <PositionProjection> CreatePosition([FromBody] CreatePositionDTO input)
        {
            var command = new CreatePositionCommand(input);
            var result  = await _commandDispatcher.Execute(command);

            return(result);
        }
Пример #4
0
        public async Task <RonSwansonQuoteDetailDto> CreateSingle(
            [FromBody] CreateRonSwansonQuoteInputDto input, CancellationToken token)
        {
            var command = new CreateRonSwansonQuoteCommand(input);

            return(await _commandDispatcher.Execute(command, token));
        }
Пример #5
0
        public async Task <ExpenditureViewModel> Post(SaveExpenditureCommand command)
        {
            await _commandDispatcher.Execute <SaveExpenditureCommand, SaveExpenditureCommand.Result>(command);

            var expenditures =
                await _queryDispatcher.Execute <GetExpenditureQuery, GetExpenditureQuery.Result>(new GetExpenditureQuery
            {
                CultureId = command.CultureId,
                UserId    = command.UserId
            });

            var accounts = await _queryDispatcher.Execute <GetAccountQuery, GetAccountQuery.Result>(new GetAccountQuery
            {
                UserId    = command.UserId,
                CultureId = command.CultureId
            });

            var budgets = await _queryDispatcher.Execute <GetBudgetQuery, GetBudgetQuery.Result>(new GetBudgetQuery
            {
                UserId    = command.UserId,
                CultureId = command.CultureId
            });

            return(new ExpenditureViewModel
            {
                AccountPresentations = accounts.AccountPresentations,
                BudgetPresentations = budgets.BudgetPresentations,
                ExpenditurePresentations = expenditures.ExpenditurePresentations
            });
        }
Пример #6
0
        public ActionResult Buy(TransactionBuyingViewModel model, FormCollection collection)
        {
            var id = Guid.NewGuid();

            try
            {
                IImage image = null;

                if (Request.Files["Image"] != null && Request.Files["Image"].ContentLength != 0)
                {
                    image = _imageService.GetImage(Request.Files["Image"], collection["image.Description"], id);
                }

                _commandDispatcher.Execute(new TransactionBuyCommand(id, model.OriginalVersion, model.OrderDate, model.Units,
                    model.PricePerUnit, model.OrderCosts, model.Description, model.Tag, image, model.InitialSL, model.InitialTP, model.Stock.Id, model.Strategy.Id));


                return RedirectToAction("Index");
            }
            catch (DomainValidationException validationException)
            {
                ModelState.AddModelError(validationException.Property, validationException.Message);
            }

            ViewBag.Stocks = _selectItemResolverRegistry.GetItems("Stock");
            ViewBag.Strategies = _selectItemResolverRegistry.GetItems("Strategy");

            return View(model);
        }
Пример #7
0
 public void SendAddItemToInventoryCommand(InventoryItem item)
 {
     if (item != null)
     {
         _commandDispatcher.Execute(new AddItemToInventoryCommand(item.Id));
     }
 }
Пример #8
0
        public ActionResult Create(StrategyViewModel model, FormCollection collection)
        {
            var id = Guid.NewGuid();

            try
            {
                IImage image = null;

                if (Request.Files["Image"] != null && Request.Files["Image"].ContentLength != 0)
                {
                    image = _imageService.GetImage(Request.Files["Image"], collection["image.Description"], id);
                }

                _commandDispatcher.Execute(new StrategyAddCommand(id, model.OriginalVersion, model.Name,
                                                                  model.Description, image));

                return(RedirectToAction("Index"));
            }
            catch (DomainValidationException validationException)
            {
                ModelState.AddModelError(validationException.Property, validationException.Message);
            }

            return(View(model));
        }
Пример #9
0
        public async Task AddComment(int articleId, string text, string userId)
        {
            var article = await _queryDispatcher.Execute <GetArticleById, Article>(new GetArticleById(articleId));

            var result = await Task.Run(() => _commandDispatcher.Execute(new AddComment(text, userId, article, DateTime.Now)));

            _logger.LogInformation($"User with Id {userId} add comment {result.Success}");
        }
Пример #10
0
        public async Task <IActionResult> Post()
        {
            var userCreateCommand = new UserCreateCommand("", "");

            var createdUserId = await _commandDispather.Execute(userCreateCommand);

            return(Ok(createdUserId));
        }
Пример #11
0
        public async Task <IActionResult> Post([FromBody] Todo value)
        {
            value.Id = Guid.NewGuid();

            var command = new CreateTodo(value.Id, value.Description);

            await _command.Execute(command);

            return(Ok(await _query.Execute <GetTodoById, Task <Todo> >(new GetTodoById(value.Id))));
        }
Пример #12
0
        public async Task <UserDTO> CreateUser([FromBody] CreateUserInputDTO input)
        {
            var message = new CreateSingleUserCommand(input);
            var result  = await _commandDispatcher.Execute(message);

            return(result);
        }
Пример #13
0
        public async Task <GetBudgetQuery.Result> Post([FromBody] SaveBudgetCommand command)
        {
            await _commandDispatcher.Execute <SaveBudgetCommand, SaveBudgetCommand.Result>(command);

            var budgets = await _queryDispatcher.Execute <GetBudgetQuery, GetBudgetQuery.Result>(new GetBudgetQuery
            {
                CultureId = command.CultureId,
                UserId    = command.UserId
            });

            return(budgets);
        }
Пример #14
0
        public async Task <GetAccountQuery.Result> Post([FromBody] SaveAccountCommand command)
        {
            await _commandDispatcher.Execute <SaveAccountCommand, SaveAccountCommand.Result>(command);

            var accounts = await _queryDispatcher.Execute <GetAccountQuery, GetAccountQuery.Result>(new GetAccountQuery
            {
                UserId    = command.UserId,
                CultureId = command.CultureId
            });

            return(accounts);
        }
        public CreatePersonModule(ICommandDispatcher commandDispatcher) : base("/api/v1/")
        {
            Post["/persons"] = parameters =>
            {
                CreatePersonCommand command = null;
                try
                {
                    command = this.Bind <CreatePersonCommand>();
                }
                catch (ModelBindingException e)
                {
                    return(Response.AsText("").WithStatusCode(HttpStatusCode.BadRequest));
                }

                try
                {
                    commandDispatcher.Execute(command);
                }
                catch (ArgumentException ae)
                {
                    return(Response.AsText(ae.Message).WithStatusCode(HttpStatusCode.UnprocessableEntity));
                }
                catch (Exception e)
                {
                    return(Response.AsText(e.Message).WithStatusCode(HttpStatusCode.InternalServerError));
                }

                return(Response.AsText("").WithStatusCode(HttpStatusCode.Created).WithHeader("Location", $"/api/v1/persons/{command.Id}"));
            };
        }
Пример #16
0
        /// <summary>
        /// Executes this job.
        /// </summary>
        public void Execute()
        {
            //TODO: Duplicate code, see QuotationController.UpdateQuotation

            Status = ScheduledJobStatus.Running;

            try
            {
                foreach (var stock in _queryDispatcher.Execute(new StockAllQuery()))
                {
                    var latestUpdate = stock.Quotations != null && stock.Quotations.Any() ? stock.Quotations.Max(q => q.Changed) : DateTime.MinValue;

                    var quotations = _quotationServiceClient.Get(stock.Id, latestUpdate.Date).ToList();

                    if (quotations.Any())
                    {
                        var cmd = new StockQuotationsAddOrChangeCommand(
                            stock.Id,
                            stock.OriginalVersion,
                            quotations);

                        _commandDispatcher.Execute(cmd);
                    }
                }
            }
            finally
            {
                Status = ScheduledJobStatus.Stopped;
            }
        }
        public IActionResult AddHashtagHistory([FromBody] HashtagHistoryModel model)
        {
            var command = new AddHashtagHistoryCommand(model);

            _commandDispatcher.Execute(command);
            return(Ok());
        }
        public IActionResult Post(SuperHero superHero)
        {
            var command = new AddSuperHeroCommand(superHero);

            commandDispatcher.Execute(command);

            return(new OkResult());
        }
Пример #19
0
        public async Task <IHttpActionResult> Perspectives(Guid networkId, bool doNotCache = false)
        {
            if (doNotCache)
            {
                await _dispatcher.Execute(new ClearGraphPerspectivesCacheCommand()
                {
                    NetworkId = networkId
                }, User);
            }
            var query = new GraphPerspectivesQuery()
            {
                NetworkId = networkId
            };
            var result = await _queryService.Execute(query, User);

            return(Ok(result));
        }
        public IActionResult Post(Villain villan)
        {
            var command = new AddVillainCommand(villan);

            commandDispatcher.Execute(command);

            return(new OkResult());
        }
Пример #21
0
        public async Task Post(IFormFileCollection file)
        {
            var command = new UploadBlogPostCommand();

            foreach (var ifile in file)
            {
                using (var br = new BinaryReader(ifile.OpenReadStream()))
                {
                    var bytes = br.ReadBytes((int)ifile.Length);
                    command.Files.Add(new UploadBlogPostCommand.File {
                        FileName = ifile.FileName, Data = bytes
                    });
                }
            }

            await _commandDispatcher.Execute(command);
        }
Пример #22
0
        public IActionResult Add(string winnerAlias)
        {
            var command = new AddWinnerCommand(winnerAlias);

            commandDispatcher.Execute(command);

            return(new OkResult());
        }
Пример #23
0
        static void Main(string[] args)
        {
            DataBaseInitializer <TaskContext> .InitializedDatabase();

            IContainer container = new SimpleIocContainer();

            BootStrapper.Configure(container);

            ICommandDispatcher commandDispatcher = container.Resolve <ICommandDispatcher>();

            IQueryDispatcher queryDispatcher = container.Resolve <IQueryDispatcher>();



            var createCommand = new CreateTaskCommand {
                Title = "CQRS Örneği", UserName = "******", IsCompleted = false, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now
            };

            commandDispatcher.Execute(createCommand);


            var getTasksQuery = new GetTasksQuery();

            getTasksQuery.Predicate = (t) => t.IsCompleted == false;

            IQueryable <Task> tasks = queryDispatcher.Query <GetTasksQuery, IQueryable <Task> >(getTasksQuery);


            Console.WriteLine("Bitmemiş tasklar getiriliyor.");

            foreach (var task in tasks.ToList())
            {
                Console.WriteLine(task);
            }

            var lastTask = tasks.ToList().LastOrDefault();


            var changeCommand = new ChangeTaskStatusCommand {
                TaskId = 24, IsCompleted = true, UpdatedOn = DateTime.Now.AddMinutes(5)
            };

            commandDispatcher.Execute(changeCommand);

            Console.ReadLine();
        }
Пример #24
0
        public async Task <PermissionDTO> CreatePermission([FromBody] CreateNewPermissionDTO input)
        {
            var command = new CreatePermissionCommand(input);
            var result  = await _commandDispatcher.Execute(command);

            return(result);
        }
        public IActionResult Create(FeedbackViewModel model)
        {
            var id = Guid.NewGuid();

            try
            {
                _commandDispatcher.Execute(new FeedbackAddCommand(id, model.OriginalVersion, model.Name,
                                                                  model.Description));

                return(RedirectToAction("Index"));
            }
            catch (DomainValidationException validationException)
            {
                ModelState.AddModelError(validationException.Property, validationException.Message);
            }

            return(View(model));
        }
Пример #26
0
        public async Task <IActionResult> Greet(CancellationToken cancellationToken, string name = null)
        {
            var command = new GreetCommand
            {
                Name   = name,
                Method = HttpContext.Request.Method,
            };

            return(Ok(await Dispatcher.Execute(command, cancellationToken)));
        }
Пример #27
0
        public HooksModule(IQueryRunner query, ICommandDispatcher command) : base("/api/admin")
        {
            Get("/projects", async _ => await query.Query(new GetProjects()));

            Post("/project/{projectId}/setup_hooks", async _ =>
            {
                await command.Execute(new SetupProjectHooks(_.projectId));
                return(new { ok = true });
            });
        }
Пример #28
0
        /// <summary>
        /// Get a list of ITweet by hashtag received as parameter.
        /// </summary>
        /// <param name="hashtagValue">Hash tag value.</param>
        /// <returns>List of ITweets.</returns>
        public IList <ITweet> GetTweetListByHashtag(string hashtagValue)
        {
            int count           = 10000;
            var searchParameter = new SearchTweetsParameters(hashtagValue)
            {
                SearchType             = SearchResultType.Popular,
                MaximumNumberOfResults = count,
                TweetSearchType        = TweetSearchType.All
            };

            var tweetsList = Search.SearchTweets(searchParameter).ToList();

            _commandDispatcher.Execute(new AddTweetCommand(tweetsList, hashtagValue));

            //for(int index = 0; index < tweetsList.Count; index++)
            //{
            //   // _commandDispatcher.Execute(new AddTweetCommand(tweetsList[index], hashtagValue));
            //}

            return(tweetsList);
        }
Пример #29
0
        public IActionResult GetIfBot(string username)
        {
            var userByUsername = _queryDispatcher.Execute <GetUserInformationByUsernameQuery,
                                                           GetUserInformationByUsernameQueryResult>(new GetUserInformationByUsernameQuery(username));

            if (userByUsername == null)
            {
                var user    = _twitterUserService.DetermineBotAnalysis(username);
                var command = new AddUserInformationCommand(user);
                _commandDisptacher.Execute(command);
                return(Ok(user));
            }
            return(Ok(userByUsername.UserModel));
        }
Пример #30
0
 private void StocksOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.NewItems != null)
     {
         var updatedStocks = e.NewItems.OfType <Stock>().ToArray();
         MessengerInstance.Send(new UpdateStockMessage(updatedStocks));
         _commandDispatcher.Execute(new UpsertStocksCommand(Mapper.Map <DtoStock[]>(updatedStocks)));
     }
     else if (e.OldItems != null)
     {
         var deleted = e.OldItems.OfType <Stock>().ToArray();
         MessengerInstance.Send(new DeleteStockMessage(deleted));
     }
 }