Exemplo n.º 1
0
        public override async Task <int> HandleCommand(UpdateUOMCommand request, CancellationToken cancellationToken)
        {
            UOM uom = null;

            if (request.Model == null || request.Model.Id == 0)
            {
                throw new BusinessException("UOM.NotExisted");
            }
            else
            {
                uom = await uomQueries.GetByIdAsync(request.Model.Id);

                if (uom == null)
                {
                    throw new BusinessException("UOM.NotExisted");
                }
            }

            var rs = -1;

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