public async Task <IActionResult> AddShop([FromBody] CreateShop command)
        {
            var createShopCommand = new CreateShopCommand(command);
            await _mediator.Send(createShopCommand);

            return(Created($"shops/{createShopCommand.Id}", null));
        }
Exemple #2
0
        public ActionResult Create([Bind(Prefix = "Item")] CreateShop shop)
        {
            IMessageProvider msg = null;

            if (ModelState.IsValid(shop))
            {
                this.ModelState.Clear();

                msg = shop.Create();

                shop = _unityContainer.Resolve <CreateShop>();
            }
            shop.Ready();
            return(View(new EcardModelItem <CreateShop>(shop, msg)));
        }
        public async Task <Guid> RegisterAsync(Guid shopId, CreateShop createShop)
        {
            var shop = await _shopRepository.GetAsync(shopId);

            if (shop != null)
            {
                throw new ServiceException(ErrorCodes.ShopExist,
                                           $"Shop with id: '{shop.Id}' already exists.");
            }

            var responsiblePerson = _mapper.Map <PersonDto, Person>(createShop.ResponsiblePerson);

            shop = new Shop(shopId, createShop.Address, responsiblePerson, createShop.SID, createShop.Phone);
            await _shopRepository.AddAsync(shop);

            return(_mapper.Map <Guid, Guid>(shop.Id));
        }
        public async Task Given_unique_id_shop_should_be_created()
        {
            var command = new CreateShop
            {
                ResponsiblePerson = new PersonDto()
                {
                    Email = "*****@*****.**", Name = "test", Phone = "87378543", Surname = "hivfdh"
                },
                Address = "Kwaitowa 3/12",
                Phone   = "33567876867876",
                SID     = "005"
            };
            var payload  = GetPayload(command);
            var response = await Client.PostAsync("shops", payload);

            response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.Created);

            string id   = response.Headers.Location.ToString().Replace("shops/", "");
            var    shop = await GetShopAsync(id);

            shop.Id.ToString().ShouldBeEquivalentTo(id);
        }
Exemple #5
0
        public async Task CreateShop_Success()
        {
            //adhere
            var initialShops = ProductAssemblyShopCategory.Shops.DeepCopy();

            //arrange
            var command = new CreateShop
            {
                Name           = "New shop name",
                ManagerId      = GlobalAdmin.Id,
                ShopCategoryId = ProductAssemblyShopCategory.Id,
                InitiatorId    = GlobalAdmin.Id
            };
            var handler = new CreateShopHandler(EntityRepository, EventTransmitter);

            //act
            await handler.HandleAsync(command);

            //assert
            var entities = GetRecordedEntities <Shop>(EntityRepository, nameof(EntityRepository.AddAsync));

            Assert.That(entities.Count, Is.EqualTo(1));
            Assert.That(entities[0].Name, Is.EqualTo(command.Name));
            Assert.That(entities[0].Manager, Is.EqualTo(GlobalAdmin));
            Assert.That(entities[0].ShopCategory, Is.EqualTo(ProductAssemblyShopCategory));
            Assert.False(initialShops.Contains(entities[0]));
            Assert.True(ProductAssemblyShopCategory.Shops.Contains(entities[0]));

            var events = GetRecordedEvents <DomainEvent <Shop> >();

            Assert.That(events.Count, Is.EqualTo(1));
            Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Added));
            Assert.That(events[0].Entity, Is.EqualTo(entities[0]));
            Assert.That(events[0].RaisedBy, Is.EqualTo(command.InitiatorId));

            //annul
            ProductAssemblyShopCategory.Shops = initialShops;
        }
 public CreateShopCommand(CreateShop createShop)
 {
     CreateShop = createShop;
 }