public IActionResult Post([FromBody] CreateCatalogViewModel model)
        {
            var newCatalog = mapper.Map <Catalog>(model);
            var res        = repo.Create(newCatalog);

            return(Ok(res));
        }
Exemplo n.º 2
0
        public CreateCatalogWindow()
        {
            InitializeComponent();

            ViewModel        = new CreateCatalogViewModel();
            this.DataContext = ViewModel;

            ViewModel.UpdatedAssetInvalid += ViewModel_UpdatedAssetInvalid;
        }
        public async Task <IHttpActionResult> Create(CreateCatalogViewModel createCatalogviewModel)
        {
            await _companyCatalogService.CreateNewCatalog(User.CompanyId(), createCatalogviewModel.SourceCatalogId, new CatalogModel
            {
                Name        = createCatalogviewModel.Name,
                Description = createCatalogviewModel.Description,
                CompaniesAssignedToCatalog = createCatalogviewModel.CompaniesAssignedToCatalog.Select(companyId => new CatalogCompanyModel
                {
                    CompanyId = companyId,
                }).ToList()
            });

            return(Ok(await _catalogHelper.GetCatalogs(User.CompanyId())));
        }
        public void Can_create_catalogviewmodel_in_wizardmode()
        {
            var vmFactory = new TestCatalogViewModelFactory <ICatalogOverviewStepViewModel>(
                ServManager.GetUri(ServiceNameEnum.Catalog), ServManager.GetUri(ServiceNameEnum.AppConfig));

            var repositoryFactory =
                new DSRepositoryFactory <ICatalogRepository, DSCatalogClient, CatalogEntityFactory>(
                    ServManager.GetUri(ServiceNameEnum.Catalog));

            //create item using entity factory
            var entityFactory = new CatalogEntityFactory();
            var item          = entityFactory.CreateEntity <Catalog>();

            var createViewModel   = new CreateCatalogViewModel(vmFactory, item);
            var overviewViewModel = createViewModel.AllRegisteredSteps[0] as ViewModelDetailAndWizardBase <Catalog>;

            overviewViewModel.InitializeForOpen();

            //check the default values in stepViewModel
            Assert.False(createViewModel.AllRegisteredSteps[0].IsValid);

            // step 1
            //fill the properties for the first step
            overviewViewModel.InnerItem.CatalogId = "TestCatalog";
            overviewViewModel.InnerItem.Name      = "TestName";
            overviewViewModel.InnerItem.CatalogLanguages.Add(new CatalogLanguage()
            {
                Language  = "ru-ru",
                CatalogId = overviewViewModel.InnerItem.CatalogId
            });
            overviewViewModel.InnerItem.DefaultLanguage = "ru-ru";

            Assert.True(createViewModel.AllRegisteredSteps[0].IsValid);

            // final actions: save
            createViewModel.PrepareAndSave();

            using (var repository = repositoryFactory.GetRepositoryInstance())
            {
                var itemFromDb = repository.Catalogs.Where(s => s.CatalogId == item.CatalogId).OfType <Catalog>().Expand(x => x.CatalogLanguages).SingleOrDefault();

                Assert.NotNull(itemFromDb);
                Assert.True(itemFromDb.Name == "TestName");
                Assert.True(itemFromDb.DefaultLanguage == "ru-ru");
                Assert.True(itemFromDb.CatalogLanguages.Any(x => x.Language == "ru-ru"));
            }
        }