public async Task DeleteByIdAsync(int id)
 {
     using (var ctx = new Data.DbContext())
     {
         await ctx.MovieCollection.DeleteByIdAsync(id);
     }
 }
 public async Task EditAsync(Movie movie)
 {
     using (var ctx = new Data.DbContext())
     {
         await ctx.MovieCollection.EditByIdAsync(movie);
     }
 }
 public async Task <IEnumerable <Movie> > GetByCinemaAsync(int cinemaId)
 {
     using (var ctx = new Data.DbContext())
     {
         return(await ctx.MovieCollection.GetMoviesByCinemaId(cinemaId));
     }
 }
 public async Task <Movie> GetByIdAsync(int id)
 {
     using (var ctx = new Data.DbContext())
     {
         return(await ctx.MovieCollection.GetById(id));
     }
 }
 public async Task AddAsync(Movie model)
 {
     using (var ctx = new Data.DbContext())
     {
         await ctx.MovieCollection.Add(model);
     }
 }
示例#6
0
        /// <summary>
        /// Pres the save.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, EntityState state)
        {
            if (state == EntityState.Deleted)
            {
                ChildContentChannels.Clear();
            }

            // clean up the index
            if (state == EntityState.Deleted && IsIndexEnabled)
            {
                this.DeleteIndexedDocumentsByContentChannel(Id);
            }
            else if (state == EntityState.Modified)
            {
                // check if indexing is enabled
                var changeEntry = dbContext.ChangeTracker.Entries <ContentChannel>().Where(a => a.Entity == this).FirstOrDefault();
                if (changeEntry != null)
                {
                    var originalIndexState = (bool)changeEntry.OriginalValues["IsIndexEnabled"];

                    if (originalIndexState == true && IsIndexEnabled == false)
                    {
                        // clear out index items
                        this.DeleteIndexedDocumentsByContentChannel(Id);
                    }
                    else if (IsIndexEnabled == true)
                    {
                        // if indexing is enabled then bulk index - needed as an attribute could have changed from IsIndexed
                        BulkIndexDocumentsByContentChannel(Id);
                    }
                }
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#7
0
        /// <summary>
        /// Posts the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            var rockContext = dbContext as RockContext;

            if (GroupHistoryChanges != null && GroupHistoryChanges.Any())
            {
                HistoryService.SaveChanges(rockContext, typeof(Group), Rock.SystemGuid.Category.HISTORY_GROUP_CHANGES.AsGuid(), GroupId, GroupHistoryChanges, true, this.ModifiedByPersonAliasId);
            }

            // If this is a Group of type Family, update the ModifiedDateTime on the Persons that are members of this family (since one of their Addresses changed)
            int groupTypeIdFamily = GroupTypeCache.GetFamilyGroupType().Id;
            var groupService      = new GroupService(rockContext);

            int groupTypeId = groupService.GetSelect(this.GroupId, s => s.GroupTypeId);

            if (groupTypeId == groupTypeIdFamily)
            {
                var currentDateTime    = RockDateTime.Now;
                var qryPersonsToUpdate = new GroupMemberService(rockContext).Queryable().Where(a => a.GroupId == this.GroupId).Select(a => a.Person);
                rockContext.BulkUpdate(qryPersonsToUpdate, p => new Person {
                    ModifiedDateTime = currentDateTime, ModifiedByPersonAliasId = this.ModifiedByPersonAliasId
                });
            }

            base.PostSaveChanges(dbContext);
        }
示例#8
0
文件: Note.cs 项目: waldo2590/Rock
        /// <summary>
        /// Method that will be called on an entity immediately after the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The entry.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry, EntityState state)
        {
            if (state == EntityState.Added)
            {
                var noteType = NoteTypeCache.Get(this.NoteTypeId);
                if (noteType?.AutoWatchAuthors == true)
                {
                    // if this is a new note, and AutoWatchAuthors, then add a NoteWatch so the author will get notified when there are any replies
                    var rockContext = dbContext as RockContext;
                    if (rockContext != null && this.CreatedByPersonAliasId.HasValue)
                    {
                        var noteWatchService = new NoteWatchService(rockContext);

                        // we don't know the Note.Id yet, so just assign the NoteWatch.Note and EF will populate the NoteWatch.NoteId automatically
                        var noteWatch = new NoteWatch
                        {
                            IsWatching           = true,
                            WatcherPersonAliasId = this.CreatedByPersonAliasId.Value,
                            Note = this
                        };

                        noteWatchService.Add(noteWatch);
                    }
                }
            }

            base.PreSaveChanges(dbContext, entry, state);
        }
示例#9
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="entry"></param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry)
        {
            bool previousDidAttendValue;

            bool previouslyDeclined;

            if (entry.State == EntityState.Added)
            {
                previousDidAttendValue = false;
                previouslyDeclined     = false;
            }
            else
            {
                previousDidAttendValue = entry.Property("DidAttend")?.OriginalValue as bool? ?? false;

                // get original value of RSVP so we can detect whether the value changed
                previouslyDeclined = (entry.Property("RSVP")?.OriginalValue as RSVP? ) == RSVP.No;
            }

            // if the record was changed to Declined, queue a GroupScheduleCancellationTransaction in PostSaveChanges
            _declinedScheduledAttendance = (previouslyDeclined == false) && this.IsScheduledPersonDeclined();

            if (previousDidAttendValue == false && this.DidAttend == true)
            {
                new Rock.Transactions.GroupAttendedTransaction(entry).Enqueue();
            }

#pragma warning disable 612, 618
            ProcessObsoleteOccurrenceFields(entry);
#pragma warning restore 612, 618

            base.PreSaveChanges(dbContext, entry);
        }
示例#10
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="entry"></param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry)
        {
            if (LogoBinaryFileId.HasValue)
            {
                BinaryFileService binaryFileService = new BinaryFileService(( RockContext )dbContext);
                var binaryFile = binaryFileService.Get(LogoBinaryFileId.Value);
                if (binaryFile != null)
                {
                    switch (entry.State)
                    {
                    case EntityState.Added:
                    case EntityState.Modified:
                    {
                        binaryFile.IsTemporary = false;

                        break;
                    }

                    case EntityState.Deleted:
                    {
                        binaryFile.IsTemporary = true;
                        break;
                    }
                    }
                }
            }

            base.PreSaveChanges(dbContext, entry);
        }
示例#11
0
 public async Task <Cinema> GetByIdAsync(int cinemaId)
 {
     using (var ctx = new Data.DbContext())
     {
         return(await ctx.CinemaCollection.GetById(cinemaId));
     }
 }
示例#12
0
 public async Task <IEnumerable <Cinema> > GetCinemasAsync()
 {
     using (var ctx = new Data.DbContext())
     {
         return(await ctx.CinemaCollection.GetAll());
     }
 }
示例#13
0
        /// <summary>
        /// Posts the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            var rockContext = dbContext as RockContext;

            if (this.PostSaveAttributeValueHistoryCurrent)
            {
                var attributeValueHistoricalService            = new AttributeValueHistoricalService(rockContext);
                var attributeValueHistoricalPreviousCurrentRow = attributeValueHistoricalService.Queryable().Where(a => a.AttributeValueId == this.Id && a.CurrentRowIndicator == true).FirstOrDefault();
                var saveChangesDateTime = RockDateTime.Now;

                if (attributeValueHistoricalPreviousCurrentRow != null)
                {
                    attributeValueHistoricalPreviousCurrentRow.CurrentRowIndicator = false;
                    attributeValueHistoricalPreviousCurrentRow.ExpireDateTime      = saveChangesDateTime;
                }

                var attributeValueHistoricalCurrent = AttributeValueHistorical.CreateCurrentRowFromAttributeValue(this, saveChangesDateTime);

                attributeValueHistoricalService.Add(attributeValueHistoricalCurrent);
                rockContext.SaveChanges();
            }

            // If this a Person Attribute, Update the ModifiedDateTime on the Person that this AttributeValue is associated with
            if (this.EntityId.HasValue && AttributeCache.Get(this.AttributeId)?.EntityTypeId == EntityTypeCache.Get <Rock.Model.Person>().Id)
            {
                var currentDateTime    = RockDateTime.Now;
                int personId           = this.EntityId.Value;
                var qryPersonsToUpdate = new PersonService(rockContext).Queryable(true, true).Where(a => a.Id == personId);
                rockContext.BulkUpdate(qryPersonsToUpdate, p => new Person {
                    ModifiedDateTime = currentDateTime, ModifiedByPersonAliasId = this.ModifiedByPersonAliasId
                });
            }

            base.PostSaveChanges(dbContext);
        }
示例#14
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, EntityState state)
        {
            if (state == EntityState.Deleted)
            {
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("PageId", this.Id);

                // since routes have a cascade delete relationship (their presave won't get called), delete routes from route table
                var routes = RouteTable.Routes;
                if (routes != null)
                {
                    foreach (var existingRoute in RouteTable.Routes.OfType <Route>().Where(r => r.PageIds().Contains(this.Id)))
                    {
                        var pageAndRouteIds = existingRoute.DataTokens["PageRoutes"] as List <Rock.Web.PageAndRouteId>;
                        pageAndRouteIds = pageAndRouteIds.Where(p => p.PageId != this.Id).ToList();
                        if (pageAndRouteIds.Any())
                        {
                            existingRoute.DataTokens["PageRoutes"] = pageAndRouteIds;
                        }
                        else
                        {
                            RouteTable.Routes.Remove(existingRoute);
                        }
                    }
                }
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#15
0
        public GlavnaObrada(Data.DbContext dbContext)
        {
            Dnevnik.Pisi("Inicijalizacija glavne obrade");
            // Inicijalizacija liste strana zaglavlja
            procitaneStraneZaglavlja = new Common.Http.ListaStrana(Properties.Settings.Default.BrojStranaZaglavlja);

            // Inicijalizacija liste strana oglasa
            procitaneStraneOglasa = new Common.Http.ListaStrana(Properties.Settings.Default.BrojStranaOglasa);

            // Inicijalizacija brojaca strane zaglavlja
            brojacStraneZaglavlja = new Common.Http.Brojac();

            // BarijeraZaPisce
            barijera = new BarijeraZaPisce(pisacZaglavlja.Length);

            // inicijalizacija pisca zaglavlja
            for (int i = 0; i < pisacZaglavlja.Length; i++)
            {
                pisacZaglavlja[i] = new PisacZaglavlja(ref procitaneStraneZaglavlja, brojacStraneZaglavlja, i, ref barijera);
            }

            // inicijalizacija citaca zaglavlja
            for (int i = 0; i < citacZaglavlja.Length; i++)
            {
                citacZaglavlja[i] = new CitacZaglavlja(ref procitaneStraneZaglavlja, ref procitaneStraneOglasa, i, brojacStraneZaglavlja);
            }

            // inicijalizacija citaca oglasa
            for (int i = 0; i < citacOglasa.Length; i++)
            {
                citacOglasa[i] = new AdReader(dbContext, ref procitaneStraneOglasa, i);
            }

            //EventLogger.WriteEventInfo("Glavna obrada inicijalizovana.");
        }
示例#16
0
 /// <summary>
 /// Updates any Cache Objects that are associated with this entity
 /// </summary>
 /// <param name="entityState">State of the entity.</param>
 /// <param name="dbContext">The database context.</param>
 public void UpdateCache(EntityState entityState, Data.DbContext dbContext)
 {
     if (this.GroupTypeId.HasValue)
     {
         GroupTypeCache.UpdateCachedEntity(this.GroupTypeId.Value, EntityState.Modified);
     }
 }
示例#17
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="entry"></param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry)
        {
            var rockContext = ( RockContext )dbContext;
            BinaryFileService binaryFileService = new BinaryFileService(( RockContext )dbContext);
            var binaryFile = binaryFileService.Get(BinaryFileId);

            if (binaryFile != null)
            {
                switch (entry.State)
                {
                case EntityState.Added:
                case EntityState.Modified:
                {
                    binaryFile.IsTemporary = false;

                    break;
                }

                case EntityState.Deleted:
                {
                    var isAttachmentInUse = new CommunicationAttachmentService(( RockContext )dbContext)
                                            .Queryable()
                                            .Where(a => a.BinaryFileId == this.BinaryFileId)
                                            .Any();
                    if (!isAttachmentInUse)
                    {
                        binaryFile.IsTemporary = true;
                    }
                    break;
                }
                }
            }

            base.PreSaveChanges(dbContext, entry);
        }
示例#18
0
        /// <summary>
        /// Perform tasks prior to saving changes to this entity.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The entry.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry)
        {
            // Add a bus to process denormalized data refreshes
            var processStreakTypeExclusionChangeMsg = GetProcessStreakTypeExclusionChangeMsg(entry);

            processStreakTypeExclusionChangeMsg.Send();
            base.PreSaveChanges(dbContext, entry);
        }
        public FileUploadController(Data.DbContext dbContext, IFileRepository fileRepository,
                                    IFavouriteRepository favouriteRepository)
        {
            _dbContext = dbContext;

            _fileRepository      = fileRepository;
            _favouriteRepository = favouriteRepository;
        }
示例#20
0
        /// <summary>
        /// Posts the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            if (HistoryChanges != null)
            {
                foreach (var historyItem in HistoryChanges)
                {
                    int personId = historyItem.PersonId > 0 ? historyItem.PersonId : PersonId;

                    // if GroupId is 0, it is probably a Group that wasn't saved yet, so get the GroupId from historyItem.Group.Id instead
                    if (historyItem.GroupId == 0)
                    {
                        historyItem.GroupId = historyItem.Group?.Id;
                    }

                    HistoryService.SaveChanges(
                        ( RockContext )dbContext,
                        typeof(Person),
                        Rock.SystemGuid.Category.HISTORY_PERSON_GROUP_MEMBERSHIP.AsGuid(),
                        personId,
                        historyItem.PersonHistoryChangeList,
                        historyItem.Caption,
                        typeof(Group),
                        historyItem.GroupId,
                        true,
                        this.ModifiedByPersonAliasId,
                        dbContext.SourceOfChange);

                    HistoryService.SaveChanges(
                        ( RockContext )dbContext,
                        typeof(GroupMember),
                        Rock.SystemGuid.Category.HISTORY_GROUP_CHANGES.AsGuid(),
                        this.Id,
                        historyItem.GroupMemberHistoryChangeList,
                        historyItem.Caption,
                        typeof(Group),
                        historyItem.GroupId,
                        true,
                        this.ModifiedByPersonAliasId,
                        dbContext.SourceOfChange);
                }
            }

            base.PostSaveChanges(dbContext);

            // if this is a GroupMember record on a Family, ensure that AgeClassification, PrimaryFamily is updated
            // NOTE: This is also done on Person.PostSaveChanges in case Birthdate changes
            var groupTypeFamilyRoleIds = GroupTypeCache.GetFamilyGroupType()?.Roles?.Select(a => a.Id).ToList();

            if (groupTypeFamilyRoleIds?.Any() == true)
            {
                if (groupTypeFamilyRoleIds.Contains(this.GroupRoleId))
                {
                    PersonService.UpdatePersonAgeClassification(this.PersonId, dbContext as RockContext);
                    PersonService.UpdatePrimaryFamily(this.PersonId, dbContext as RockContext);
                    PersonService.UpdateGivingLeaderId(this.PersonId, dbContext as RockContext);
                }
            }
        }
示例#21
0
        /// <summary>
        /// Posts the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            if (HistoryChangeList != null && HistoryChangeList.Any())
            {
                HistoryService.SaveChanges((RockContext)dbContext, typeof(Group), Rock.SystemGuid.Category.HISTORY_GROUP_CHANGES.AsGuid(), this.Id, HistoryChangeList, this.Name, null, null, true, this.ModifiedByPersonAliasId, dbContext.SourceOfChange);
            }

            base.PostSaveChanges(dbContext);
        }
示例#22
0
        /// <summary>
        /// Posts the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            if (GroupHistoryChanges != null && GroupHistoryChanges.Any())
            {
                HistoryService.SaveChanges((RockContext)dbContext, typeof(Group), Rock.SystemGuid.Category.HISTORY_GROUP_CHANGES.AsGuid(), GroupId, GroupHistoryChanges, true, this.ModifiedByPersonAliasId);
            }

            base.PostSaveChanges(dbContext);
        }
示例#23
0
        /// <summary>
        /// Method that will be called on an entity immediately after the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            if (_declinedScheduledAttendance)
            {
                new GroupScheduleCancellationTransaction(this).Enqueue();
            }

            base.PostSaveChanges(dbContext);
        }
示例#24
0
 /// <summary>
 /// Assigns the item global key to the current instance if one does not exist.
 /// </summary>
 /// <param name="dbContext">The database context.</param>
 private void AssignItemGlobalKey(Data.DbContext dbContext)
 {
     if (this.ItemGlobalKey.IsNullOrWhiteSpace())
     {
         var rockContext = ( RockContext )dbContext;
         var contentChannelItemSlugService = new ContentChannelItemSlugService(rockContext);
         this.ItemGlobalKey = contentChannelItemSlugService.GetUniqueContentSlug(this.Title, null);
     }
 }
示例#25
0
        /// <summary>
        /// Method that will be called on an entity immediately after the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            base.PostSaveChanges(dbContext);

            if (_didNameChange)
            {
                new PageRenameTransaction(Guid).Enqueue();
            }
        }
示例#26
0
        /// <summary>
        /// Method that will be called on an entity immediately after the item is saved
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges(Data.DbContext dbContext)
        {
            if (HistoryChangeList?.Any() == true)
            {
                HistoryService.SaveChanges(( RockContext )dbContext, typeof(FinancialScheduledTransaction), Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(), this.ScheduledTransactionId, HistoryChangeList, true, this.ModifiedByPersonAliasId);
            }

            base.PostSaveChanges(dbContext);
        }
示例#27
0
文件: Page.cs 项目: ewin66/rockrms
        /// <summary>
        /// Method that will be called on an entity immediately after the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The entry.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, System.Data.Entity.Infrastructure.DbEntityEntry entry, System.Data.Entity.EntityState state)
        {
            if (state == System.Data.Entity.EntityState.Modified || state == System.Data.Entity.EntityState.Deleted)
            {
                _originalParentPageId = entry.OriginalValues["ParentPageId"]?.ToString().AsIntegerOrNull();
            }

            base.PreSaveChanges(dbContext, entry, state);
        }
示例#28
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The entry.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry, EntityState state)
        {
            if (state == EntityState.Deleted)
            {
                new RegistrationTemplateService(dbContext as RockContext).RelatedEntities.DeleteRelatedEntities(this);
            }

            base.PreSaveChanges(dbContext, entry, state);
        }
示例#29
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, EntityState state)
        {
            if (state == EntityState.Deleted)
            {
                DeleteConnectionRequestWorkflows(dbContext);
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#30
0
        /// <summary>
        /// Posts the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        public override void PostSaveChanges( Data.DbContext dbContext )
        {
            if ( HistoryChanges != null && HistoryChanges.Any() && HistoryPersonId.HasValue )
            {
                HistoryService.SaveChanges( (RockContext)dbContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), HistoryPersonId.Value, HistoryChanges, true, this.ModifiedByPersonAliasId );
            }

            base.PostSaveChanges( dbContext );
        }