Beispiel #1
0
        public ActionResult <Event> CreateEvent([FromBody] Event model)
        {
            if (model.Id > 0)
            {
                return(BadRequest());
            }
            var entity = new DataAccess.Models.Event();

            _mapper.Map(model, entity);
            _context.Add(entity);
            _context.SaveChanges();
            model = _mapper.Map <Event>(entity);
            return(CreatedAtAction(nameof(GetEvent), new { id = model.Id }, model));
        }
Beispiel #2
0
        public void OnItemSaved(object sender, EventArgs args)
        {
            bool isItemSavedEventArgs = args is SitecoreEventArgs;

            if (!isItemSavedEventArgs)
            {
                return;
            }

            var  saveEventArgs = args as SitecoreEventArgs;
            var  itemChanges   = (ItemChanges)saveEventArgs.Parameters[saveEventArgs.Parameters.Length - 1];
            bool isSaveEventInvokedByPublish = itemChanges.HasPropertiesChanged;

            if (isSaveEventInvokedByPublish)
            {
                return;
            }
            try
            {
                var saveDetailsEntity = new SaveDetail()
                {
                    Language = itemChanges.Item.Language.Name,
                    Changes  = Settings.TraceChanges ? GetFieldChanges(itemChanges) : "[not-tracked]"
                };

                var _saveDetails = _saveDetailsRepository.AddSaveDetailItem(saveDetailsEntity);

                var eventEntity = new DataAccess.Models.Event()
                {
                    ItemId         = itemChanges.Item.ID.ToGuid(),
                    Date           = DateTime.ParseExact(itemChanges.FieldChanges[_updatedFieldId].Value, "yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture), // TODO
                    EventType      = EventType.Save,
                    ItemPath       = itemChanges.Item.Paths?.FullPath,
                    ItemVersion    = itemChanges.Item.Version.Number,
                    SourceDatabase = itemChanges.Item.Database.Name,
                    UserName       = itemChanges.FieldChanges[_updatedByFieldId].Value,
                    SaveDetailId   = _saveDetails.Id
                };

                _eventRepository.AddEventItem(eventEntity);
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("EventLog SaveEventHandler threw an exception", ex);
            }
        }
Beispiel #3
0
        public void OnItemDeleted(object sender, EventArgs args)
        {
            bool isItemDeletedArgs = args is SitecoreEventArgs;

            if (!isItemDeletedArgs)
            {
                return;
            }
            try
            {
                var  deleteEventArgs = args as SitecoreEventArgs;
                var  item            = (Item)deleteEventArgs.Parameters.First();
                ID   parentId        = null;
                Item parentItem      = null;
                if (deleteEventArgs.Parameters.Count() > 1)
                {
                    parentId   = (ID)deleteEventArgs.Parameters[1];
                    parentItem = Database.GetDatabase("master").GetItem(parentId);
                }

                var @event = new DataAccess.Models.Event()
                {
                    ItemId         = item.ID.ToGuid(),
                    ItemPath       = (parentItem != null) ? string.Format("{0}{1}", parentItem.Paths.FullPath, item.Paths.Path) : item.Paths.Path,
                    ItemVersion    = item.Version?.Number,
                    SourceDatabase = item.Database.Name,
                    EventType      = EventType.Delete,
                    Date           = DateTime.Now.ToLocalTime(),
                    UserName       = Sitecore.Context.User?.Name
                };

                _eventRepository.AddEventItem(@event);
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("EventLog DeleteEvenhandler threw an exception", ex);
            }
        }