예제 #1
0
        public CommandResult CadastrarTipoInscricao(TipoInscricao tipoInscricao)
        {
            try
            {
                _uow.BeginTransaction();
                _uow.GetConnection().Execute(
                    "dbo.spGravaTipoInscricao",
                    new
                {
                    Id           = tipoInscricao.Id,
                    Descricao    = tipoInscricao.Descricao,
                    Status       = tipoInscricao.Status,
                    AliasUsuario = tipoInscricao.AliasUsuario
                },
                    _uow.GetTransaction(),
                    commandType: CommandType.StoredProcedure
                    );

                _uow.Commit();
                return(new CommandResult(true, "Cadastro realizado com sucesso.", null));
            }
            catch (Exception e)
            {
                _uow.Rollback();
                return(new CommandResult(false, "Erro ao tentar realizar cadastro: " + e.Message, null));
            }
        }
예제 #2
0
        public async Task <IActionResult> Response(object result, IEnumerable <Notification> notifications)
        {
            if (!notifications.Any())
            {
                try
                {
                    bool ExistsNofications = false;

                    _uow.OpenTransaction();

                    await _uow.Commit();


                    return(Ok(new
                    {
                        success = true,
                        data = result
                    }));
                }
                catch (Exception ex)
                {
                    return(await TryErrors(ex));
                }
            }
            else
            {
                _uow.Rollback();
                return(BadRequest(new { success = false, errors = notifications.GroupBy(x => new { x.Property, x.Message }).Select(x => x.FirstOrDefault()) }));
            }
        }
 public async Task <IActionResult> Response(object result, IEnumerable <Notification> notifications)
 {
     if (!notifications.Any())
     {
         try
         {
             _uow.Commit();
             return(Ok(new
             {
                 success = true,
                 data = result
             }));
         }
         catch
         {
             _uow.Rollback();
             return(BadRequest(new
             {
                 success = false,
                 errors = new[] { "Ocorreu uma falha interna no servidor." }
             }));
         }
     }
     else
     {
         return(BadRequest(new
         {
             success = false,
             errors = notifications
         }));
     }
 }
예제 #4
0
        public async Task <IActionResult> Respond(object result, IEnumerable <Notification> notifications)
        {
            if (!notifications.Any())
            {
                try
                {
                    _uow.Commit();
                    return(Ok(new
                    {
                        success = true,
                        data = result
                    }));
                }
                catch (Exception ex)
                {
                    _uow.Rollback();
                    return(BadRequest(new
                    {
                        success = false,
                        errors = new[] { "Ocorreu uma falha interna no servidor." }
                    }));
                }
            }
            else
            {
                var translateNotifications = new List <Notification>();

                notifications.ToList().ForEach(notification =>
                {
                    translateNotifications.Add(new Notification(notification.Property, notification.Message));
                });

                _uow.Rollback();
                return(BadRequest(new
                {
                    success = false,
                    errors = translateNotifications
                }));
            }
        }
예제 #5
0
        public async Task <DomainEvent[]> ProcessWithEvents(TCommand command, CrossContext ctx)
        {
            var  logger = _loggerFactory.CreateLogger($"CommandProcessor[{nameof(command)}][{ctx.CorrelationUuid}]");
            IUow uow    = null;

            try
            {
                logger.LogInformation($"Started at {DateTime.Now}");
                var handler = _handlerBuilder();
                handler.Logger = _loggerFactory.CreateLogger(nameof(handler));
                handler.ExternalServiceProvider = _externalServiceProvider;
                handler.CancellationToken       = ctx.Token;

                await handler.BeforeExecute(async func =>
                {
                    using (var nonTransactionalUow = _uowfactory.CreateUnitOfWork(null, ctx.Token))
                    {
                        await func(nonTransactionalUow);
                    }
                }, command);

                var transactionUuid = UseTransaction ? Guid.NewGuid() : (Guid?)null;
                uow = _uowfactory.CreateUnitOfWork(transactionUuid, ctx.Token);

                await handler.Execute(uow, command);

                await uow.Commit();

                return(handler.EventList.ToArray());
            }
            catch (Exception e)
            {
                var t = uow?.Rollback();
                if (t != null)
                {
                    await t;
                }

                logger.LogError("{0}\n{1}", e.Message, e.StackTrace);
                throw;
            }
            finally
            {
                uow?.Dispose();

                logger.LogInformation($"Done at {DateTime.Now}");
            }
        }
예제 #6
0
        private void btnUow_Click(object sender, EventArgs e)
        {
            IUow objUow = FactoryDal <IUow> .Create("EfUow");

            try
            {
                CustomerBase cust1 = new CustomerBase();
                cust1.CustomerName = "UowTest1";
                cust1.CustomerType = "Customer";
                cust1.BillDate     = DateTime.Now;
                cust1.BillAmount   = 10;
                cust1.Address      = "Addres of UowTest";

                IRepository <CustomerBase> dal = FactoryDal <IRepository <CustomerBase> > .Create(cmbDal.Text);

                dal.SetUnitWork(objUow);
                dal.Add(cust1);
                dal.Save();

                CustomerBase cust2 = new CustomerBase();
                cust2.CustomerName = "UowTest22 ";
                cust2.CustomerType = "Lead";
                cust2.BillDate     = DateTime.Now;
                cust2.BillAmount   = 10;
                cust2.Address      = "Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2Addres of UowTest2";

                IRepository <CustomerBase> dal1 = FactoryDal <IRepository <CustomerBase> > .Create(cmbDal.Text);

                dal1.SetUnitWork(objUow);
                dal1.Add(cust2);
                dal1.Save();

                objUow.Commit();
            }
            catch (Exception ex)
            {
                objUow.Rollback();
                MessageBox.Show(ex.Message);
            }
        }
예제 #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            //validate first
            customer.Validate();

            IRepository <CustomerBase> dal = null;

            dal = FactoryCustomer.CreateDAL("CustomerDAL");

            //get customer base instance using factory
            CustomerBase customerBase = new CustomerBase();

            //get customer base instance using factory
            IUow unitOfWork = (IUow)FactoryCustomer.CreateUOW();

            //Map
            customerBase.Address      = customer.Address;
            customerBase.BillAmount   = customer.BillAmount;
            customerBase.BillDate     = customer.BillDate;
            customerBase.Address      = customer.Address;
            customerBase.PhoneNumber  = customer.PhoneNumber;
            customerBase.CustomerName = customer.CustomerName;

            try
            {
                dal.SetUnitOfWork(unitOfWork);
                dal.Add(customerBase);
                //dal.Save(customerBase);
                unitOfWork.Committ();   //use unit-of-work design pattern
                dataGridView1.DataSource = LoadGrid();
            }
            catch
            {
                unitOfWork.Rollback();
            }
        }
예제 #8
0
 public void Rollback()
 {
     _uow.Rollback();
 }
예제 #9
0
 public void Rollback(string message)
 {
     DomainEvent.Raise <DomainNotification>(new DomainNotification("BusinessError", message));
     _uow.Rollback();
 }