예제 #1
0
        /// <summary>
        /// Method to delete a list of Info entities from the database.
        /// </summary>
        /// <param name="oldItems">The list of items to remove.</param>
        public static void DbDelete(List <InfoEntity> oldItems)
        {
            // Check for Removing items.
            try
            {
                log.Info("Deleting Section(s). Please wait...");

                if (oldItems != null && oldItems.Count > 0)
                {
                    foreach (InfoEntity entity in oldItems)
                    {
                        //MainWindow.Database.Info_Delete(entity.PrimaryKey);

                        throw new NotImplementedException();

                        //Logger.Info(string.Format("Section [{0}:{1}] deleted.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Adding Section(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Deleting Section(s) list failed !");
            }
        }
예제 #2
0
        /// <summary>
        /// Method to update a list of Info entities into the database.
        /// </summary>
        /// <param name="newItems">The list of items to update.</param>
        /// <param name="oldItems"></param>
        public static async void DbUpdateAsync(List <InfoEntity> newItems, List <InfoEntity> oldItems)
        {
            // Check for Replace | Edit items.
            try
            {
                log.Info("Replacing Info. Please wait...");

                if (newItems != null && newItems.Count > 0)
                {
                    foreach (InfoEntity entity in newItems)
                    {
                        //await MainWindow.Database.Infos.UpdateAsync(entity);
                        await Task.Delay(10);

                        throw new NotImplementedException();

                        //Logger.Info(string.Format("Info [{0}:{1}] updated.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Replacing Info(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Replacing Info(s) failed !");
            }
        }
예제 #3
0
        /// <summary>
        /// Method to insert a list of Info entities into the database.
        /// </summary>
        /// <param name="newItems">The list of items to add.</param>
        public static void DbInsert(List <InfoEntity> newItems)
        {
            try
            {
                log.Info("Adding Info(s). Please wait...");

                if (newItems != null && newItems.Count > 0)
                {
                    foreach (InfoEntity entity in newItems)
                    {
                        //entity.Initialize();
                        //MainWindow.Database.Info_Add(entity);

                        throw new NotImplementedException();

                        //Logger.Info(string.Format("Info [{0}:{1}] added.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Adding Info(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Adding Info(s) failed !");
            }
        }
예제 #4
0
        /// <summary>
        /// Method to insert a list of AclGroup entities into the database.
        /// </summary>
        /// <param name="newItems">Thee list of items to add.</param>
        public static void DbInsert(List <AclGroupEntity> newItems)
        {
            log.Info("Adding AclGroup(s). Please wait...");

            try
            {
                if (newItems != null && newItems.Count > 0)
                {
                    foreach (AclGroupEntity entity in newItems)
                    {
                        Db.AclGroups.Add(entity);

                        log.Info($"AclGroup [{entity.PrimaryKey}:{entity.Name}] added.");
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Adding AclGroup(s). Done !");
            }
            catch (Exception e)
            {
                log.Error(e.Output(), e);
                MessageBoxs.Fatal(e, "Adding AclGroup(s) failed !");
            }
        }
예제 #5
0
        /// <summary>
        /// Method called asynchronously on User entities collection changed.
        /// </summary>
        /// <param name="newItems">Thee list of items to add.</param>
        public static void DbInsert(List <UserEntity> newItems)
        {
            MessageBoxs.IsBusy = true;
            log.Info("Adding User(s). Please wait...");

            try
            {
                log.Info("Adding User(s). Please wait...");

                if (newItems != null && newItems.Count > 0)
                {
                    foreach (UserEntity entity in newItems)
                    {
                        Db.Users.Add(entity);

                        log.Info(string.Format("User [{0}:{1}] added.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Adding User(s). Done !");
            }
            catch (Exception e)
            {
                log.Error(e);
                MessageBoxs.Fatal(e, "Adding User(s) failed !");
            }
            finally
            {
                MessageBoxs.IsBusy = false;
            }
        }
예제 #6
0
        /// <summary>
        /// Method to update a list of AclGroup entities into the database.
        /// </summary>
        /// <param name="newItems">Thee list of items to update.</param>
        /// <param name="oldItems"></param>
        public static async void DbUpdateAsync(List <AclGroupEntity> newItems, List <AclGroupEntity> oldItems)
        {
            log.Info("Replacing AclGroup. Please wait...");

            try
            {
                if (newItems != null && newItems.Count > 0)
                {
                    foreach (AclGroupEntity entity in newItems)
                    {
                        await Db.AclGroups.UpdateAsync(entity);

                        if (entity.IsDefault)
                        {
                            Db.AclGroups.SetDefault(entity.PrimaryKey);
                        }

                        log.Info(string.Format("AclGroup [{0}:{1}] updated.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Replacing AclGroup(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Replacing AclGroup(s) failed !");
            }
        }
예제 #7
0
        /// <summary>
        /// Method to update a list of AclAction entities into the database.
        /// </summary>
        /// <param name="newItems">Thee list of items to update.</param>
        /// <param name="oldItems"></param>
        public static void DbUpdate(List <AclActionEntity> newItems, List <AclActionEntity> oldItems)
        {
            log.Info("Replacing AclAction. Please wait...");

            try
            {
                if (newItems != null && newItems.Count > 0)
                {
                    foreach (AclActionEntity entity in newItems)
                    {
                        //await Db.AclActions.Update(entity);

                        MessageBoxs.NotImplemented();

                        log.Info($"AclAction [{entity.PrimaryKey}:{entity.Action}] updated.");
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Replacing AclAction(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                MessageBoxs.Fatal(ex, "Replacing AclAction(s) failed !");
            }
        }
예제 #8
0
        /// <summary>
        /// Method to delete a list of AclGroup entities from the database.
        /// </summary>
        /// <param name="oldItems">The list of items to remove.</param>
        public static void DbDelete(List <AclGroupEntity> oldItems)
        {
            log.Info("Deleting AclGroup(s). Please wait...");

            try
            {
                if (oldItems != null && oldItems.Count > 0)
                {
                    foreach (AclGroupEntity entity in oldItems)
                    {
                        if (!entity.IsDefault)
                        {
                            Db.AclGroups.Delete(entity.PrimaryKey);
                        }

                        log.Info(string.Format("AclGroup [{0}:{1}] deleted.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Deleting AclGroup(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Deleting AclGroup(s) list failed !");
            }
        }
예제 #9
0
        /// <summary>
        /// Method to update a list of Picture entities into the database.
        /// </summary>
        /// <param name="newItems">The list of items to update.</param>
        /// <param name="oldItems"></param>
        public static async void DbUpdateAsync(List <PictureEntity> newItems, List <PictureEntity> oldItems)
        {
            // Check for Replace | Edit items.
            try
            {
                log.Info("Replacing Picture. Please wait...");

                if (newItems != null && newItems.Count > 0)
                {
                    foreach (PictureEntity entity in newItems)
                    {
                        await Db.Pictures.UpdateAsync(entity);

                        log.Info(string.Format("Picture [{0}:{1}] updated.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Replacing Picture(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Replacing Picture(s) failed !");
            }
        }
예제 #10
0
        /// <summary>
        /// Method called asynchronously on User entities collection changed.
        /// </summary>
        /// <param name="oldItems">The list of items to remove.</param>
        public static void DbDelete(List <UserEntity> oldItems)
        {
            log.Info("Deleting User(s). Please wait...");

            try
            {
                log.Info("Deleting User(s). Please wait...");

                if (oldItems != null && oldItems.Count > 0)
                {
                    foreach (UserEntity entity in oldItems)
                    {
                        Db.Users.Delete(entity);

                        log.Info(string.Format("User [{0}:{1}] deleted.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Adding User(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Deleting User(s) list failed !");
            }
        }
예제 #11
0
        /// <summary>
        /// Method to update a list of Section entities into the database.
        /// </summary>
        /// <param name="newItems">Thee list of items to update.</param>
        /// <param name="oldItems"></param>
        public static async void DbUpdateAsync(List <SectionEntity> newItems, List <SectionEntity> oldItems)
        {
            log.Info("Replacing Section. Please wait...");

            try
            {
                if (newItems != null && newItems.Count > 0)
                {
                    foreach (SectionEntity entity in newItems)
                    {
                        FormatAlias(entity);

                        await Db.Sections.UpdateAsync(entity);

                        log.Info(string.Format("Section [{0}:{1}] updated.", entity.PrimaryKey, entity.Name));
                    }
                }

                AppNavigatorBase.Clear();
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Replacing Section(s) failed !");
            }
        }
예제 #12
0
        /// <summary>
        /// Method to update a list of Album entities into the database.
        /// </summary>
        /// <param name="newItems">The list of items to update.</param>
        /// <param name="oldItems">The list of items before changes.</param>
        public static async Task <IList <AlbumEntity> > DbUpdateAsync(IEnumerable <AlbumEntity> newItems, IEnumerable <AlbumEntity> oldItems)
        {
            // Log error if the list to update if not null.
            if (newItems == null)
            {
                log.Error(Exceptions.GetArgumentNull(nameof(newItems), typeof(IEnumerable <AlbumEntity>)).Output());
                return(null);
            }

            // Check if the list to update is not empty.
            if (newItems.Count() == 0)
            {
                log.Debug($"{typeof(AlbumEntityCollection).Name}.{MethodBase.GetCurrentMethod().Name} : the list of {typeof(AlbumEntity).Name} to update is empty.");
                return(null);
            }

            // Create a new list for update return.
            IList <AlbumEntity> itemsUpdated = new List <AlbumEntity>();

            log.Info($"Updating {newItems.Count()} album{(newItems.Count() > 1 ? "s" : "")} : Please wait...");

            try
            {
                foreach (AlbumEntity entity in newItems)
                {
                    // Get all Album to check some properties before inserting new item.
                    // Format Alias before update.
                    FormatAlias(entity);

                    // Update item into the database.
                    itemsUpdated.Add(await Db.Albums.UpdateAsync(entity));
                    log.Info($"Album [{entity.PrimaryKey}:{entity.Name}] updated.");
                }

                // Clear application navigator to refresh it for new data.
                AppNavigatorBase.Clear();
                log.Info($"Updating {itemsUpdated.Count()} album{(itemsUpdated.Count() > 1 ? "s" : "")} : Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, $"Updating {newItems.Count() - itemsUpdated.Count()}/{newItems.Count()} album{(newItems.Count() > 1 ? "s" : "")} : Failed.");
            }

            return(itemsUpdated);
        }
예제 #13
0
        /// <summary>
        /// Method to insert a list of Album entities into the database.
        /// </summary>
        /// <param name="newItems">The list of items to add.</param>
        public static IEnumerable <AlbumEntity> DbInsert(IEnumerable <AlbumEntity> newItems)
        {
            if (newItems == null)
            {
                ArgumentNullException e = Exceptions.GetArgumentNull(nameof(newItems), typeof(IEnumerable <AlbumEntity>));
                log.Error(e.Output());
                return(null);
            }

            // Check if the list to add is not empty.
            if (newItems.Count() == 0)
            {
                log.Debug($"{typeof(AlbumEntityCollection).Name}.{MethodBase.GetCurrentMethod().Name} : the list of {typeof(AlbumEntity).Name} to insert is empty.");
                return(null);
            }

            IList <AlbumEntity> itemsAdded = new List <AlbumEntity>();

            log.Info($"Adding {newItems.Count()} album{(newItems.Count() > 1 ? "s" : "")} : Please wait...");

            try
            {
                foreach (AlbumEntity entity in newItems)
                {
                    // Get all Album to check some properties before inserting new item.
                    // Format Alias before update.
                    FormatAlias(entity);

                    // Add new item into the database.
                    itemsAdded.Add(Db.Albums.Add(entity));
                    log.Info($"Album [{entity.PrimaryKey}:{entity.Name}] added.");
                }

                // Clear application navigator to refresh it for new data.
                AppNavigatorBase.Clear();
                log.Info($"Adding {itemsAdded.Count()} album{(itemsAdded.Count() > 1 ? "s" : "")} : Done.");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);;
                MessageBoxs.Fatal(ex, $"Adding {newItems.Count() - itemsAdded.Count()}/{newItems.Count()} album{(newItems.Count() > 1 ? "s" : "")} : Failed.");
            }

            return(itemsAdded);
        }
예제 #14
0
        /// <summary>
        /// Method to insert a list of Section entities into the database.
        /// </summary>
        /// <param name="newItems">Thee list of items to add.</param>
        public static void DbInsert(List <SectionEntity> newItems)
        {
            log.Info("Adding Section(s) to database. Please wait...");

            try
            {
                // Get all Section to check some properties before inserting new item.
                var items = Db.Sections.List(GetOptionsDefault());

                // Define if it is first item insertion.
                bool firstItem = true;

                // Check if we have new items list to insert.
                if (newItems != null && newItems.Count > 0)
                {
                    int i = 0;
                    foreach (SectionEntity entity in newItems)
                    {
                        // Check it is the first entity to set IsDefault if required.
                        if (items.Count == 0 && firstItem)
                        {
                            entity.IsDefault = true;
                            firstItem        = false;
                        }

                        FormatAlias(entity);

                        // Finally add the entity into the database.
                        Db.Sections.AddAsync(entity);
                        i++;

                        log.Info(string.Format("Section [{0}:{1}] added to database.", entity.PrimaryKey, entity.Name));
                    }
                }

                // Clear navigation cache.
                AppNavigatorBase.Clear();
                log.Info("Adding Section(s) to database. Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Adding Section(s) to database. Fail !");
            }
        }
예제 #15
0
        /// <summary>
        /// Method to delete a list of Album entities from the database.
        /// </summary>
        /// <param name="oldItems">The list of items to remove.</param>
        public static async Task <IList <AlbumEntity> > DbDeleteAsync(IEnumerable <AlbumEntity> oldItems)
        {
            // Log error if the list to update if not null.
            if (oldItems == null)
            {
                ArgumentNullException e = Exceptions.GetArgumentNull(nameof(oldItems), typeof(IEnumerable <AlbumEntity>));
                log.Error(e.Output(), e);
                return(null);
            }

            // Check if the list to update is not empty.
            if (oldItems.Count() == 0)
            {
                log.Debug($"{typeof(AlbumEntityCollection).Name}.{MethodBase.GetCurrentMethod().Name} : the list of {typeof(AlbumEntity).Name} to delete is empty.");
                return(null);
            }

            // Create a new list for update return.
            IList <AlbumEntity> itemsDeleted = new List <AlbumEntity>();

            log.Info($"Deleting {oldItems.Count()} album{(oldItems.Count() > 1 ? "s" : "")} : Please wait...");

            // Check for Removing items.
            try
            {
                foreach (AlbumEntity entity in oldItems)
                {
                    itemsDeleted.Add(await Db.Albums.DeleteAsync(entity));
                    log.Info($"Album [{entity.PrimaryKey}:{entity.Name}] deleted.");
                }

                // Clear application navigator to refresh it for new data.
                AppNavigatorBase.Clear();
                log.Info($"Deleting {itemsDeleted.Count()} album{(itemsDeleted.Count() > 1 ? "s" : "")} : Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, $"Deleting {oldItems.Count() - itemsDeleted.Count()}/{oldItems.Count()} album{(oldItems.Count() > 1 ? "s" : "")} : Failed.");
            }

            return(itemsDeleted);
        }
예제 #16
0
        /// <summary>
        /// Method to update a list of Section entities into the database.
        /// </summary>
        /// <param name="newItem"></param>
        public static void SetDefault(SectionEntity newItem)
        {
            log.Info("Setting default Section. Please wait...");

            try
            {
                if (newItem != null)
                {
                    Db.Sections.SetDefaultAsync(newItem.PrimaryKey);
                }

                AppNavigatorBase.Clear();
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Setting default Section. Failed !");
            }
        }
예제 #17
0
        /// <summary>
        /// Method to update a list of AclGroup entities into the database.
        /// </summary>
        /// <param name="newItem"></param>
        public static void SetDefault(AclGroupEntity newItem)
        {
            log.Info("Setting default User Group. Please wait...");

            try
            {
                if (newItem != null)
                {
                    Db.AclGroups.SetDefault(newItem.PrimaryKey);
                }

                AppNavigatorBase.Clear();
                log.Info("Setting default User Group. Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Setting default User Group failed !");
            }
        }
예제 #18
0
        /// <summary>
        /// Method to delete a list of AclAction entities from the database.
        /// </summary>
        /// <param name="oldItems">The list of items to remove.</param>
        public static void DbDelete(List <AclActionEntity> oldItems)
        {
            log.Info("Deleting AclAction(s). Please wait...");

            try
            {
                if (oldItems != null && oldItems.Count > 0)
                {
                    foreach (AclActionEntity entity in oldItems)
                    {
                        Db.AclActions.Delete(entity.PrimaryKey);
                        log.Info($"AclAction [{entity.PrimaryKey}:{entity.Action}] deleted.");
                    }
                }

                AppNavigatorBase.Clear();
                log.Info("Deleting AclAction(s). Done !");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                MessageBoxs.Fatal(ex, "Deleting AclAction(s) list failed !");
            }
        }
예제 #19
0
        /// <summary>
        /// Method to insert a list of Picture entities into the database.
        /// </summary>
        /// <param name="newItems">The list of items to add.</param>
        /// <param name="albums">The list of Albums, past on reference, to associate the items and update their informations.</param>
        /// <returns>The list of new items inserted in the database.</returns>
        public static IList <PictureEntity> DbInsert(IEnumerable <PictureEntity> newItems, ref IEnumerable <AlbumEntity> albums)
        {
            log.Debug($"{typeof(PictureEntityCollection).Name}.{MethodBase.GetCurrentMethod().Name} 3 : {newItems?.Count()} newItems to insert into database.");

            if (newItems == null)
            {
                log.Error(Exceptions.GetArgumentNull(nameof(newItems), typeof(IEnumerable <PictureEntity>)).Output());
                return(null);
            }

            if (newItems.Count() == 0)
            {
                log.Debug($"{typeof(AlbumEntityCollection).Name}.{MethodBase.GetCurrentMethod().Name} : the list of {typeof(IEnumerable<PictureEntity>).Name} to insert is empty.");
                return(null);
            }

            if (albums == null)
            {
                log.Error(Exceptions.GetArgumentNull(nameof(albums), typeof(IEnumerable <AlbumEntity>)).Output());
                return(null);
            }

            // Create new Picture list to return.
            IList <PictureEntity> itemsAdded = new List <PictureEntity>();

            try
            {
                log.Debug("----------------------------------------------------------------------------------------------------------");
                log.Info($"Adding {newItems.Count()} picture{(newItems.Count() > 1 ? "s" : "")} : Please wait...");

                foreach (PictureEntity entity in newItems)
                {
                    if (entity == null)
                    {
                        log.Error($"{typeof(PictureEntityCollection).Name}.{MethodBase.GetCurrentMethod().Name} : Picture null can't be inserted in database.");
                        continue;
                    }

                    // Process association to each AlbumEntity.
                    if (albums != null && albums.Count() > 0)
                    {
                        foreach (AlbumEntity a in albums)
                        {
                            if (a == null)
                            {
                                log.Error(new NullReferenceException($"Album null can't be associated to a Picture.").Output());
                                continue;
                            }

                            // Try to find Picture and Album dependency
                            PicturesInAlbums dependency = (new List <PicturesInAlbums>(entity.PicturesInAlbums)).Find(x => x.AlbumId == a.AlbumId);

                            // Associate Picture to the Album if not already set.
                            if (dependency == null)
                            {
                                entity.PicturesInAlbums.Add(
                                    new PicturesInAlbums
                                {
                                    AlbumId  = a.AlbumId,
                                    Ordering = entity.PicturesInAlbums.Count + 1
                                }
                                    );

                                log.Info($"Picture [{entity.PrimaryKey}:{entity.Name}] associated to Album [{a.PrimaryKey}:{a.Name}].");
                            }
                        }
                    }

                    // Add picture strored in database to the return list.
                    var pictAdded = Db.Pictures.Add(entity);
                    itemsAdded.Add(pictAdded);

                    foreach (AlbumEntity a in albums)
                    {
                        if (a == null)
                        {
                            log.Error(new NullReferenceException($"Picture null can't be associated to a Album.").Output());
                            continue;
                        }

                        a.LinkPicture(pictAdded.PrimaryKey, false);

                        log.Info($"Album [{a.PrimaryKey}:{a.Name}] associated to Picture [{entity.PrimaryKey}:{entity.Name}].");
                    }

                    log.Info($"Picture [{entity.PrimaryKey}:{entity.Name}] added to database.");
                }

                AppNavigatorBase.Clear();
                log.Debug("Application navigator cleared.");
                log.Info($"Adding {itemsAdded?.Count() ?? 0} picture{(itemsAdded?.Count() > 1 ? "s" : "")} : Done.");
            }

            catch (Exception ex)
            {
                log.Error(ex.Output(), ex);
                MessageBoxs.Fatal(ex, $"Adding {newItems.Count()}/{newItems.Count()} picture{(newItems.Count() > 1 ? "s" : "")} : Failed.");
            }

            log.Debug("----------------------------------------------------------------------------------------------------------");
            return(itemsAdded);
        }