Esempio n. 1
0
        /// <summary>
        /// Determines whether the specified compare is square.
        /// </summary>
        /// <param name="compare">
        /// The compare.
        /// </param>
        /// <returns>
        /// True if square; false otherwise.
        /// </returns>
        public bool IsSquare([NotNull] ChartObject compare)
        {
            // If fixed star is either of the objects, automatic false (Only conjunctions and possibly oppositions count).
            if (compare == null)
            {
                throw new ArgumentNullException("compare");
            }

            if ((compare.CelestialObject.CelestialObjectTypeId == (byte)ObjectTypes.FixedStar) ||
                (this.CelestialObject.CelestialObjectTypeId == (byte)ObjectTypes.FixedStar))
            {
                return(false);
            }

            decimal thisOrb;

            if (compare.CelestialObject.CelestialObjectTypeId == this.CelestialObject.CelestialObjectTypeId)
            {
                thisOrb = (compare.CelestialObject.AllowableOrb + this.CelestialObject.AllowableOrb) / 2M;
            }
            else if ((compare.CelestialObject.CelestialObjectTypeId == (byte)ObjectTypes.Asteroid) ||
                     (this.CelestialObject.CelestialObjectTypeId == (byte)ObjectTypes.Asteroid) ||
                     (compare.CelestialObject.CelestialObjectTypeId == (byte)ObjectTypes.Midpoint) ||
                     (this.CelestialObject.CelestialObjectTypeId == (byte)ObjectTypes.Midpoint))
            {
                thisOrb = Math.Min(compare.CelestialObject.AllowableOrb, this.CelestialObject.AllowableOrb);
            }
            else
            {
                thisOrb = Math.Min(compare.CelestialObject.AllowableOrb, this.CelestialObject.AllowableOrb);
            }

            var           difference  = Math.Abs(compare.CalculatedCoordinate - this.CalculatedCoordinate);
            const decimal DegreeCheck = 90M;

            return(((difference >= DegreeCheck - thisOrb) && (difference <= DegreeCheck + thisOrb)) ||
                   ((difference >= (360 - DegreeCheck) - thisOrb) && (difference <= (360 - DegreeCheck) + thisOrb)));
        }
        public async Task<IHttpActionResult> PostChartObject(ChartObject chartObject)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            this.db.ChartObjects.Add(chartObject);
            await this.db.SaveChangesAsync();

            return this.CreatedAtRoute("DefaultApi", new { id = chartObject.ChartObjectId }, chartObject);
        }
Esempio n. 3
0
        public ChartObject GetDraconicChartObject([CanBeNull] ChartObject northNode)
        {
            if (northNode == null)
            {
                return(null);
            }

            if (this.CelestialObject.Draconic)
            {
                // if already draconic, return itself.
                return(this);
            }

            const int SecondsInMinutes = 60;
            const int MinutesInDegrees = 60;
            const int DegreesInSign    = 30;
            const int SignsInChart     = 12;

            var newCoordinateInSeconds = this.CoordinateInSeconds - northNode.CoordinateInSeconds;

            while (newCoordinateInSeconds < 0)
            {
                newCoordinateInSeconds += SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes;
            }

            while (newCoordinateInSeconds > SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes)
            {
                newCoordinateInSeconds %= SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes;
            }

            var newSignId = (byte)(newCoordinateInSeconds / (DegreesInSign * MinutesInDegrees * SecondsInMinutes));

            var deg = (newCoordinateInSeconds / (MinutesInDegrees * SecondsInMinutes)) % DegreesInSign;
            var min = (newCoordinateInSeconds / SecondsInMinutes) % MinutesInDegrees;
            var sec = newCoordinateInSeconds % SecondsInMinutes;

            return(new ChartObject
            {
                EnteredChart = this.EnteredChart,
                EnteredChartID = this.EnteredChartID,
                Degrees = (byte)deg,
                Minutes = (byte)min,
                Seconds = (byte)sec,
                SignId = newSignId,
                Sign = new AstroGearsEntities().Signs.Find(newSignId),
                CelestialObject =
                    new CelestialObject
                {
                    AllowableOrb = this.CelestialObject.AllowableOrb,
                    AlternateName =
                        "Dr. " + this.CelestialObject.AlternateName,
                    CelestialObjectId = 0,
                    CelestialObjectName =
                        "Dr. " + this.CelestialObject.CelestialObjectName,
                    Draconic = true,
                    CelestialObjectType =
                        new CelestialObjectType
                    {
                        CelestialObjectTypeName =
                            this.CelestialObject
                            .CelestialObjectType
                            .CelestialObjectTypeName,
                        CelestialObjectTypeId =
                            this.CelestialObject
                            .CelestialObjectType
                            .CelestialObjectTypeId
                    },
                    CelestialObjectTypeId =
                        this.CelestialObject.CelestialObjectTypeId
                },
                CelestialObjectId = this.CelestialObjectId,
                Orientation =
                    new Orientation
                {
                    OrientationId = this.Orientation.OrientationId,
                    OrientationAbbreviation =
                        this.Orientation.OrientationAbbreviation
                },
                OrientationId = this.OrientationId
            });
        }
Esempio n. 4
0
        public ChartObject GetMidpoint(
            [CanBeNull] ChartObject otherChartObject)
        {
            if (otherChartObject == null)
            {
                return(null);
            }

            const int SecondsInMinutes = 60;
            const int MinutesInDegrees = 60;
            const int DegreesInSign    = 30;
            const int SignsInChart     = 12;

            var newCoordinateInSeconds = (this.CoordinateInSeconds + otherChartObject.CoordinateInSeconds) / 2;

            // If the logical order of the
            if (Math.Abs(this.CoordinateInSeconds - otherChartObject.CoordinateInSeconds)
                > 180 * MinutesInDegrees * SecondsInMinutes)
            {
                newCoordinateInSeconds += 180 * MinutesInDegrees * SecondsInMinutes;
            }

            while (newCoordinateInSeconds < 0)
            {
                newCoordinateInSeconds += SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes;
            }

            while (newCoordinateInSeconds > SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes)
            {
                newCoordinateInSeconds %= SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes;
            }

            var newSignId = (byte)(newCoordinateInSeconds / (DegreesInSign * MinutesInDegrees * SecondsInMinutes));

            var deg = (newCoordinateInSeconds / (MinutesInDegrees * SecondsInMinutes)) % DegreesInSign;
            var min = (newCoordinateInSeconds / SecondsInMinutes) % MinutesInDegrees;
            var sec = newCoordinateInSeconds % SecondsInMinutes;

            return(new ChartObject
            {
                EnteredChart = this.EnteredChart,
                EnteredChartID = this.EnteredChartID,
                Degrees = (byte)deg,
                Minutes = (byte)min,
                Seconds = (byte)sec,
                SignId = newSignId,
                Sign = new AstroGearsEntities().Signs.Find(newSignId),
                CelestialObject =
                    new CelestialObject
                {
                    AllowableOrb = 1M,
                    AlternateName =
                        this.CelestialObject.AlternateName + "/" + otherChartObject.CelestialObject.AlternateName + " Midpoint",
                    CelestialObjectId = 0,
                    CelestialObjectName =
                        this.CelestialObject.CelestialObjectName + "/" + otherChartObject.CelestialObject.CelestialObjectName + " Midpoint",
                    Draconic = this.CelestialObject.Draconic && otherChartObject.CelestialObject.Draconic,
                    CelestialObjectType =
                        new CelestialObjectType
                    {
                        CelestialObjectTypeName =
                            "Midpoint",
                        CelestialObjectTypeId =
                            (byte)ObjectTypes.Midpoint
                    },
                    CelestialObjectTypeId =
                        (byte)ObjectTypes.Midpoint
                },
                CelestialObjectId = this.CelestialObjectId,
                Orientation =
                    new Orientation
                {
                    OrientationId = 1,
                    OrientationAbbreviation =
                        string.Empty
                },
                OrientationId = 1
            });
        }
        public List<ChartObject> GetArabicPartChartObjects(int chartId, byte houseSystemId, bool arabic)
        {
            try
            {
                // Exit without changes if invalid selection selected.
                if (chartId <= 0 || !arabic)
                {
                    return new List<ChartObject>();
                }

                ////var arabicImport = new EnteredChart(id);
                ////var arabicImport = this.db.EnteredCharts.Find(id);
                ////arabicImport.GetObjects();

                // Most arabic parts are dependent on knowing the angles.  Without these, we cannot continue.
                // So angles AND all major planets are required.
                ////var angleCusps = new List<EnteredChartObject>();
                var cuspHouses =
                    this.db.ChartHouses.Include(ch => ch.Sign)
                        .Where(
                            houses =>
                            houses.EnteredChartId == chartId && houses.HouseSystemId == houseSystemId
                            && houses.HouseCusp.HouseCuspName != "Vertex")
                        .OrderBy(a => a.HouseId)
                        .ToList();

                if (cuspHouses.Count != 12)
                {
                    return new List<ChartObject>();
                }

                var chartAngles =
                    this.db.ChartAngles.Include(an => an.Sign)
                        .Where(ah => ah.EnteredChartId == chartId)
                        .OrderBy(a => a.AngleId)
                        .ToList();

                var angles =
                    chartAngles.Select(
                        an =>
                        new ChartObject
                            {
                                Sign = an.Sign,
                                SignId = an.SignId,
                                Degrees = an.Degrees,
                                Minutes = an.Minutes,
                                Seconds = an.Seconds,
                                CelestialObject =
                                    new CelestialObject { CelestialObjectName = an.HouseAngle.AngleName }
                            })
                        .ToList();

                var cusps =
                    cuspHouses.Select(
                        ah =>
                        new ChartObject
                            {
                                Sign = ah.Sign,
                                SignId = ah.SignId,
                                Degrees = ah.Degrees,
                                Minutes = ah.Minutes,
                                Seconds = ah.Seconds,
                                CelestialObject =
                                    new CelestialObject { CelestialObjectName = ah.HouseCusp.HouseCuspName }
                            })
                        .ToList();

                ////var angleCusps = this.db.ChartHouses.Where(houses => houses.EnteredChartId == id && houses.HouseAngle.HouseAngleName != "Vertex").ToList();
                var planets =
                    this.db.ChartObjects.Include(ob => ob.Sign)
                        .Where(
                            p =>
                            p.EnteredChartID == chartId
                            && p.CelestialObject.CelestialObjectTypeId
                            == (byte)ChartObject.ObjectTypes.MajorPlanetLuminary && !p.CelestialObject.Draconic)
                        .OrderBy(p => p.CelestialObjectId)
                        .ToList();

                var houseRulers = new List<ChartObject>();

                // House Cusps / Angles (we don't worry as much about Vertex)
                // IF any house/angle is missing, end.
                if (cusps.Count() != 12)
                {
                    return new List<ChartObject>();
                }

                var northNode =
                    this.db.ChartObjects.FirstOrDefault(
                        nn => nn.CelestialObject.CelestialObjectName == "True Node" && nn.EnteredChartID == chartId);

                ChartObject southNode = null;
                if (northNode != null)
                {
                    southNode = new ChartObject
                                    {
                                        EnteredChart = northNode.EnteredChart,
                                        EnteredChartID = northNode.EnteredChartID,
                                        Degrees = northNode.Degrees,
                                        Minutes = northNode.Minutes,
                                        Seconds = northNode.Seconds,
                                        SignId = northNode.SignId,
                                        Sign = null,
                                        CelestialObject =
                                            new CelestialObject
                                                {
                                                    AllowableOrb =
                                                        northNode.CelestialObject.AllowableOrb,
                                                    AlternateName = null,
                                                    CelestialObjectId = 0,
                                                    CelestialObjectName = "South Node",
                                                    Draconic = false,
                                                    CelestialObjectType =
                                                        new CelestialObjectType
                                                            {
                                                                CelestialObjectTypeName
                                                                    =
                                                                    northNode
                                                                    .CelestialObject
                                                                    .CelestialObjectType
                                                                    .CelestialObjectTypeName,
                                                                CelestialObjectTypeId
                                                                    =
                                                                    northNode
                                                                    .CelestialObject
                                                                    .CelestialObjectType
                                                                    .CelestialObjectTypeId
                                                            },
                                                    CelestialObjectTypeId =
                                                        northNode.CelestialObject
                                                        .CelestialObjectTypeId
                                                },
                                        CelestialObjectId = northNode.CelestialObjectId,
                                        Orientation =
                                            new Orientation
                                                {
                                                    OrientationId =
                                                        northNode.Orientation.OrientationId,
                                                    OrientationAbbreviation =
                                                        northNode.Orientation
                                                        .OrientationAbbreviation
                                                },
                                        OrientationId = northNode.OrientationId
                                    };
                    southNode.CelestialObject.CelestialObjectName = "South Node";
                    if (northNode.SignId > 5)
                    {
                        southNode.SignId = (byte)(northNode.SignId - 6);
                    }
                    else
                    {
                        southNode.SignId = (byte)(northNode.SignId + 6);
                    }

                    southNode.Sign = this.db.Signs.Find(southNode.SignId);
                }

                // IF any planet is missing, end.
                if (planets.Count != 10)
                {
                    return new List<ChartObject>();
                }

                for (var i = 0; i < 12; i++)
                {
                    houseRulers.Add(planets.FirstOrDefault(p => p.CelestialObjectId == cusps[i].Sign.ModernRulerId));
                }

                // If the sun is in houses 7-12, it's a day chart.  Otherwise, treat as a night chart.
                var sun = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Sun");
                var moon = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Moon");
                var mercury = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Mercury");
                var venus = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Venus");
                var mars = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Mars");
                var jupiter = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Jupiter");
                var saturn = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Saturn");
                var uranus = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Uranus");
                var neptune = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Neptune");
                var pluto = planets.FirstOrDefault(p => p.CelestialObject.CelestialObjectName == "Pluto");

                var first = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "1st House Cusp");
                var second = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "2nd House Cusp");
                var third = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "3rd House Cusp");
                var fourth = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "4th House Cusp");
                var fifth = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "5th House Cusp");

                ////var sixth = angleCusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "6th House Cusp");
                var seventh = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "7th House Cusp");
                var eighth = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "8th House Cusp");
                var ninth = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "9th House Cusp");

                ////var tenth = cusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "10th House Cusp");
                ////var eleventh = angleCusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "11th House Cusp");
                ////var twelfth = angleCusps.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "12th House Cusp");
                var ascendant = angles.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "Ascendant");
                var midheaven = angles.FirstOrDefault(a => a.CelestialObject.CelestialObjectName == "Midheaven");

                if (ascendant == null || midheaven == null)
                {
                    return new List<ChartObject>();
                }

                var rulerOfFirst = houseRulers[0];
                var rulerOfSecond = houseRulers[1];
                var rulerOfThird = houseRulers[2];

                ////var rulerOfFourth = houseRulers[3];
                var rulerOfFifth = houseRulers[4];

                ////var rulerOfSixth = houseRulers[5];
                ////var rulerOfSeventh = houseRulers[6];
                ////var rulerOfEighth = houseRulers[7];
                ////var rulerOfNinth = houseRulers[8];
                var rulerOfTenth = houseRulers[9];

                ////var rulerOfEleventh = houseRulers[10];
                var rulerOfTwelfth = houseRulers[11];

                var cancerId = this.db.Signs.FirstOrDefault(s => s.SignName == "Cancer").SignId;
                var libraId = this.db.Signs.FirstOrDefault(s => s.SignName == "Libra").SignId;

                var isDayChart = first != null
                                 && (seventh != null
                                     && (sun != null
                                         && ((sun.CalculatedCoordinate > seventh.CalculatedCoordinate)
                                             || (sun.CalculatedCoordinate < first.CalculatedCoordinate))));

                ChartObject partoffortune, partofspirit;

                if (isDayChart)
                {
                    partoffortune = this.NewArabicPart(chartId, "Part of Fortune", first, moon, sun);
                    partofspirit = this.NewArabicPart(chartId, "Part of Spirit", first, sun, moon);
                }
                else
                {
                    partoffortune = this.NewArabicPart(chartId, "Part of Fortune", first, sun, moon);
                    partofspirit = this.NewArabicPart(chartId, "Part of Spirit", first, moon, sun);
                }

                var lastCuspBeforeMoon = cusps.LastOrDefault(x => x.CalculatedCoordinate < moon.CalculatedCoordinate)
                                         ?? cusps.LastOrDefault(
                                             x => x.CalculatedCoordinate < (moon.CalculatedCoordinate + 360M));

                var lastCuspIndex = cusps.IndexOf(lastCuspBeforeMoon);

                var rulerMoonHouse = houseRulers[lastCuspIndex];

                var newParts = new List<ChartObject> { partoffortune, partofspirit };

                if (isDayChart)
                {
                    newParts.Add(this.NewArabicPart(chartId, "Part of Ancestors/Relations", first, mars, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Children", first, saturn, jupiter));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Danger, Violence, Debt", first, mercury, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Death (Parents)", first, jupiter, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Debt", first, mercury, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Destiny", midheaven, sun, moon));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Fame", first, jupiter, sun));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Father", first, sun, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Grandparents (1)", first, jupiter, second));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Grandparents (2)", first, saturn, second));
                    newParts.Add(
                        this.NewArabicPart(
                            chartId,
                            "Part of Journeys (Water)",
                            first,
                            new ChartObject
                                {
                                    EnteredChartID = chartId,
                                    SignId = cancerId,
                                    OrientationId = 1,
                                    Degrees = 15,
                                    Minutes = 0,
                                    Seconds = 0,
                                    CelestialObject =
                                        new CelestialObject
                                            {
                                                CelestialObjectTypeId = 1,
                                                AllowableOrb = 1M,
                                                Draconic = false
                                            }
                                },
                            saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Knowledge", first, moon, mercury));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Life, Reincarnation", first, saturn, jupiter));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Peril", first, eighth, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Real Estate (Land)", first, moon, saturn));
                    newParts.Add(
                        this.NewArabicPart(chartId, "Part of Real Estate (Investment)", first, jupiter, mercury));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Son-in-Laws", first, venus, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Success", first, jupiter, partoffortune));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Surgery", first, saturn, mars));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Victory", first, jupiter, partofspirit));
                }
                else
                {
                    newParts.Add(this.NewArabicPart(chartId, "Part of Ancestors/Relations", first, saturn, mars));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Children", first, jupiter, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Danger, Violence, Debt", first, saturn, mercury));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Death (Parents)", first, saturn, jupiter));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Debt", first, saturn, mercury));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Destiny", midheaven, moon, sun));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Fame", first, sun, jupiter));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Father", first, saturn, sun));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Grandparents (1)", first, second, jupiter));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Grandparents (2)", first, second, saturn));
                    newParts.Add(
                        this.NewArabicPart(
                            chartId,
                            "Part of Journeys (Water)",
                            first,
                            saturn,
                            new ChartObject
                                {
                                    EnteredChartID = chartId,
                                    SignId = cancerId,
                                    OrientationId = 1,
                                    Degrees = 15,
                                    Minutes = 0,
                                    Seconds = 0,
                                    CelestialObject =
                                        new CelestialObject
                                            {
                                                CelestialObjectTypeId = 1,
                                                AllowableOrb = 1M,
                                                Draconic = false
                                            }
                                }));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Knowledge", first, mercury, moon));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Life, Reincarnation", first, jupiter, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Peril", first, saturn, eighth));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Real Estate (Land)", first, saturn, moon));
                    newParts.Add(
                        this.NewArabicPart(chartId, "Part of Real Estate (Investment)", first, mercury, jupiter));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Son-in-Laws", first, saturn, venus));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Success", first, partoffortune, jupiter));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Surgery", first, mars, saturn));
                    newParts.Add(this.NewArabicPart(chartId, "Part of Victory", first, partofspirit, jupiter));
                }

                newParts.Add(this.NewArabicPart(chartId, "Part of Ability", first, mars, rulerOfFirst));
                newParts.Add(this.NewArabicPart(chartId, "Part of Abundance", first, sun, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Accident", first, saturn, mars));
                newParts.Add(this.NewArabicPart(chartId, "Part of Accomplishment", first, sun, jupiter));
                newParts.Add(this.NewArabicPart(chartId, "Part of Action/Reasoning", first, mars, mercury));
                if (southNode != null)
                {
                    newParts.Add(this.NewArabicPart(chartId, "Part of Addiction", first, southNode, neptune));
                }

                newParts.Add(this.NewArabicPart(chartId, "Part of Administrators", first, mars, mercury));
                newParts.Add(this.NewArabicPart(chartId, "Part of Agriculture", first, saturn, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Allegiance", first, saturn, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Ancestral Heritage", first, moon, eighth));
                newParts.Add(this.NewArabicPart(chartId, "Part of Armies", first, saturn, mars));
                newParts.Add(this.NewArabicPart(chartId, "Part of Art", first, venus, mercury));
                newParts.Add(this.NewArabicPart(chartId, "Part of Assassination (1)", first, rulerOfTwelfth, neptune));
                newParts.Add(this.NewArabicPart(chartId, "Part of Assassination (2)", mars, neptune, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Assurance", first, jupiter, mercury));
                newParts.Add(this.NewArabicPart(chartId, "Part of Astrology", first, uranus, mercury));
                newParts.Add(this.NewArabicPart(chartId, "Part of Bad Luck", first, partoffortune, partofspirit));
                newParts.Add(this.NewArabicPart(chartId, "Part of Bankruptcy (1)", jupiter, neptune, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Bankruptcy (2)", jupiter, jupiter, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Beauty", first, venus, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Benific Change", first, pluto, jupiter));
                newParts.Add(this.NewArabicPart(chartId, "Part of Benevolence", first, jupiter, pluto));
                newParts.Add(this.NewArabicPart(chartId, "Part of Business Partnerships", first, seventh, rulerOfTenth));
                newParts.Add(this.NewArabicPart(chartId, "Part of Cancer", first, neptune, jupiter));
                newParts.Add(this.NewArabicPart(chartId, "Part of Catastrophe (1)", first, uranus, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Catastrophe (2)", first, uranus, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Caution", first, neptune, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Commerce (1)", first, mercury, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Commerce (2)", first, mars, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Controversy", first, jupiter, mars));
                newParts.Add(this.NewArabicPart(chartId, "Part of Corruptness", first, neptune, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Curiosity", first, moon, mercury));
                newParts.Add(this.NewArabicPart(chartId, "Part of Damage", first, neptune, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Daughters", first, venus, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Death", first, eighth, moon));
                newParts.Add(
                    this.NewArabicPart(chartId, "Part of Desire, Sexual Attraction", first, fifth, rulerOfFifth));
                newParts.Add(this.NewArabicPart(chartId, "Part of Destruction", first, mars, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Disease", first, mars, mercury));
                newParts.Add(this.NewArabicPart(chartId, "Part of Divorce (1)", first, venus, seventh));
                newParts.Add(this.NewArabicPart(chartId, "Part of Divorce (2)", first, seventh, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Eccentricity", first, mercury, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Energy, Sex Drive", first, pluto, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Expected Birth (1)", first, rulerMoonHouse, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Expected Birth (2)", first, venus, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Famous Friends", first, partoffortune, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Fascination", first, venus, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Fatality", first, saturn, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Fate (Karma)", first, saturn, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Fraud", first, neptune, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Friends (1)", first, moon, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Friends (2)", first, mercury, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Friends (3)", first, moon, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Genius", first, sun, neptune));
                newParts.Add(this.NewArabicPart(chartId, "Part of Guidance", first, neptune, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Happiness", first, uranus, jupiter));
                newParts.Add(this.NewArabicPart(chartId, "Part of Homosexuality", first, mars, uranus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Horsemanship", first, moon, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Identity", first, saturn, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Imprisonment", first, sun, neptune));
                newParts.Add(this.NewArabicPart(chartId, "Part of Increase", first, jupiter, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Inheritance (1)", first, moon, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Inheritance (2)", first, jupiter, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Journeys (Air)", first, uranus, ninth));
                newParts.Add(this.NewArabicPart(chartId, "Part of Journeys (Land)", first, ninth, ninth));
                newParts.Add(this.NewArabicPart(chartId, "Part of Kings, Rulers", first, moon, mercury));
                newParts.Add(this.NewArabicPart(chartId, "Part of Love", first, venus, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Lovers", mars, venus, fifth));
                newParts.Add(this.NewArabicPart(chartId, "Part of Luck", first, moon, jupiter));
                newParts.Add(this.NewArabicPart(chartId, "Part of Marriage", first, seventh, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Marriage of Woman (1)", first, saturn, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Marriage of Woman (2)", first, mars, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Marriage of Man (1)", first, venus, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Marriage of Man (2)", first, venus, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Mother", first, moon, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Partners", first, seventh, venus));
                newParts.Add(this.NewArabicPart(chartId, "Part of Possessions", first, second, rulerOfSecond));
                newParts.Add(this.NewArabicPart(chartId, "Part of Secret Enemies", first, moon, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Short Journeys", first, third, rulerOfThird));
                newParts.Add(this.NewArabicPart(chartId, "Part of Siblings", first, saturn, jupiter));
                newParts.Add(this.NewArabicPart(chartId, "Part of Sickness", first, mars, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Sons", fourth, moon, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Success (Investment)", first, venus, saturn));
                newParts.Add(this.NewArabicPart(chartId, "Part of Suicide(1)", first, eighth, neptune));
                newParts.Add(this.NewArabicPart(chartId, "Part of Suicide(2)", first, jupiter, neptune));
                newParts.Add(this.NewArabicPart(chartId, "Part of Tragedy", first, saturn, sun));
                newParts.Add(this.NewArabicPart(chartId, "Part of Unusual Events", first, uranus, moon));
                newParts.Add(this.NewArabicPart(chartId, "Part of Weddings, Legal Contracts", ninth, third, venus));
                newParts.Add(
                    this.NewArabicPart(
                        chartId,
                        "Part of Widowhood",
                        first,
                        new ChartObject
                            {
                                EnteredChartID = chartId,
                                SignId = libraId,
                                OrientationId = 1,
                                Degrees = 8,
                                Minutes = 50,
                                Seconds = 0,
                                CelestialObject =
                                    new CelestialObject
                                        {
                                            CelestialObjectTypeId = 1,
                                            AllowableOrb = 1M,
                                            Draconic = false
                                        }
                            },
                        neptune));

                return newParts;
            }
            catch
            {
                return new List<ChartObject>();
            }
        }
        public List<ChartObject> GetAngleChartObjects(int chartId)
        {
            try
            {
                const byte AngleHouseCuspTypeId = (byte)ChartObject.ObjectTypes.AngleHouseCusp;
                var angleHouseCuspType = this.db.CelestialObjectTypes.Find(AngleHouseCuspTypeId);
                const byte AngleOrientationId = (byte)1;
                var angleOrientation = this.db.Orientations.Find(AngleOrientationId);
                var signs = this.db.Signs.ToList();

                var chartAngles = new List<ChartObject>();

                var baseAngles = this.db.ChartAngles.Where(angles => angles.EnteredChartId == chartId);

                foreach (var x in baseAngles)
                {
                    chartAngles.Add(
                        new ChartObject
                            {
                                EnteredChartID = chartId,
                                CelestialObject =
                                    new CelestialObject
                                        {
                                            CelestialObjectName = x.HouseAngle.AngleName,
                                            AlternateName = x.HouseAngle.AngleName.ToUpper(),
                                            AllowableOrb =
                                                x.HouseAngle.AngleName == "Vertex" ? 1M : 3M,
                                            CelestialObjectTypeId = AngleHouseCuspTypeId,
                                            CelestialObjectType = angleHouseCuspType,
                                            Draconic = false
                                        },
                                OrientationId = AngleOrientationId,
                                Orientation = angleOrientation,
                                SignId = x.Sign.SignId,
                                Sign = signs.Find(s => s.SignId == x.Sign.SignId),
                                Degrees = x.Degrees,
                                Minutes = x.Minutes,
                                Seconds = x.Seconds,
                                AngleId = x.AngleId
                            });
                }

                var vertex = chartAngles.FirstOrDefault(x => x.CelestialObject.CelestialObjectName == "Vertex");

                if (vertex != null)
                {
                    var antivertex = new ChartObject
                                         {
                                             EnteredChartID = chartId,
                                             CelestialObject =
                                                 new CelestialObject
                                                     {
                                                         CelestialObjectName = "Antivertex",
                                                         AlternateName = "ANTIVERTEX",
                                                         AllowableOrb = 1M,
                                                         CelestialObjectTypeId =
                                                             AngleHouseCuspTypeId,
                                                         CelestialObjectType =
                                                             angleHouseCuspType,
                                                         Draconic = false
                                                     },
                                             OrientationId = AngleOrientationId,
                                             Orientation = angleOrientation,
                                             SignId =
                                                 vertex.SignId < 6
                                                     ? (byte)(vertex.SignId + 6)
                                                     : (byte)(vertex.SignId - 6),
                                             Sign =
                                                 signs.Find(
                                                     s =>
                                                     s.SignId
                                                     == (vertex.SignId < 6
                                                             ? (byte)(vertex.SignId + 6)
                                                             : (byte)(vertex.SignId - 6))),
                                             Degrees = vertex.Degrees,
                                             Minutes = vertex.Minutes,
                                             Seconds = vertex.Seconds,
                                             AngleId = 3
                                         };

                    chartAngles.Add(antivertex);
                }

                var ascendant = chartAngles.FirstOrDefault(x => x.CelestialObject.CelestialObjectName == "Ascendant");

                if (ascendant != null)
                {
                    var descendant = new ChartObject
                                         {
                                             EnteredChartID = chartId,
                                             CelestialObject =
                                                 new CelestialObject
                                                     {
                                                         CelestialObjectName = "Descendant",
                                                         AlternateName = "DESCENDANT",
                                                         AllowableOrb = 3M,
                                                         CelestialObjectTypeId =
                                                             AngleHouseCuspTypeId,
                                                         CelestialObjectType =
                                                             angleHouseCuspType,
                                                         Draconic = false
                                                     },
                                             OrientationId = AngleOrientationId,
                                             Orientation = angleOrientation,
                                             SignId =
                                                 ascendant.SignId < 6
                                                     ? (byte)(ascendant.SignId + 6)
                                                     : (byte)(ascendant.SignId - 6),
                                             Sign =
                                                 this.db.Signs.Find(
                                                     ascendant.SignId < 6
                                                         ? (byte)(ascendant.SignId + 6)
                                                         : (byte)(ascendant.SignId - 6)),
                                             Degrees = ascendant.Degrees,
                                             Minutes = ascendant.Minutes,
                                             Seconds = ascendant.Seconds,
                                             AngleId = 4
                                         };

                    chartAngles.Add(descendant);
                }

                var midheaven = chartAngles.FirstOrDefault(x => x.CelestialObject.CelestialObjectName == "Midheaven");

                if (midheaven != null)
                {
                    var imumCoeli = new ChartObject
                                        {
                                            EnteredChartID = chartId,
                                            CelestialObject =
                                                new CelestialObject
                                                    {
                                                        CelestialObjectName = "Imum Coeli",
                                                        AlternateName = "IMUM COELI",
                                                        AllowableOrb = 3M,
                                                        CelestialObjectTypeId =
                                                            AngleHouseCuspTypeId,
                                                        CelestialObjectType = angleHouseCuspType,
                                                        Draconic = false
                                                    },
                                            OrientationId = AngleOrientationId,
                                            Orientation = angleOrientation,
                                            SignId =
                                                midheaven.SignId < 6
                                                    ? (byte)(midheaven.SignId + 6)
                                                    : (byte)(midheaven.SignId - 6),
                                            Sign =
                                                this.db.Signs.Find(
                                                    midheaven.SignId < 6
                                                        ? (byte)(midheaven.SignId + 6)
                                                        : (byte)(midheaven.SignId - 6)),
                                            Degrees = midheaven.Degrees,
                                            Minutes = midheaven.Minutes,
                                            Seconds = midheaven.Seconds,
                                            AngleId = 5
                                        };

                    chartAngles.Add(imumCoeli);
                }

                return chartAngles;
            }
            catch
            {
                return new List<ChartObject>();
            }
        }
        public ChartObject NewArabicPart(
            int id,
            [NotNull] string name,
            [CanBeNull] ChartObject baseChartObject,
            [CanBeNull] ChartObject addChartObject,
            [CanBeNull] ChartObject subtractChartObject)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if ((baseChartObject == null) || (addChartObject == null) || (subtractChartObject == null))
            {
                return null;
            }

            const int SecondsInMinutes = 60;
            const int MinutesInDegrees = 60;
            const int DegreesInSign = 30;
            const int SignsInChart = 12;

            ////var diff = baseChartObject.CalculatedCoordinate + addChartObject.CalculatedCoordinate - subtractChartObject.CalculatedCoordinate;
            var diff = baseChartObject.CoordinateInSeconds + addChartObject.CoordinateInSeconds
                       - subtractChartObject.CoordinateInSeconds;

            // There is a risk of the calculation going out of bounds.  Adjust.
            while (diff < 0)
            {
                ////diff += 360;
                diff += SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes;
            }

            ////while (diff > 360M)
            while (diff > SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes)
            {
                ////diff %= 360M;
                diff %= SignsInChart * DegreesInSign * MinutesInDegrees * SecondsInMinutes;
            }

            ////var rawInSign = decimal.Round((diff % 30M) * 3600);
            ////var sign = (byte)((int)diff / 30);
            ////var sec = (int)rawInSign;
            ////var deg = sec / 3600;
            ////sec %= 3600;
            ////var min = sec / 60;
            ////sec %= 60;
            var sign = (byte)(diff / (DegreesInSign * MinutesInDegrees * SecondsInMinutes));

            var deg = (diff / (MinutesInDegrees * SecondsInMinutes)) % DegreesInSign;
            var min = (diff / SecondsInMinutes) % MinutesInDegrees;
            var sec = diff % SecondsInMinutes;

            var newPart = new ChartObject
                              {
                                  EnteredChartID = id,
                                  CelestialObject =
                                      new CelestialObject
                                          {
                                              CelestialObjectName = name,
                                              AllowableOrb = 1M,
                                              CelestialObjectTypeId = 3,
                                              CelestialObjectType =
                                                  this.db.CelestialObjectTypes.Find(3),
                                              Draconic =
                                                  baseChartObject.CelestialObject.Draconic
                                          },
                                  OrientationId = 1,
                                  Orientation = this.db.Orientations.Find(1),
                                  SignId = sign,
                                  Sign = this.db.Signs.Find(sign),
                                  Degrees = (byte)deg,
                                  Minutes = (byte)min,
                                  Seconds = (byte)sec
                              };

            return newPart;
        }
        /// <summary>
        /// Creates the chart object for entered chart.
        /// </summary>
        /// <param name="enteredChartId">The entered chart identifier.</param>
        /// <param name="degrees">The degrees.</param>
        /// <param name="signId">The sign identifier.</param>
        /// <param name="minutes">The minutes.</param>
        /// <param name="seconds">The seconds.</param>
        /// <param name="orientationId">The orientation identifier.</param>
        /// <param name="celestialObjectId">The celestial object identifier.</param>
        /// <returns>
        /// A JSON result.
        /// </returns>
        public JsonResult CreateChartObjectForEnteredChart(
            int enteredChartId,
            byte degrees,
            byte signId,
            byte minutes,
            byte seconds,
            byte orientationId,
            int celestialObjectId)
        {
            var newObject = new ChartObject
                                {
                                    EnteredChartID = enteredChartId,
                                    Degrees = degrees,
                                    SignId = signId,
                                    Minutes = minutes,
                                    Seconds = seconds,
                                    OrientationId = orientationId,
                                    CelestialObjectId = celestialObjectId
                                };
            this.db.ChartObjects.Add(newObject);
            this.db.SaveChanges();

            return this.Json("Success", JsonRequestBehavior.AllowGet);
        }