Пример #1
0
        public async Task HandleAsync(string key, UserCreatedEvent @event)
        {
            _dbContext.Customers.Add(new Data.Customer
            {
                Id        = @event.Id,
                Email     = @event.Email,
                FirstName = @event.FirstName,
                LastName  = @event.LastName,
            });

            await _dbContext.SaveChangesAsync();
        }
Пример #2
0
        public async Task <IActionResult> PutNotificationMessage(int id, NotificationMessage notificationMessage)
        {
            notificationMessage.ID = id;

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotificationMessageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task HandleAsync(string key, CustomerUpdatedEvent @event)
        {
            var user = await _dbContext.Customers.FirstOrDefaultAsync(s => s.Email == @event.Email);

            if (user == null)
            {
                throw new ApplicationException("Email is not found.");
            }

            user.FirstName   = @event.FirstName;
            user.LastName    = @event.LastName;
            user.PhoneNumber = @event.PhoneNumber;

            await _dbContext.SaveChangesAsync();
        }