public async Task Create(CreateBrand entity) { var brand = new Brand { Name = entity.Name }; await _brandRepository.Create(brand); }
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); }
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); } }
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); } }
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); } }
public async Task <ActionResult <MutationResult> > CreateAsync([FromBody] CreateBrand mutation) { return(GetResult(await _mutationsHanlder.Handle(mutation))); }