Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Post(BrandCreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var advertiser = await _advertiserService.GetAdvertiser(model.AdvertiserUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

            if (advertiser == null)
            {
                return(BadRequest("The specified advertiser was not found."));
            }

            var productCategory = await _productCategoryService.GetProductCategory(model.ProductCategoryId.GetValueOrDefault(0)).ConfigureAwait(false);

            if (productCategory == null)
            {
                return(BadRequest("The specified product category was not found."));
            }

            var brand = _mapping.Map <AdvertiserProduct>(model);
            await _brandService.CreateBrand(brand).ConfigureAwait(false);

            brand = await _brandService.GetBrand(brand.AdvertiserProductUuid).ConfigureAwait(false);

            var brandViewModel = _mapping.Map <BrandViewModel>(brand);

            return(CreatedAtRoute("Brands.GetById", new { Id = brandViewModel.BrandUuid }, brandViewModel));
        }
Ejemplo n.º 2
0
        public async Task Post_ShouldReturnOk()
        {
            // Arrange
            var model = new BrandCreateViewModel
            {
                AdvertiserUuid    = Guid.NewGuid(),
                SiteListOption    = "AllSites",
                BrandSafetyMode   = "RunOnAllSites",
                ProductCategoryId = 1
            };

            Mock.Mock <IAdvertiserService>().Setup(x => x.GetAdvertiser(It.IsAny <Guid>()))
            .Returns(Task.FromResult(new Advertiser()));
            Mock.Mock <IProductCategoryService>().Setup(x => x.GetProductCategory(It.IsAny <int>()))
            .Returns(Task.FromResult(new ProductCategory()));
            Mock.Mock <IBrandService>().Setup(x => x.GetBrand(It.IsAny <Guid>()))
            .Returns(Task.FromResult(new AdvertiserProduct()));

            // Act
            var retVal = await Controller.Post(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <CreatedAtRouteNegotiatedContentResult <BrandViewModel> >());
            Mock.Mock <IBrandService>().Verify(x => x.CreateBrand(It.IsAny <AdvertiserProduct>()), Times.Once);
        }
Ejemplo n.º 3
0
 public ActionResult Create(BrandCreateViewModel model)
 {
     if (!Security.IsAuthenticate)
     {
         return RedirectToAction("index", "brand");
     }
     if (Brands.DoesBrandExists(model.Name)) {
         ModelState.AddModelError("Name", "This brand already existe please change.");
     }
     if (!ModelState.IsValid)
     {
         return View("Create",model);
     }
     Brands.Create(model);
     return RedirectToAction("index", "brand");
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Add([FromBody] BrandCreateViewModel brand)
        {
            var id = await _brandCommandFunctionality.AddAsync(Mapper.Map <BrandCreateCommand>(brand));

            return(ResponseWithData(StatusCodes.Status201Created, id));
        }