public async Task <ActionResult> Create([FromBody] PowerSupplyInsertDto powerSupply) { _logger.LogForModelInsert(HttpContext); var insertResult = await _powerSuppliesService.CreatePowerSupplyAsync(powerSupply); return(insertResult ? Json(powerSupply) : ResponseResultsHelper.InsertError()); }
/// <inheritdoc/> public async Task <bool> CreatePowerSupplyAsync(PowerSupplyInsertDto powerSupply) { var mappedPowerSupply = _mapper.Map <PowerSupplyInsertDto, PowerSupplyEntity>(powerSupply); var entityAlreadyExists = await _unitOfWorkHardwareAPI.PowerSuppliersRepository.AnyAsync(x => x.Equals(mappedPowerSupply)); if (entityAlreadyExists) { return(false); } await _unitOfWorkHardwareAPI.PowerSuppliersRepository.AddAsync(mappedPowerSupply); return(await _unitOfWorkHardwareAPI.SaveChangesAsync() > 0); }