public async Task <IActionResult> Create([FromBody] CreateManufacturerDto newCategoryDto) { var response = await _service.CreateManufacturerAsync(newCategoryDto); if (!response.Success) { return(BadRequest(response)); } return(Ok(response)); }
public async Task <IActionResult> Add(ManufacturersAddInputModel input) { await this.countriesService.Add(input.Name, input.IsoCode); var manufacturerDto = new CreateManufacturerDto { Name = input.Name, IsoCode = input.IsoCode, Overview = input.Overview, UserId = await this.usersService.GetIdAsync(this.User.Identity.Name), }; await this.manufacturersService.AddAsync(manufacturerDto, input.Files, Path.Combine(this.webHostEnvironment.WebRootPath, "images", "logos")); return(this.Redirect("/")); }
public async Task AddAsync(CreateManufacturerDto inputDto, IFormFile image, string imageFolder) { if (!this.manufacturersRepository.All().Any(x => x.Name == inputDto.Name)) { var manufacturer = new Manufacturer { Name = inputDto.Name, Overview = inputDto.Overview, CountryId = this.countriesRepository.All().SingleOrDefault(x => x.IsoCode == inputDto.IsoCode).Id, Logo = new Image { Name = image.FileName, AddedByEmployeeId = inputDto.UserId, Extension = this.ChangeToContentType(Path.GetExtension(image.FileName).Replace(".", string.Empty).Trim()), }, }; await this.UploadImagesToDirectory(imageFolder, image); await this.manufacturersRepository.AddAsync(manufacturer); await this.manufacturersRepository.SaveChangesAsync(); } }
public async Task <ServiceResponse <GetManufacturerDto> > CreateManufacturerAsync(CreateManufacturerDto dto) { var response = new ServiceResponse <GetManufacturerDto>(); try { Manufacturer newManufacturer = _mapper.Map <Manufacturer>(dto); await _context.Manufacturers.AddAsync(newManufacturer); await _context.SaveChangeWithValidationAsync(); response.Data = _mapper.Map <GetManufacturerDto>(newManufacturer); return(response); } catch (BaseServiceException ex) { response.Success = false; response.Message = ex.ErrorMessage; response.Code = ex.Code; _logger.LogError(ex.Message, ex.StackTrace); return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; response.Code = ErrorCode.MANUFACTURER_UNEXPECTED_ERROR; _logger.LogError(ex.Message, ex.StackTrace); return(response); } }