Ejemplo n.º 1
0
        public static async Task <bool> AddDescriptionsToDataBaseAsync(DescDBContext dbContext, ICollection <LithologicDescription> descriptions)
        {
            try
            {
                dbContext.AttachRange(descriptions);
                await dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("Error adding descriptions to database context.");
            }
        }
Ejemplo n.º 2
0
        public static async Task <bool> AddMeasurementsToDataBaseAsync(DescDBContext dbContext, ICollection <Measurement> measurements)
        {
            try
            {
                dbContext.AttachRange(measurements);
                await dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Log.Warning(ex.Message);
                throw new Exception("Error adding measurements to database context.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// T
        /// </summary>
        /// <param name="descriptionsToTake">The number of records to create intervals for before the dbContext is disposed</param>
        /// <returns></returns>
        public static async Task <bool> CreateSubIntervalsForDescriptions(int descriptionsToTake)
        {
            //Do this expedition by expedition, after expedition measurements have been uploaded, this would only need to be called once

            try
            {
                using (DescDBContext dbContext = new DescDBContext())
                {
                    var descriptions = dbContext.LithologicDescriptions
                                       .Include(x => x.SectionInfo)
                                       .Include(x => x.LithologicSubintervals)
                                       .ThenInclude(x => x.SectionInfo)
                                       .Include(x => x.LithologicSubintervals)
                                       .ThenInclude(x => x.LithologicDescription)           //The object graph, I want to add subintervals to a description, and add sectioninfo and description references to those subintervals
                                                                                            // .Where(x => x.SectionInfo.Expedition == expedition)
                                       .Where(x => x.LithologicSubintervals.Any() == false) //The description should not have subintervals generated for it yet.
                                                                                            //  .Where (x=>x.SectionInfo.Expedition == expedition)
                                       .Where(x => x.EndOffset > x.StartOffset)             //There are some descriptions that have incorrectly entered start and end offsets
                                       .Take(descriptionsToTake)
                                       .ToHashSet();

                    if (descriptions.Any() == false)
                    {
                        return(false);
                    }

                    foreach (var description in descriptions)
                    {
                        description.GenerateSubintervals();
                    }

                    dbContext.AttachRange(descriptions);   //I can use Attach, but the objects are being tracked presently, SaveChanges should work just fine
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error generating subintervals for descriptions.");
            }

            return(true);
        }