示例#1
0
        /// <summary>
        /// Сохранить, добавить
        /// </summary>
        /// <param name="LogEvents"></param>
        /// <returns></returns>
        public long SaveLogEvents(LogEvents LogEvents)
        {
            LogEvents dbEntry;

            try
            {
                if (LogEvents.ID == 0)
                {
                    dbEntry = new LogEvents()
                    {
                        ID              = 0,
                        DateTime        = LogEvents.DateTime,
                        UserName        = LogEvents.UserName,
                        UserHostName    = LogEvents.UserHostName,
                        UserHostAddress = LogEvents.UserHostAddress,
                        PhysicalPath    = LogEvents.PhysicalPath,
                        Service         = LogEvents.Service,
                        EventID         = LogEvents.EventID,
                        Event           = LogEvents.Event,
                        Status          = LogEvents.Status
                    };
                    context.LogEvents.Add(dbEntry);
                }
                else
                {
                    dbEntry = context.LogEvents.Find(LogEvents.ID);
                    if (dbEntry != null)
                    {
                        dbEntry.DateTime        = LogEvents.DateTime;
                        dbEntry.UserName        = LogEvents.UserName;
                        dbEntry.UserHostName    = LogEvents.UserHostName;
                        dbEntry.UserHostAddress = LogEvents.UserHostAddress;
                        dbEntry.PhysicalPath    = LogEvents.PhysicalPath;
                        dbEntry.Service         = LogEvents.Service;
                        dbEntry.EventID         = LogEvents.EventID;
                        dbEntry.Event           = LogEvents.Event;
                        dbEntry.Status          = LogEvents.Status;
                    }
                }

                context.SaveChanges();
            }
            catch (Exception e)
            {
                e.SaveErrorMethod(String.Format("SaveLogEvents(LogEvents={0})", LogEvents.GetFieldsAndValue()), blog);
                return(-1);
            }
            return(dbEntry.ID);
        }