Пример #1
0
        public IHttpActionResult Post([FromBody] CreateAuditEventModel command)
        {
            if (command == null || !ModelState.IsValid)
            {
                return(this.Error().InvalidParameters("Audit event body parameters missing"));
            }

            List <AuditEventValueType> valueTypes = new AuditEventValueTypeRepository().GetAll();

            var auditEvent = new AuditEvent()
            {
                ID          = Guid.NewGuid().ToString(),
                TimeCreated = (command.TimeCreated == null ? DateTime.UtcNow : (DateTime)command.TimeCreated),
                EventTypeID = command.EventTypeID,
                TenantID    = 0,
                UserID      = 0,
            };

            command.Values.ForEach(item => auditEvent.Values.Add(new AuditEventValue()
            {
                TypeID = item.TypeID, Value = AuditEventValue.ConvertValue(item.TypeID, item.Value, valueTypes.Find(vt => vt.ID == item.TypeID))
            }));

            _auditEventRepository.Insert(auditEvent);

            return(Ok());
        }
Пример #2
0
        public List <AuditEventModel> PostGet([FromBody] AuditEventFilterModel command)
        {
            AuditEventFilter auditEventFilter = _mapper.Map <AuditEventFilter>(command);

            // Convert values
            List <AuditEventValueType> valueTypes = new AuditEventValueTypeRepository().GetAll();

            foreach (AuditEventValueFilter valueFilter in auditEventFilter.ValueFilters)
            {
                valueFilter.Value = AuditEventValue.ConvertValue(valueFilter.ValueTypeID, valueFilter.Value, valueTypes.Find(vt => vt.ID == valueFilter.ValueTypeID));
            }

            // Get audit events
            var auditEvents = _auditEventRepository.Get(auditEventFilter);

            return(_mapper.Map <List <AuditEventModel> >(auditEvents));
        }