예제 #1
0
        private void HandleEvent(Event @event, AuditLogDbContext dbContext)
        {
            switch (@event)
            {
            case ToDoCompletedEvent completedEvent:
                dbContext.ToDoLogs.Add(new ToDoLog()
                {
                    Description = $"User has completed '{completedEvent.Name}' at {completedEvent.CreatedDate.ToShortDateString()}",
                    CreatedDate = completedEvent.CreatedDate
                });
                break;

            case ToDoCreatedEvent createdEvent:
                dbContext.ToDoLogs.Add(new ToDoLog()
                {
                    Description = $"User has created '{createdEvent.Name}' at {createdEvent.CreatedDate.ToShortDateString()}",
                    CreatedDate = createdEvent.CreatedDate
                });
                break;

            case ToDoUncompletedEvent uncompletedEvent:
                dbContext.ToDoLogs.Add(new ToDoLog()
                {
                    Description = $"User has uncompleted '{uncompletedEvent.Name}' at {uncompletedEvent.CreatedDate.ToShortDateString()}",
                    CreatedDate = uncompletedEvent.CreatedDate
                });
                break;
            }

            dbContext.SaveChanges();
        }
예제 #2
0
        public async Task <IActionResult> PutAuditLog([FromRoute] Guid id, [FromRoute] string result)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var registerdAuditLog = await _context.AuditLogs.FindAsync(id);

            registerdAuditLog.CommandResult         = result;
            _context.Entry(registerdAuditLog).State = EntityState.Modified;

            try
            {
                int r = _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuditLogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        private AuditLogDbContext GetContextWithData()
        {
            var options = new DbContextOptionsBuilder <AuditLogDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context   = new AuditLogDbContext(options);
            var auditLog1 = new SmartLock.Services.AuditLogs.API.Model.AuditLog {
                AuditLogId = Guid.NewGuid(),
                UserId     = Guid.NewGuid(), LockId = Guid.NewGuid(), RequestDate = DateTime.Now, Command = "Open"
            };

            context.AuditLogs.Add(auditLog1);

            context.SaveChanges();

            return(context);
        }
예제 #4
0
 public void Insert(SerializedEvent serializedEvent)
 {
     _context.SerializedEvents.Add(serializedEvent);
     _context.SaveChanges();
 }