public async Task <IActionResult> Post([FromBody] AddPriceViewModel model) { if (model == null) { return(BadRequest()); } if (await _priceRepo.IsExistNameAsync(model.Name)) { ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist); return(BadRequest(ModelState.GetWithErrorsKey())); } var price = new Price(model.Name); var affectedRows = await _priceRepo.AddAsync(price); if (affectedRows > 0) { var viewModel = AutoMapper.Mapper.Map <PriceViewModel>(price); return(CreatedAtRoute("GetPrice", new { id = price.Number }, viewModel)); } return(BadRequest()); }
public async Task <int> Create(Price price) { await _priceRepository.AddAsync(price); await _unitOfWork.SaveAsync(); return(price.PriceId); }