public async Task <ActionResultResponse> Insert(ProductUnit productUnit) { var productInfo = await _productRepository.CheckExists(productUnit.ProductId, productUnit.TenantId); if (!productInfo) { return(new ActionResultResponse(-1, _sharedResourceService.GetString(ErrorMessage.NotExists, _resourceService.GetString("product")))); } // Kiểm tra đơn vị đã tồn tại chưa. var isExists = await _productUnitRepository.CheckExists(productUnit.TenantId, productUnit.ProductId, productUnit.UnitId); if (isExists) { return(new ActionResultResponse(-2, _sharedResourceService.GetString(ErrorMessage.AlreadyExists, _resourceService.GetString("unit")))); } if (productUnit.IsDefault) { // Kiểm tra đã tồn tại đơn vị mặc định chưa. var isDefaultUnitExists = await _productUnitRepository.CheckDefaultUnitExists(productUnit.ProductId, productUnit.TenantId); if (isDefaultUnitExists) { return(new ActionResultResponse(-3, _sharedResourceService.GetString(ErrorMessage.AlreadyExists, _resourceService.GetString("default unit")))); } } var result = await _productUnitRepository.Insert(productUnit); return(new ActionResultResponse(result, result <= 0 ? _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong) : _sharedResourceService.GetString(SuccessMessage.AddSuccessful, _resourceService.GetString("Product unit")))); }
public void CreateProductUnit(CreateProductUnitInput input) { var productunit = new ProductUnit { UnitCode = input.UnitCode, UnitName = input.UnitName, UnitToKg = input.UnitToKg, CreatorUserId = input.CreatorUserId }; _ProductUnitRepository.Insert(productunit); }