Exemplo n.º 1
0
        public override async Task <int> HandleCommand(DeleteUOMCommand request, CancellationToken cancellationToken)
        {
            if (request.Model == 0)
            {
                throw new BusinessException("UOM.NotSelected");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        if (await uomRepository.DeleteAsync(request.Model) > 0)
                        {
                            rs = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }
            return(rs);
        }