Example #1
0
        public async Task <IActionResult> AddCategory(CategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var acc = new AddCategoryCommand
            {
                Name        = model.Name,
                Description = model.Description
            };

            var result = await _cp.ProcessAsync(acc);

            if (result.Succeeded)
            {
                _logger.LogInformation("Successfully added Category with name {0} and description {1}", model.Name,
                                       model.Description);

                return(RedirectToAction("ManageCategories"));
            }
            _logger.LogWarning("Unable to add category with name {0} and description {1}", model.Name, model.Description);
            // todo: better error handling
            ModelState.AddModelError("Error", "Unable to add category, perhpas the name is not unique.");
            return(View(model));
        }
Example #2
0
        public async Task Category_Create()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new AppcentTodoContext(options))
                {
                    var service = new AddCategoryCommandHandler(context, TestHelper.GetMapperInstance());
                    var command = new AddCategoryCommand();
                    command.Data = new AddCategoryRequest
                    {
                        UserName = "******",
                        Category = "Task Category"
                    };
                    var result = await service.Execute(command);

                    Assert.True(result.Result.IsSuccess);
                }

                using (var context = new AppcentTodoContext(options))
                {
                    var count = context.AcCategories.Where(e => e.CategoryName == "Task Category");
                    Assert.Equal(1, count.Count());
                }
            }
            finally
            {
                connection.Close();
            }
        }
Example #3
0
        void PupulateEntities(out int clientId, out int serviceId)
        {
            var createCategory = new AddCategoryCommand(null, "test");

            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);

            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver <Category>().FutureValue();
            var client   = Session.QueryOver <Client>().FutureValue();

            var categoryId = category.Value.Id;

            clientId = client.Value.Id;

            var createServiceCommand = new CreateServiceCommand(true, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);

            ExecuteCommand(createServiceCommand);

            var service = Session.QueryOver <Service>().SingleOrDefault();

            serviceId = service.Id;
        }
Example #4
0
        public void AddCategory(CategoryParams @params)
        {
            var addProductCommand = new AddCategoryCommand(
                @params.Name);

            bus.SendCommand(addProductCommand);
        }
        public ExpenseTrackerVM()
        {
            Expenses        = new ObservableCollection <Expense>();
            Current_Expence = new Expense();
            NewCategory     = new Category();

            Icons = new ObservableCollection <BitmapImage>();

            foreach (var path in icons)
            {
                Icons.Add(new BitmapImage(new Uri(@path.Substring(3), UriKind.Relative)));
            }
            Rows       = Icons.Count / Cols;
            Categories = new ObservableCollection <Category> {
                new Category()
                {
                    Name = "Food",
                    Icon = new BitmapImage(new Uri(@"../Icons/apple-alt.png", UriKind.Relative))
                },
                new Category()
                {
                    Name = "Coffee/Tea",
                    Icon = new BitmapImage(new Uri(@"../Icons/coffee.png", UriKind.Relative))
                },
                new Category()
                {
                    Name = "Furniture",
                    Icon = new BitmapImage(new Uri(@"../Icons/couch.png", UriKind.Relative))
                },
                new Category()
                {
                    Name = "Sport",
                    Icon = new BitmapImage(new Uri(@"../Icons/swimmer.png", UriKind.Relative))
                },
                new Category()
                {
                    Name = "Technologies",
                    Icon = new BitmapImage(new Uri(@"../Icons/mobile-alt.png", UriKind.Relative))
                },
                new Category()
                {
                    Name = "Leasure",
                    Icon = new BitmapImage(new Uri(@"../Icons/book.png", UriKind.Relative))
                },
                new Category()
                {
                    Name = "Presents",
                    Icon = new BitmapImage(new Uri(@"../Icons/gift.png", UriKind.Relative))
                },
                new Category()
                {
                    Name = "Other",
                    Icon = new BitmapImage(new Uri(@"../Icons/leaf.png", UriKind.Relative))
                }
            };
            AddExpanceCommand  = new AddExpanceCommand(this);
            AddCategoryCommand = new AddCategoryCommand(this);
        }
 public async Task<IActionResult> Add(AddCategoryCommand command)
 {
     if (ModelState.IsValid)
     {
         await Mediator.Handle(command);
         return RedirectToAction(nameof(CategoryList));
     }
     return View(command);
 }
        public async Task <ActionResult> Add(AddCategoryCommand command)
        {
            var result = await _mediator.Send(command);

            if (!result)
            {
                return(NotFound());
            }

            return(Ok());
        }
Example #8
0
        public async Task AddCategoryHandler_Adds_Category()
        {
            var message = new AddCategoryCommand()
            {
                Name = "Test category", Description = "Some description"
            };
            var handler = new AddCategoryCommandHandler(RequestDbContext);

            var result = await handler.Handle(message, CancellationToken.None);

            Assert.IsType <SuccessResult>(result);
        }
    public bool AddCategory(AddCategoryCommand newCategory)
    {
        using (var db = new SqlConnection(_connectionString))
        {
            var sql = @"INSERT INTO [dbo].[Category]
                                       ([Name])
                                 VALUES
                                       (@name)";

            return db.Execute(sql, newCategory) == 1;
        }
    }
Example #10
0
        public void Add_Top_Level_Category()
        {
            const string categoryName = "test";
            var initialCount = Session.QueryOver<Category>().Where(c => c.Name == categoryName).RowCount();

            var addCategoryCommand = new AddCategoryCommand(null, categoryName);
            ExecuteCommand(addCategoryCommand);

            var category = Session.QueryOver<Category>().Where(c => c.Name == categoryName).SingleOrDefault();

            Assert.AreEqual(0, initialCount);
            Assert.AreEqual(categoryName, category.Name);
            Assert.IsNull(category.ParentCategory);
        }
Example #11
0
 public ResultDto CreateCategory(CategoryDto newCategory)
 {
     return(Result(() =>
     {
         var command = new AddCategoryCommand
         {
             Name = newCategory.Name,
             Description = newCategory.Description,
             ParentId = newCategory.ParentId,
             SiteId = newCategory.SiteId,
             IsPublic = newCategory.IsPublic,
         };
         CommandDispatcher.Send(command);
     }));
 }
        void PupulateEntities(out int categoryId, out int clientId)
        {
            var createCategory = new AddCategoryCommand(null, "test");
            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);
            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver<Category>().FutureValue();

            var client = Session.QueryOver<Client>().FutureValue();

            categoryId = category.Value.Id;
            clientId = client.Value.Id;
        }
Example #13
0
        public void Add_Top_Level_Category()
        {
            const string categoryName = "test";
            var          initialCount = Session.QueryOver <Category>().Where(c => c.Name == categoryName).RowCount();

            var addCategoryCommand = new AddCategoryCommand(null, categoryName);

            ExecuteCommand(addCategoryCommand);

            var category = Session.QueryOver <Category>().Where(c => c.Name == categoryName).SingleOrDefault();

            Assert.AreEqual(0, initialCount);
            Assert.AreEqual(categoryName, category.Name);
            Assert.IsNull(category.ParentCategory);
        }
        public async Task <IActionResult> Add(AddCategoryCommand add)
        {
            if (!ModelState.IsValid)
            {
                return(View(add));
            }
            var rs = await Mediator.Send(add);

            if (rs.Succeeded)
            {
                return(RedirectToAction("Index",
                                        new { area = "Admin", id = rs.Data, succeeded = rs.Succeeded, message = rs.Message }));
            }
            ModelState.AddModelError(string.Empty, rs.Message);
            return(View(add));
        }
Example #15
0
        public async Task <ActionResult> AddCategory([FromBody] AddCategoryDto viewRequest)
        {
            if (!TryValidateModel(viewRequest))
            {
                return(BadRequest(ValidationHelper.GetModelErrors(ModelState)));
            }

            var request = this._mapper.Map <AddCategoryRequest>(viewRequest);

            request.UserName = HttpContext.User.Identity.Name;
            var command = new AddCategoryCommand {
                Data = request
            };

            return(await Go(command));
        }
        void PupulateEntities(out int categoryId, out int clientId)
        {
            var createCategory = new AddCategoryCommand(null, "test");

            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);

            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver <Category>().FutureValue();

            var client = Session.QueryOver <Client>().FutureValue();

            categoryId = category.Value.Id;
            clientId   = client.Value.Id;
        }
Example #17
0
        public void Add_Sub_Category()
        {
            const string parentCategoryName = "parent";
            var addParentCategoryCommand = new AddCategoryCommand(null, parentCategoryName);
            ExecuteCommand(addParentCategoryCommand);

            var parentCategory = Session.QueryOver<Category>().Where(c => c.Name == parentCategoryName).SingleOrDefault();

            const string categoryName = "test";
            var addCategoryCommand = new AddCategoryCommand(parentCategory.Id, categoryName);
            ExecuteCommand(addCategoryCommand);

            var category = Session.QueryOver<Category>().Where(c => c.Name == categoryName).SingleOrDefault();

            Assert.AreEqual(categoryName, category.Name);
            Assert.IsNotNull(category.ParentCategory);
        }
Example #18
0
        public async Task AddCategoryCommandHandle_AddsCategory()
        {
            //Arrange
            var addCategoryCommand = new AddCategoryCommand
            {
                Name        = "TestName",
                Description = "TestDescription"
            };

            //Act
            await _addCategoryCommandHandler.Handle(addCategoryCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Categories.Should()
            .Contain(category =>
                     category.Name == addCategoryCommand.Name &&
                     category.Description == addCategoryCommand.Description);
        }
Example #19
0
        public void Add_Sub_Category()
        {
            const string parentCategoryName       = "parent";
            var          addParentCategoryCommand = new AddCategoryCommand(null, parentCategoryName);

            ExecuteCommand(addParentCategoryCommand);

            var parentCategory = Session.QueryOver <Category>().Where(c => c.Name == parentCategoryName).SingleOrDefault();

            const string categoryName       = "test";
            var          addCategoryCommand = new AddCategoryCommand(parentCategory.Id, categoryName);

            ExecuteCommand(addCategoryCommand);

            var category = Session.QueryOver <Category>().Where(c => c.Name == categoryName).SingleOrDefault();

            Assert.AreEqual(categoryName, category.Name);
            Assert.IsNotNull(category.ParentCategory);
        }
        void PupulateEntities(out int clientId, out int serviceId)
        {
            var createCategory = new AddCategoryCommand(null, "test");
            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);
            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver<Category>().FutureValue();
            var client = Session.QueryOver<Client>().FutureValue();

            var categoryId = category.Value.Id;
            clientId = client.Value.Id;

            var createServiceCommand = new CreateServiceCommand(true, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);
            ExecuteCommand(createServiceCommand);

            var service =  Session.QueryOver<Service>().SingleOrDefault();

            serviceId = service.Id;
        }
Example #21
0
        public async Task <IActionResult> AddCategory(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var acc = new AddCategoryCommand()
                {
                    Name        = model.Name,
                    Description = model.Description
                };

                var result = await _cp.ProcessAsync(acc);

                if (result.Succeeded)
                {
                    return(RedirectToAction("ManageCategories"));
                }
                else
                {
                    return(NotFound());
                }
            }
            return(View(model));
        }
Example #22
0
        public async Task <Response <int> > Handle(AddCategoryCommand command, CancellationToken cancellationToken)
        {
            if (await _persistenceUnitOfWork.Category.Entity.Where(x => x.Slug == command.Slug)
                .AnyAsync(cancellationToken: cancellationToken))
            {
                return(Response <int> .Fail("The slug already exists. Please try a different one"));
            }
            var category = _mapper.Map <Domain.Persistence.Entities.Category>(command);

            try
            {
                await _persistenceUnitOfWork.Category.AddAsync(category);

                await _persistenceUnitOfWork.CommitAsync();

                return(Response <int> .Success(category.Id, "Successfully added the category"));
            }
            catch (Exception e)
            {
                _persistenceUnitOfWork.Dispose();
                _logger.LogError(e, "Failed to add category: {category} ", command.Title);
                return(Response <int> .Fail("Failed to add the category"));
            }
        }
Example #23
0
        public async Task <IActionResult> CreateCategory([FromBody] AddCategoryCommand command)
        {
            int id = await _mediator.Send(command, CancellationToken);

            return(CreatedAtAction(nameof(Get), new { id }, command));
        }
Example #24
0
        public void Create(AddCategoryCommand newCategory)
        {
            var repo = new CategoryRepository();

            repo.AddCategory(newCategory);
        }
Example #25
0
        public async Task <IActionResult> AddCategory([FromBody] AddCategoryCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(result));
        }
Example #26
0
        public async Task <IActionResult> AddCategory(AddCategoryCommand cmd)
        {
            var result = await _commandDispatcher.SendAsync(cmd);

            return(Created($"/expenses/{result:N}", result));
        }
 public async Task <IActionResult> AddCategoryAsync([FromBody] AddCategoryCommand command)
 {
     return(await HandleCommandWithLocationResultAsync(command, GetCategoryAsyncRouteName));
 }
Example #28
0
 public async Task <int> AddAsync(AddCategoryCommand category, CancellationToken cancellationToken)
 {
     return(await _categoryRepository.AddAsync(category, cancellationToken));
 }
 private void OnCategorySelectionChanged(CategoryMessage cm)
 {
     _selectedCategory = cm;
     AddCategoryCommand.RaiseCanExecuteChanged();
     DeleteCategoryCommand.RaiseCanExecuteChanged();
 }
Example #30
0
        public async Task <ActionResult <CategoryDto> > Create([FromBody] AddCategoryCommand command)
        {
            var dto = await _mediator.Send(command);

            return(Ok(dto));
        }
 public async Task <IActionResult> AddAsync([FromBody] AddCategoryCommand category, CancellationToken cancellationToken)
 => Ok(await _categoryApplication.AddAsync(category, cancellationToken));
Example #32
0
 public Task <CategoryDto> AddCategory(AddCategoryCommand command, CancellationToken token)
 => HandlerDispatcher.Invoke <AddCategoryHandler, AddCategoryCommand, CategoryDto>(command, token);