Exemplo n.º 1
0
        public async Task Create(CreateBrand entity)
        {
            var brand = new Brand
            {
                Name = entity.Name
            };

            await _brandRepository.Create(brand);
        }
Exemplo n.º 2
0
        public async Task <BrandResponse> Create(CreateBrand request)
        {
            var requestDataAccess = _mapper.Map <BrandAccess>(request);
            var entity            = await _brandDataAccess.CreateAsync(requestDataAccess);

            var model = _mapper.Map <BrandResponse>(entity);

            return(model);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateBrand(CreateBrand model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View("~/Views/Admin/Brand/CreateBrand.cshtml", model));
                }
                var newBrand = await _brandService.Create(model);

                return(RedirectToAction("EditBrand", new { id = newBrand.Id }));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
        }
Exemplo n.º 4
0
        public async Task CreateBrand(
            EStatusCode expectedStatus,
            CreateBrand mutation
            )
        {
            if (expectedStatus == EStatusCode.Conflict)
            {
                EntitiesFactory.NewBrand(name: mutation.Name).Save();
            }

            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var brandDb = await MutationsDbContext.Brands.Where(b => b.Id == mutation.Id).FirstOrDefaultAsync();

                Assert.NotNull(brandDb);
                Assert.Equal(mutation.Name, brandDb.Name);
            }
        }
Exemplo n.º 5
0
        public async Task <Brand> Create(CreateBrand newBrand)
        {
            try
            {
                if (_brandRepository.Get().FirstOrDefault(b => b.Name == newBrand.Name) != null)
                {
                    throw new Exception("Brand o takiej nazwie już istnieje");
                }

                var brandGuid     = Guid.NewGuid();
                var maxBrandOrder = _brandRepository.Get().MaxAsync(b => b.Order);
                var brandToCreate = new Brand
                {
                    CreationDate = DateTime.Now,
                    EditDate     = DateTime.Now,
                    Id           = brandGuid,
                    Name         = newBrand.Name,
                    Order        = await maxBrandOrder + 1
                };

                if (newBrand.Cover == null)
                {
                    throw new Exception("Brak zdjęcia głównego dla brandu");
                }
                brandToCreate.CoverId = await SaveCover(brandGuid, newBrand.Name, newBrand.Cover);

                var createdBrand = _brandRepository.Add(brandToCreate);
                await _brandRepository.SaveChangesAsync();

                return(await createdBrand);
            }
            catch (Exception e)
            {
                throw new Exception("Brand hasn't been created", e);
            }
        }
Exemplo n.º 6
0
 public async Task <ActionResult <MutationResult> > CreateAsync([FromBody] CreateBrand mutation)
 {
     return(GetResult(await _mutationsHanlder.Handle(mutation)));
 }