public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (Membership.ValidateUser(model.UserName, model.Password))
            {
                var context = new ACDBContext();
                var user    = context.Users.FirstOrDefault(x => x.UserName == model.UserName);
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    return(RedirectToAction("Index", "Searches"));
                }
                ModelState.AddModelError("", "You are not authorized. Contact Administrator");
            }
            else
            {
                ModelState.AddModelError("", "Invalid username or password.");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #2
0
        static void Main(string[] args)
        {
            using (var db = new ACDBContext())
            {
                //lEFTjOIN
                var LeftJoin = from x in db.Packages
                               join y in db.Customers on x.PackId equals y.PackId into ys
                               from y in db.Customers.DefaultIfEmpty()
                               select new { Category = x.PackId, SubCategory = y.FirstName };

                foreach (var j in LeftJoin)
                {
                    //Console.WriteLine($"{j.Category}, {j.SubCategory}");
                }

                //cross join

                var CrossJoin =
                    from x in db.Packages
                    from y in db.Customers
                    select new { var1 = x.PackId, var2 = y.FirstName };

                foreach (var c in CrossJoin)
                {
                    Console.WriteLine($"{c.var1}, {c.var2}");
                }
            }

            Console.ReadKey();
        }
        private static void PersonAddresses(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.AddressPersonRels.Count();
            var entityName = "Person-Address";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.AddressPersonRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var person = context.Persons.Include("PersonAddresses").FirstOrDefault(x => x.Id == item.CommonPerson.Id);
                    if (person == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    //todo: verify query
                    if (person.PersonAddresses.Any(
                        x => x.Street == item.Address.Address1?.Trim() &&
                             x.City == item.Address.City?.Trim() &&
                             x.StateId == item.Address.StateId &&
                             x.PrimaryStatus == (PrimaryStatus)item.PrimaryStatusId))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {person.ReverseFullName}-{item.Address.Address1} already exists");
                        continue;
                    }
                    person.PersonAddresses.Add(new PersonAddress()
                    {
                        Street = item.Address.Address1?.Trim(),
                        Street2 = item.Address.Address2?.Trim(),
                        City = item.Address.City?.Trim(),
                        County = item.Address.County?.Trim(),
                        StateId = item.Address.StateId,
                        ZipCode = $"{item.Address.Zip5?.Trim()}-{item.Address.Zip4?.Trim()}",
                        Country = item.Address.Country?.Trim(),
                        Latitude = item.Address.Latitude,
                        Longitude = item.Address.Longitude,
                        PrimaryStatus = (PrimaryStatus)item.PrimaryStatusId,
                        DateCreated = item.DateCreated,
                        DateUpdated = item.DateModified
                    });
                    person.LogEntries.Add(new PersonLogEntry() { Note = $"Added Address {item.Address.Address1}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {person.ReverseFullName}-{item.Address.Address1}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
            }
        }
        public static void LoadChapters(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.Chapters.Count();
            var entityName = "Chapter";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Chapters ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.Chapters.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.Chapters.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Name} already exists");
                            continue;
                        }
                        var newItem = new Domain.Models.Chapter()
                        {
                            Id = item.Id,
                            Name = item.ChapterName?.Trim(),
                            SecurityLevel =
                                item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                            Description = item.ChapterDesc?.Trim(),
                            DateFormed = item.FormedDate,
                            DateDisbanded = item.DisbandDate,
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            IsHeadquarters = item.IsHeadquarters,
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified
                        };
                        newItem.LogEntries.Add(new ChapterLogEntry() { Note = $"Added {entityName} {newItem.Name}" });
                        context.Chapters.Add(newItem);
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Name}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Chapters OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
 static OrganizationService()
 {
     using (var context = new AppContext())
     {
         m2 = context.Movements.ToList();
     }
     using (var db = new ACDBContext())
     {
         m1 = db.MovementClasses.ToList();
     }
 }
Example #6
0
 static Helpers()
 {
     using (var context = new AppContext())
     {
         m2 = context.Movements.ToList();
     }
     using (var db = new ACDBContext())
     {
         m1 = db.MovementClasses.ToList();
     }
 }
        private static void OrganizationAliases(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.AliasOrganizationRels.Count();
            var entityName = "Organziation-Alias";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.AliasOrganizationRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var org = context.Organizations.Include(x => x.OrganizationAliases).FirstOrDefault(x => x.Id == item.OrganizationId);
                    if (org == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (org.OrganizationAliases.Any(
                        x => x.Name == item.Alias.AliasName && x.PrimaryStatus == (PrimaryStatus)item.PrimaryStatusId))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {org.Name}-{item.Alias.AliasName} already exists");
                        continue;
                    };
                    org.OrganizationAliases.Add(new OrganizationAlias()
                    {
                        Name = item.Alias.AliasName,
                        PrimaryStatus = (PrimaryStatus)item.PrimaryStatusId,
                        DateCreated = item.DateCreated,
                        DateUpdated = item.DateModified
                    });
                    org.LogEntries.Add(new OrganizationLogEntry() { Note = $"Added Alias {item.Alias.AliasName}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {org.Name}-{item.Alias.AliasName}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        private static void OrganizationActivities(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.OrganizationStatusHistories.Count();
            var entityName = "Organziation-Activity";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.OrganizationStatusHistories.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var org = context.Organizations.Include(x => x.OrganizationActivity).FirstOrDefault(x => x.Id == item.OrganizationId);

                    if (org == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }

                    if (org.OrganizationActivity.Any(x => x.ActiveYear == item.ActiveYear))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {org.Name}-{item.ActiveYear} already exists");
                        continue;
                    }

                    org.OrganizationActivity.Add(new OrganizationActivity()
                    {
                        ActiveYear = item.ActiveYear,
                    });
                    org.LogEntries.Add(new OrganizationLogEntry() { Note = $"Added Activity Year {item.ActiveYear}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {org.Name}-{item.ActiveYear}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        private static void PublicationCorrespondences(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.MediaPublishedMediaCorrespondenceRels.Count();
            var entityName = "Publication-Correspondence";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.MediaPublishedMediaCorrespondenceRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var e = context.Correspondences.Find(item.MediaCorrespondenceId);
                    var pub =
                        context.Publications.Include(x => x.Correspondence).FirstOrDefault(x => x.Id == item.MediaPublishedId);
                    if (e == null || pub == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    //todo: change to correspondences
                    if (pub.Correspondence.Any(x => x.Id == e.Id))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {pub.Name}-{e.Name} already exists");
                        continue;
                    }
                    pub.Correspondence.Add(e);
                    pub.LogEntries.Add(new PublicationLogEntry() { Note = $"Added Correspondence {e.Name}" });
                    e.LogEntries.Add(new CorrespondenceLogEntry() { Note = $"Added Publication {pub.Name}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {pub.Name}-{e.Name}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
Example #10
0
        public EventsController(
            ILookupRepository lookupRepo,
            IEventRepository eventRepo,
            ACDBContext ctx)
        {
            _lookupRepo = lookupRepo;
            _eventRepo  = eventRepo;
            _ctx        = ctx;

            ViewBag.PossibleEventDocumentationTypes = _lookupRepo.GetEventDocumentationTypes();
            ViewBag.PossibleEventTypes       = _lookupRepo.GetEventTypes();
            ViewBag.PossibleWebIncidentTypes = _lookupRepo.GetWebIncidentTypes();
            ViewBag.PossibleApprovalStatus   = _lookupRepo.GetApprovalStatuses();
            ViewBag.PossibleActiveStatus     = _lookupRepo.GetActiveStatuses();
            ViewBag.PossibleMovementClasses  = _lookupRepo.GetMovementClasses();
            ViewBag.PossibleRemovalStatus    = _lookupRepo.GetRemovalStatus();
            ViewBag.PossiblePrimaryStatus    = _lookupRepo.GetPrimaryStatuses();
            ViewBag.PossibleNewsSources      = _lookupRepo.GetNewsSources();
            ViewBag.PossibleReligions        = _lookupRepo.GetReligions();
        }
        private static void WebsitePublications(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.MediaPublishedMediaWebsiteEGroupRels.Count();
            var entityName = "Website-Publication";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.MediaPublishedMediaWebsiteEGroupRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var e = context.Publications.Find(item.MediaPublishedId);
                    var website = context.Websites.Include("Publications").FirstOrDefault(x => x.Id == item.MediaWebsiteEGroupId);
                    if (e == null || website == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (website.Publications.Any(x => x.Id == e.Id))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {website.Name}-{e.Name} already exists");
                        continue;
                    }
                    website.Publications.Add(e);
                    website.LogEntries.Add(new WebsiteLogEntry() { Note = $"Added Publication {e.Name}" });
                    e.LogEntries.Add(new PublicationLogEntry() { Note = $"Added Website {website.Name}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {website.Name}-{e.Name}");
                    savedCount++;
                    context.SaveChanges();
                }

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
Example #12
0
 public LookupRepository(ACDBContext ctx)
 {
     _ctx = ctx;
 }
        private static void EventAudioVideos(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.EventMediaAudioVideoRels.Count();
            var entityName = "Event-AudioVideo";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.EventMediaAudioVideoRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var e = context.AudioVideos.Find(item.MediaAudioVideoId);
                    var @event = context.Events.Include("AudioVideos").FirstOrDefault(x => x.Id == item.EventId);
                    if (e == null || @event == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (@event.AudioVideos.Any(x => x.Id == e.Id))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {@event.Name}-{e.Title} already exists");
                        continue;
                    }
                    @event.AudioVideos.Add(e);
                    @event.LogEntries.Add(new EventLogEntry() { Note = $"Added Audio Video {e.Title}" });
                    e.LogEntries.Add(new AudioVideoLogEntry() { Note = $"Added Event {@event.Name}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {@event.Name}-{e.Title}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
            }
        }
        private static void OrganizationChapters(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.ChapterOrganizationRels.Count();
            var entityName = "Chapter-Organziation";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.ChapterOrganizationRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var chapter = context.Chapters.Find(item.ChapterId);
                    var org = context.Organizations.Find(item.OrganizationId);
                    if (chapter == null || org == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (chapter.Organization != null)
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {chapter.Name}-{org.Name} already exists");
                        continue;
                    }
                    chapter.Organization = org;
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {chapter.Name}-{org.Name}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
Example #15
0
 public EventCommentRepository(ACDBContext ctx)
 {
     context = ctx;
 }
        public static void LoadPeople(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.BeholderPersons.Count();
            var entityName = "Person";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Persons ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.BeholderPersons.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0).Include("CommonPerson"))
                    {
                        count++;
                        var i = context.Persons.Find(item.CommonPersonId);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.FullName} already exists");
                            continue;
                        }

                        Gender gender;
                        Enum.TryParse(item.CommonPerson.GenderId.ToString(), out gender);
                        MaritialStatus maritialStatus;
                        Enum.TryParse(item.CommonPerson.MaritialStatusId.ToString(), out maritialStatus);
                        var newItem = new Person()
                        {
                            Id = item.CommonPersonId,
                            PrefixId = item.CommonPerson.PrefixId,
                            SuffixId = item.CommonPerson.SuffixId,
                            FirstName = item.CommonPerson.FName?.Trim(),
                            MiddleName = item.CommonPerson.MName?.Trim(),
                            LastName = item.CommonPerson.LName?.Trim(),
                            DOB = item.CommonPerson.DOB,
                            ActualDOB = item.CommonPerson.ActualDOBIndicator,
                            DeceasedDate = item.CommonPerson.DeceasedDate,
                            ActualDeceasedDate = item.CommonPerson.ActualDeceasedDateIndicator,
                            Height = item.CommonPerson.Height,
                            Weight = item.CommonPerson.Weight,
                            SSN = item.CommonPerson.SSN,
                            LicenseType = Helpers.GetLicenseType(item.CommonPerson.LicenseTypeId),
                            DriversLicenseNumber = item.CommonPerson.DriversLicenseNumber,
                            DriversLicenseStateId = item.CommonPerson.DriversLicenseStateId,
                            MaritialStatus = maritialStatus,
                            Gender = gender,
                            HairColorId = item.CommonPerson.HairColorId,
                            HairPatternId = item.CommonPerson.HairPatternId,
                            EyeColorId = item.CommonPerson.EyeColorId,
                            RaceId = item.CommonPerson.RaceId,
                            SecurityLevel =
                                item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                            DistinguishableMarks = item.DistinguishableMarks?.Trim(),
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            DateCreated = item.CommonPerson.DateCreated,
                            DateUpdated = item.CommonPerson.DateModified,
                        };
                        newItem.LogEntries.Add(new PersonLogEntry() { Note = $"Added {entityName} {newItem.ReverseFullName}" });
                        context.Persons.Add(newItem);
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.FullName}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Persons OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
 public OrganizationRepository(ACDBContext ctx)
 {
     _ctx = ctx;
 }
Example #18
0
 public SearchRepository(ACDBContext Context)
 {
     context = Context;
 }
        public static void LoadSubscriptions(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.Subscriptions.Count();
            var entityName = "Subscription";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Subscriptions ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.Subscriptions.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.Subscriptions.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Name} already exists");
                            continue;
                        }

                        var newItem = new Domain.Models.Subscription()
                        {
                            Id = item.Id,
                            Name = item.PublicationName?.Trim(),
                            Rate = item.SubscriptionRate?.Trim(),
                            RenewalDate = item.RenewalPermissionDate,
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified
                        };
                        newItem.LogEntries.Add(new SubscriptionLogEntry() { Note = $"Added {entityName} {newItem.Name}" });
                        context.Subscriptions.Add(newItem);
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Name}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Subscriptions OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        private static void PersonWebsites(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.PersonMediaWebsiteEGroupRels.Count();
            var entityName = "Person-Website";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.PersonMediaWebsiteEGroupRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var e = context.Websites.Find(item.MediaWebsiteEGroupId);
                    var person = context.Persons.Include("Websites").FirstOrDefault(x => x.Id == item.BeholderPerson.CommonPersonId);
                    if (e == null || person == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (person.Websites.Any(x => x.Id == e.Id))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {person.ReverseFullName}-{e.Name} already exists");
                        continue;
                    }
                    person.Websites.Add(e);
                    person.LogEntries.Add(new PersonLogEntry() { Note = $"Added website {e.Name}" });
                    e.LogEntries.Add(new WebsiteLogEntry() { Note = $"Added Person {person.FullName}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {person.ReverseFullName}-{e.Name}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        private static void PersonOnlineAliases(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.PersonScreenNames.Count();
            var entityName = "Person-OnlineAlias";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.PersonScreenNames.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var person = context.Persons.Include("OnlineAlias").FirstOrDefault(x => x.Id == item.BeholderPerson.CommonPersonId);
                    if (person == null)
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {person.ReverseFullName}-{item.ScreenName} already exists");
                        continue;
                    }
                    //todo: change to onlinealiases
                    if (person.OnlineAlias.Any(x => x.ScreenName == item.ScreenName?.Trim() && x.PrimaryStatus == (PrimaryStatus)item.PrimaryStatusId))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {person.ReverseFullName}-{item.ScreenName} already exists");
                        continue;
                    }
                    person.OnlineAlias.Add(new OnlineAlias()
                    {
                        ScreenName = item.ScreenName,
                        PrimaryStatus = (PrimaryStatus)item.PrimaryStatusId,
                        DateCreated = item.DateCreated,
                        DateUpdated = item.DateModified
                    });
                    person.LogEntries.Add(new PersonLogEntry() { Note = $"Added Online Alias {item.ScreenName}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {person.ReverseFullName}-{item.ScreenName}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        public static void LoadWebsites(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.MediaWebsiteEGroups.Count();
            var entityName = "Website";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Websites ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.MediaWebsiteEGroups.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.Websites.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Name} already exists");
                            continue;
                        }

                        var newItem = new Website()
                        {
                            Id = item.Id,
                            Name = item.Name,
                            //                            Type = (WebsiteType)item.WebsiteEGroupTypeId,
                            Url = item.URL,
                            Summary = item.Summary,
                            DateDiscovered = item.DateDiscovered,
                            DatePublished = item.DatePublished,
                            DateOffline = item.DateOffline,
                            WhoIs = item.WhoIsInfo,
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified
                        };

                        newItem.LogEntries.Add(new WebsiteLogEntry() { Note = $"Added website {newItem.Name}" });
                        context.Websites.Add(newItem);
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Name}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Websites OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        private static void PersonComments(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.PersonComments.Count();
            var entityName = "Person-Comment";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.PersonComments.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var comment = item.Comment.Length > 15 ? item.Comment?.Substring(0, 15) : item.Comment;
                    var person = context.Persons.Include("LogEntries").FirstOrDefault(x => x.Id == item.BeholderPerson.CommonPersonId);
                    if (person == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (person.LogEntries.Any(x => x.Note == item.Comment?.Trim()))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {person.ReverseFullName}-{comment} already exists");
                        continue;
                    }
                    person.LogEntries.Add(new PersonLogEntry() { Note = item.Comment });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {person.ReverseFullName}-{comment}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
            }
        }
Example #24
0
 public CachedLookupRepository(ACDBContext ctx) : base(ctx)
 {
 }
 public MediaImageCommentRepository(ACDBContext ctx)
 {
     context = ctx;
 }
        private static void OrganizationImages(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.OrganizationMediaImageRels.Count();
            var entityName = "Organziation-Image";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.OrganizationMediaImageRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var e = context.MediaImages.Find(item.MediaImageId);
                    var org = context.Organizations.Include(x => x.MediaImages).First(x => x.Id == item.OrganizationId);
                    if (e == null || org == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (org.MediaImages.Any(x => x.Id == e.Id))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {org.Name}-{e.Title} already exists");
                        continue;
                    }
                    org.MediaImages.Add(e);
                    org.LogEntries.Add(new OrganizationLogEntry() { Note = $"Added Image {e.Title}" });
                    e.LogEntries.Add(new MediaImageLogEntry() { Note = $"Added Organization {org.Name}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {org.Name}-{e.Title}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
Example #27
0
 public EventRepository(ACDBContext ctx)
 {
     _ctx = ctx;
 }
        public static void LoadPublications(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.MediaPublisheds.Count();
            var entityName = "Publication";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Publications ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.MediaPublisheds.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.Publications.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Name} already exists");
                            continue;
                        }

                        var newItem = new Publication()
                        {
                            Id = item.Id,
                            Name = item.Name,
                            Summary = item.Summary,
                            DateReceived = item.DateReceived,
                            DatePublished = item.DatePublished,
                            Author = item.Author,
                            CatalogId = item.CatalogId,
                            RenewalType = Helpers.ConvertRenewalType(item.RenewalPermissionTypeId),
                            SecurityLevel = item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            //                        PublicationTypeId = item.PublishedTypeId,
                            City = item.City,
                            County = item.County,
                            StateId = item.StateId,
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified
                        };
                        newItem.LogEntries.Add(new PublicationLogEntry() { Note = $"Added {entityName} {newItem.Name}" });
                        context.Publications.Add(newItem);
                        context.SaveChanges();
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Name}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    //context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Publications OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
Example #29
0
        public static void Test()
        {
            using (ACDBContext db = new ACDBContext())
            {
                //                foreach (var c in db.Customers)
                //                {
                //                    Console.WriteLine($"{c.CustomerId}, {c.LastName}, {c.FirstName}, {c.JoinDate}");
                //                }

                //lEFTjOIN
                var LeftJoinn = from x in db.Packages
                                join y in db.Customers on x.PackId equals y.PackId into ys
                                from y in db.Customers.DefaultIfEmpty()
                                select new { Category = x.PackId, SubCategory = y.FirstName };

                //cross join
                var CrossJoin =
                    from x in db.Packages
                    from y in db.Customers
                    select new { var1 = x.PackId, var2 = y.FirstName };

                Console.WriteLine("1.	Display the lowest last name alphabetically (Customers table)");
                Console.WriteLine(db.Customers.Max(x => x.LastName));

                var v2 = db.Customers.OrderByDescending(x => x.LastName).Select(x => x.LastName).Take(1);

                var v3 = (from x in db.Customers
                          orderby x.LastName
                          select(x.LastName)).Take(1);

                //----------
                Console.WriteLine("2.	Display the average monthly payment (Packages table).");
                var v4 = db.Packages.Average(x => x.MonthlyPayment);
                Console.WriteLine(v4);


                Console.WriteLine("3.	Display the highest last name alphabetically (Customers table).");
                var v5  = db.Customers.OrderBy(x => x.LastName).Select(x => x.LastName).Take(1);
                var v51 = db.Customers.Min(x => x.LastName);
                foreach (var v in v5)
                {
                    Console.WriteLine($"{v} {v51}");
                }

                //==================

                Console.WriteLine("4.	Display the number of internet packages (Packages table).");
                var v6 = db.Packages.Count();
                Console.WriteLine(v6);

                //=====================

                Console.WriteLine("5.	Display the number of records in Customers table.");
                var v7 = db.Customers.Count();
                Console.WriteLine(v7);
                //========================

                Console.WriteLine("6.	Display the number of distinct states  (Customers table).");
                var v8 = db.Customers.Select(x => x.State).Distinct().Count();
                Console.WriteLine(v8);
                //========================

                Console.WriteLine("7.	Display the number of distinct internet speeds (Packages table).");
                var v9 = db.Packages.Select(x => x.Speed).Distinct().Count();
                Console.WriteLine(v9);
                //=======================

                Console.WriteLine("8.	Display the number of values (exclude Nulls) in Fax column (Customers table).");
                var v10 = db.Customers.Where(x => x.Fax != null).Select(x => x.Fax).Count();
                Console.WriteLine(v10);
                //======================

                Console.WriteLine("9.	Display the number of Null values in Fax column (Customers table).");
                var v11 = db.Customers.Where(x => x.Fax == null).Select(x => x.Fax).Count();
                Console.WriteLine(v11);
                //======================

                Console.WriteLine("10.	Display the highest, lowest and average monthly discount (Customers table).");
                var v12 = db.Customers.Average(x => x.MonthlyDiscount);
                var v13 = db.Customers.Min(x => x.MonthlyDiscount);
                var v14 = db.Customers.Max(x => x.MonthlyDiscount);


                //========================================================================================================
                Console.WriteLine("1.	Display the state and the number of customers for each state (Customers table).");
                var v15 = db.Customers.GroupBy(x => x.State).Select(x => new
                {
                    State          = x.Key,
                    CountCustomers = x.Count()
                });
                foreach (var v in v15)
                {
                    //Console.WriteLine($"{v.State}, {v.CountCustomers}");
                }
                //======================

                Console.WriteLine("2.	Display the internet speed and the average monthly payment for each speed (Packages table).");
                var v16 = db.Packages.GroupBy(x => x.Speed).Select(x => new
                {
                    Speed            = x.Key,
                    AvgMontlypayment = x.Average(y => y.MonthlyPayment)
                });
                foreach (var v in v16)
                {
                    Console.WriteLine($"{v.Speed}, {v.AvgMontlypayment}");
                }
                //=======================

                Console.WriteLine("3.	Display the state and the number of distinct cities for each state (Customers table).");
                var v17 = db.Customers.GroupBy(x => x.State).Select(x => new
                {
                    State           = x.Key,
                    DistinctCtities = x.Select(y => y.City).Distinct().Count()
                });
                foreach (var v in v17)
                {
                    //Console.WriteLine($"{v.State}{v.DistinctCtities}");
                }
                //==================

                Console.WriteLine("4.	Display the sector number and the highest monthly payment for each sector (Packages table).");
                var v18 = db.Packages.GroupBy(x => x.SectorId).Select(x => new
                {
                    SectorsNumber     = x.Key,
                    HighMontlyPayment = x.Max(y => y.MonthlyPayment)
                });

                //================
                //lEFTjOIN
                var LeftJoin = from x in db.Packages
                               join y in db.Customers on x.PackId equals y.PackId into ys
                               from y in db.Customers.DefaultIfEmpty()
                               select new { Category = x.PackId, SubCategory = y.FirstName };

                Console.WriteLine();
            }
        }
        public static void LoadAudioVideo(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.MediaAudioVideos.Count();
            var entityName = "AudioVideo";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT AudioVideos ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.MediaAudioVideos.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.AudioVideos.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Title} already exists");
                            continue;
                        }

                        var newItem = new AudioVideo()
                        {
                            Id = item.Id,
                            Title = item.Title?.Trim(),
                            Summary = item.Summary?.Trim(),
                            SpeakerCommentator = item.SpeakerCommentator?.Trim(),
                            MediaLength = item.MediaLength?.Trim(),
                            CatalogId = item.CatalogId?.Trim(),
                            DateReceivedRecorded = item.DateReceivedRecorded,
                            DateAired = item.DateAired,
                            AudioVideoType = (AudioVideoType)item.AudioVideoTypeId,
                            SecurityLevel =
                                item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            City = item.City?.Trim(),
                            County = item.County?.Trim(),
                            StateId = item.StateId,
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified,
                        };
                        newItem.LogEntries.Add(new AudioVideoLogEntry() { Note = $"Added {entityName} {newItem.Title}" });
                        context.AudioVideos.Add(newItem);
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Title}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT AudioVideos OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        public static void LoadImages(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.MediaImages.Count();
            var entityName = "Image";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT MediaImages ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.MediaImages.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.MediaImages.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Title} already exists");
                            continue;
                        }

                        var newItem = new Domain.Models.MediaImage()
                        {
                            Id = item.Id,
                            Title = item.ImageTitle?.Trim(),
                            Summary = item.Summary?.Trim(),
                            FileName = item.ImageFileName?.Trim(),
                            CatalogId = item.CatalogId?.Trim(),
                            ContactOwner = item.ContactOwner?.Trim(),
                            BatchSortOrder = item.BatchSortOrder,
                            Photographer = item.PhotographerArtist?.Trim(),
                            DatePublished = item.DatePublished,
                            DateTaken = item.DateTaken,
                            RollFrame = item.RollFrameNumber?.Trim(),
                            ImageType = Helpers.ConvertImageType(item.ImageTypeId),
                            SecurityLevel = item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            ////                        Image = item.Image.IMAGE1,
                            //                        MimeType = item.Image.MimeType.Name, //todo: make type
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified,
                        };
                        newItem.LogEntries.Add(new MediaImageLogEntry() { Note = $"Added {entityName} {newItem.Title}" });
                        context.MediaImages.Add(newItem);
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Title}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT MediaImages OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
Example #32
0
 public AddressPersonRelRepository(ACDBContext Context)
 {
     context = Context;
 }
Example #33
0
 public ImageRepository(ACDBContext Context)
 {
     context = Context;
 }
Example #34
0
 public VehicleRepository(ACDBContext ctx)
 {
     _ctx = ctx;
 }
        private static void OrganizationPeople(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.OrganizationPersonRels.Count();
            var entityName = "Organziation-Person";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.OrganizationPersonRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0).Include(x => x.BeholderPerson).OrderBy(x => x.Id))
                {
                    count++;
                    var person = context.Persons.Include(x => x.Organizations).FirstOrDefault(x => x.Id == item.BeholderPerson.CommonPersonId);
                    var org = context.Organizations.Find(item.OrganizationId);
                    if (person == null || org == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }

                    if (person.Organizations.Any(x => x.Id == org.Id))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {org.Name}-{person.FullName} already exists");
                        continue;
                    }
                    org.Persons.Add(person);
                    org.LogEntries.Add(new OrganizationLogEntry() { Note = $"Added Person {person.ReverseFullName}" });
                    person.LogEntries.Add(new PersonLogEntry() { Note = $"Added Organization {org.Name}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {org.Name}-{person.ReverseFullName}");
                    savedCount++;
                    context.SaveChanges();

                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
Example #36
0
 public ValidationController(ACDBContext context)
 {
     this.context = context;
 }
        private static void ChapterSubscriptions(int? skip = 0, int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.ChapterSubscriptionRels.Count();
            var entityName = "Chapter-Subscription";

            w.White.Line($"Creating {takecount} {entityName}s");
            using (var context = new AppContext())
            {
                foreach (var item in db.ChapterSubscriptionRels.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                {
                    count++;
                    var e = context.Subscriptions.Find(item.SubscriptionId);
                    var chapter = context.Chapters.Include(x => x.Subscriptions).FirstOrDefault(x => x.Id == item.ChapterId);
                    if (e == null || chapter == null)
                    {
                        w.Red.Line($"Error {entityName} {count} of {takecount}: {entityName} not found");
                        continue;
                    }
                    if (chapter.Subscriptions.Any(x => x.Id == e.Id))
                    {
                        w.Yellow.Line($"Warning {entityName} {count} of {takecount}: {entityName} {chapter.Name}-{e.Name} already exists");
                        continue;
                    }
                    chapter.Subscriptions.Add(e);
                    chapter.LogEntries.Add(new ChapterLogEntry() { Note = $"Added Subscription {e.Name}" });
                    e.LogEntries.Add(new SubscriptionLogEntry() { Note = $"Added Chapter {chapter.Name}" });
                    w.Green.Line($"Adding {count} of {takecount} {entityName}: {chapter.Name}-{e.Name}");
                    savedCount++;
                    context.SaveChanges();
                }
                w.Gray.Line($"Saving {entityName}s...");
                context.SaveChanges();

                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }
        public static void LoadCorrespondence(int? takecount = 0)
        {
            var startTime = DateTime.Now;
            var w = FluentConsole.Instance;
            var db = new ACDBContext();
            var count = 0;
            var savedCount = 0;
            if (takecount == 0) takecount = db.MediaCorrespondences.Count();
            var entityName = "Correspondence";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Correspondences ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.MediaCorrespondences.Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.Correspondences.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Name} already exists");
                            continue;
                        }

                        var newItem = new Correspondence()
                        {
                            Id = item.Id,
                            Name = item.CorrespondenceName?.Trim(),
                            CatalogId = item.CatalogId?.Trim(),
                            DateReceived = item.DateReceived,
                            Summary = item.Summary?.Trim(),
                            SecurityLevel =
                                item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                            Sender = item.FromName?.Trim(),
                            Receiver = item.FromName?.Trim(),
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            City = item.City?.Trim(),
                            County = item.County?.Trim(),
                            StateId = item.StateId,
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified
                        };
                        newItem.LogEntries.Add(new CorrespondenceLogEntry() { Note = $"Added {entityName} {newItem.Name}" });
                        context.Correspondences.Add(newItem);
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Name}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Correspondences OFF");
                    trans.Commit();
                }
                var totalTime = DateTime.Now - startTime;
                w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} ");
                w.White.Line(new String('-', 15));
            }
        }