示例#1
0
        /// <summary>
        /// Updates an existing entity
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public virtual T Update(T item)
        {
            // Tracking
            item = Track(item, true);

            context.Entry(item).State = EntityState.Modified;
            context.SaveChanges();

            using (AuditLogService service = new AuditLogService())
            {
                service.Create(ActivityTypes.Edit, item, OldObject);
            }

            return(item);
        }
示例#2
0
        /// <summary>
        /// Deletes an existing entity
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public virtual bool Delete(T item)
        {
            if (!context.ChangeTracker.Entries <T>().Any(e => e.Entity == item))
            {
                context.Set <T>().Attach(item);
            }

            context.Set <T>().Remove(item);
            context.SaveChanges();

            using (AuditLogService service = new AuditLogService())
            {
                service.Create(ActivityTypes.Delete, item, OldObject);
            }

            return(true);
        }
示例#3
0
        /// <summary>
        /// Creates a new entity
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public virtual T Create(T item, bool track = true)
        {
            // Tracking
            if (track)
            {
                item = Track(item);
            }

            context.Set <T>().Add(item);

            context.SaveChanges();

            using (AuditLogService service = new AuditLogService())
            {
                service.Create(ActivityTypes.Create, item);
            }

            return(item);
        }