Ejemplo n.º 1
0
        public Result <object> AddEventLog(EventLogDataContract eventLog)
        {
            var result = new Result <object>();

            try
            {
                if (eventLog == null)
                {
                    throw new Exception("Новая запись лога не задана");
                }

                using (var ctx = new PolicyProjectEntities())
                {
                    eventLog.EventLogId = ctx.tbl_activity_log.Any() ? ctx.tbl_activity_log.Max(x => x.id) + 1 : 1;
                    var newEventLog = EventLogDataContract.FromEventLogDataContractToTblEventLog(eventLog);
                    newEventLog.log_date = DateTime.Now;
                    ctx.tbl_activity_log.Add(newEventLog);
                    result.BoolRes = ctx.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка добавления записи лога. ", ex.Message);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public Result <EventLogDataContract[]> GetEventLog(EventLogDataContract eventLogFilter)
        {
            var result = new Result <EventLogDataContract[]>();

            try
            {
                using (var ctx = new PolicyProjectEntities())
                {
                    if (eventLogFilter == null)
                    {
                        result.SomeResult =
                            ctx.tbl_activity_log.Select(
                                eventLogTblData => new EventLogDataContract
                        {
                            EventLogId   = eventLogTblData.id,
                            EventLogDate = eventLogTblData.log_date,
                            EventId      = eventLogTblData.id_event,
                            Login        = eventLogTblData.login,
                            Device       = eventLogTblData.device,
                            DocumentId   = eventLogTblData.id_document,
                            Message      = eventLogTblData.message,
                            EventName    =
                                ctx.tbl_event.FirstOrDefault(x => x.id == eventLogTblData.id_event).event_name
                        }).ToArray();
                    }
                    else
                    {
                        result.SomeResult = ctx.tbl_activity_log.Where(x => x.id == eventLogFilter.EventLogId)
                                            .Select(eventLogTblData => new EventLogDataContract
                        {
                            EventLogId   = eventLogTblData.id,
                            EventLogDate = eventLogTblData.log_date,
                            EventId      = eventLogTblData.id_event,
                            Login        = eventLogTblData.login,
                            Device       = eventLogTblData.device,
                            DocumentId   = eventLogTblData.id_document,
                            Message      = eventLogTblData.message,
                            EventName    =
                                ctx.tbl_event.FirstOrDefault(x => x.id == eventLogTblData.id_event).event_name
                        })
                                            .ToArray();
                    }

                    result.BoolRes = true;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка получения лога событий. ", ex.Message);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static tbl_activity_log FromEventLogDataContractToTblEventLog(EventLogDataContract eventLogData)
        {
            if (eventLogData.EventLogId < 1 || eventLogData.EventId < 1 ||
                string.IsNullOrEmpty(eventLogData.Device.Trim()) || string.IsNullOrEmpty(eventLogData.Login.Trim()))
            {
                return(null);
            }

            return(new tbl_activity_log
            {
                id = eventLogData.EventLogId,
                log_date = eventLogData.EventLogDate,
                id_event = eventLogData.EventId,
                device = eventLogData.Device.Trim(),
                login = eventLogData.Login.Trim(),
                id_document = eventLogData.DocumentId,
                message = eventLogData.Message
            });
        }
Ejemplo n.º 4
0
        public static bool Compare(EventLogDataContract obj1, EventLogDataContract obj2)
        {
            if (obj1 == null && obj2 == null)
            {
                return(true);
            }

            if (obj1 == null && obj2 != null)
            {
                return(false);
            }

            if (obj1 != null && obj2 == null)
            {
                return(false);
            }

            return(obj1.EventLogId == obj2.EventLogId && obj1.EventLogDate == obj2.EventLogDate &&
                   string.Equals(obj1.Device, obj2.Device, StringComparison.InvariantCultureIgnoreCase) &&
                   string.Equals(obj1.Login, obj2.Login, StringComparison.InvariantCultureIgnoreCase) &&
                   obj1.EventId == obj2.EventId && obj1.DocumentId == obj2.DocumentId);
        }
Ejemplo n.º 5
0
        public Result <object> AddEventLogExplicit(string device, string login, int eventId, long documentId,
                                                   string message)
        {
            var result = new Result <object>();

            try
            {
                if (string.IsNullOrEmpty(device.Trim()) || string.IsNullOrEmpty(login.Trim()) || eventId < 1)
                {
                    throw new Exception("Новая запись лога не задана");
                }

                using (var ctx = new PolicyProjectEntities())
                {
                    var eventLog = new EventLogDataContract
                    {
                        EventLogId = ctx.tbl_activity_log.Any() ? ctx.tbl_activity_log.Max(x => x.id) + 1 : 1,
                        EventId    = eventId,
                        DocumentId = documentId,
                        Message    = message,
                        Login      = login,
                        Device     = device
                    };
                    var newEventLog = EventLogDataContract.FromEventLogDataContractToTblEventLog(eventLog);
                    newEventLog.log_date = DateTime.Now;
                    ctx.tbl_activity_log.Add(newEventLog);
                    result.BoolRes = ctx.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка добавления записи лога. ", ex.Message);
            }

            return(result);
        }
Ejemplo n.º 6
0
        public string GetEventLogRest(EventLogDataContract eventLogFilter)
        {
            var queryResult = GetEventLog(eventLogFilter);

            return(JsonConvert.SerializeObject(queryResult));
        }