Пример #1
0
        public async Task <ActionResult> Create([FromBody] MotherboardInsertDto motherboard)
        {
            _logger.LogForModelInsert(HttpContext);

            var insertResult = await _motherboardsService.CreateMotherboardAsync(motherboard);

            return(insertResult ? Json(motherboard) : ResponseResultsHelper.InsertError());
        }
Пример #2
0
        /// <inheritdoc/>
        public async Task <bool> CreateMotherboardAsync(MotherboardInsertDto motherboard)
        {
            var mappedMotherboard = _mapper.Map <MotherboardInsertDto, MotherboardEntity>(motherboard);

            var entityAlreadyExists =
                await _unitOfWorkHardwareAPI.MotherboardsRepository.AnyAsync(x => x.Equals(mappedMotherboard));

            if (entityAlreadyExists)
            {
                return(false);
            }

            await _unitOfWorkHardwareAPI.MotherboardsRepository.AddAsync(mappedMotherboard);

            return(await _unitOfWorkHardwareAPI.SaveChangesAsync() > 0);
        }