public void Submit(ProductGroup productGroup) { SubmitValidate(productGroup); if (productGroup.Id > 0) { _productGroupRepository.Update(productGroup); } else { _productGroupRepository.Insert(productGroup); } _unitOfWork.Commit(); }
public async Task <IActionResult> AddProductGroup([FromBody] CreateProductGroupDto productGroup) { if (await _productGroupRepository.ProductGroupExists(productGroup.Name)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } var entity = Mapper.Map <ProductGroup>(productGroup); await _productGroupRepository.Insert(entity); if (!await _unitOfWork.Commit()) { return(new StatusCodeResult(500)); } var createdProductGroup = await _productGroupRepository.GetProductGroupByName(entity.Name); return(CreatedAtRoute("ProductGroupGet", new { name = createdProductGroup.Name.ToLower() }, Mapper.Map <ProductGroupDto>(createdProductGroup))); }
/// <summary> /// Implements <see cref="IProductGroupService.AddProductGroup(ProductGroup)"/> /// </summary> public async Task <ProductGroup> AddProductGroup(ProductGroup productGroup) { if (productGroup is null) { throw new ArgumentNullException(nameof(productGroup)); } if (string.IsNullOrWhiteSpace(productGroup.Name)) { throw new ArgumentNullException(nameof(productGroup.Name)); } productGroup.Id = Guid.NewGuid().ToString(); productGroup.CreatedAt = DateTime.Now; productGroup.UpdatedAt = DateTime.Now; _logger.Debug("Generated id {id} for product {name}", productGroup.Id, productGroup.Name); await _productGroupRepository.Insert(productGroup); return(productGroup); }