コード例 #1
0
        public void Insert(User user)
        {
            using var transaction = _context.Database.BeginTransaction();
            try
            {
                var hashedPassword = ToMd5(user.Password);
                var userToInsert   = new User(user.Name, user.Login, hashedPassword, user.UserRoles);

                _context.Entry(userToInsert).State = EntityState.Added;

                _context.UserRoles.AddRange(userToInsert.UserRoles);

                _context.SaveChanges();

                transaction.Commit();
            }
            catch (SqlException ex)
            {
                transaction.Rollback();
                if (ex.Number > 50000)
                {
                    throw new InvalidUserException(ex.Message);
                }
                throw ex;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
コード例 #2
0
        public void EnviarParaGerencia(int clientId, int userId)
        {
            using var transaction = _context.Database.BeginTransaction();
            try
            {
                var clientFromDb = _clientRepository.GetById(clientId);

                clientFromDb.SetCurrentStatus(EStatus.AGUARDANDO_GERENCIA);

                _context.Entry(clientFromDb).State = EntityState.Modified;

                var fluxo = new Fluxo(clientId, userId, clientFromDb.CurrentStatusId);

                _context.Entry(fluxo).State = EntityState.Added;

                _context.SaveChanges();

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
コード例 #3
0
        public void Update(Client client)
        {
            using var transaction = _context.Database.BeginTransaction();
            try
            {
                EditPhones(client, client.Phones.ToList());

                _context.Entry(client).State        = EntityState.Modified;
                _context.Entry(client.Adress).State = EntityState.Modified;

                _context.SaveChanges();
                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }