Beispiel #1
0
        public static string AddBirthData(string user, BirthData birthData)
        {
            SQLiteConnection connection = new SQLiteConnection(ConnectionString);
            string           insertText = string.Empty
                                          + @"INSERT INTO birthdata (owner, first_name, last_initial, birthday) VALUES "
                                          + "(@owner, @first_name, @last_initial, @birth_day)";
            SQLiteCommand command = new SQLiteCommand(insertText, connection);

            command.Parameters.AddWithValue("@owner", user);
            command.Parameters.AddWithValue("@first_name", birthData.Name.FirstName);
            command.Parameters.AddWithValue("@last_initial", birthData.Name.LastInitial.ToString());
            command.Parameters.AddWithValue("@birth_day", birthData.Birthday);

            string returnMessage = "I dunno what happened.";

            try
            {
                connection.Open();
                if (command.ExecuteNonQuery() > 0)
                {
                    returnMessage = "Success!";
                }
            }
            catch (Exception e)
            {
                returnMessage = string.Format("There was an error. This was the message:\r\n\r\n{0}", e.Message);
            }
            finally
            {
                connection.Close();
            }

            return(returnMessage);
        }
Beispiel #2
0
        internal static IEnumerable <Models.BirthData> GetBirthData(string user, Dictionary <string, object> searchObject)
        {
            var theBirthData = new List <BirthData>();

            if (searchObject.ContainsKey("names"))
            {
                var names = searchObject["names"] as Name[];
                foreach (Name name in names)
                {
                    var birthData = new BirthData(name.FirstName, name.LastInitial, "03-22", "MM-DD");
                    theBirthData.Add(birthData);
                }
            }

            return(theBirthData);
        }
Beispiel #3
0
        public static string UpdateBirthData(string user, BirthData birthData)
        {
            SQLiteConnection connection = new SQLiteConnection(ConnectionString);
            string           updateText = @"UPDATE birthdata SET birthday=@birthday";
            SQLiteCommand    command    = new SQLiteCommand(updateText, connection);

            command.Parameters.AddWithValue("@birthday", birthData.Birthday);
            command = AddWhereConditions(
                command,
                new Dictionary <string, object>
            {
                { "owner", user },
                { "names", new Name[] { birthData.Name } }
            }
                );

            string returnMessage = "I dunno what happened.";

            try
            {
                connection.Open();
                if (command.ExecuteNonQuery() > 0)
                {
                    returnMessage = "Success!";
                }
            }
            catch (Exception e)
            {
                returnMessage = string.Format("There was an error. This was the message:\r\n\r\n{0}", e.Message);
            }
            finally
            {
                connection.Close();
            }

            return(returnMessage);
        }
 public Person()
 {
     Contacts = new List <Contact>();
     Birth    = new BirthData();
 }
Beispiel #5
0
        public Personography()
        {
            ClearChangeTrack();


            SourceRepository = new MoravianLivesGitHubFileStorage().ResolveStorage();

            var _pl = new MapDefinition
            {
                KeyMaps = new Dictionary <string, KeyMapConfiguration>
                {
                    {
                        "person.persName.forename",
                        new KeyMapConfiguration
                        {
                            Target  = "Name",
                            Handler = "HistoricString"
                        }
                    }
                }
            };

            // SourceRepository.StoreText("Projects/TEI_Memoirs", "ML_personography-transformMap.json", _pl.ToJson());

            Identifier(entry => entry.Id)
            .Configure(config =>
            {
                config.StaleRecordTimespan  = TimeSpan.FromSeconds(1);
                config.Collection           = "Bucknell.MoravianLives.GitHub";
                config.SourceIdentifierPath = "person.@xml:id";
                config.Set = "Personography";

                //config.MemberMapping = SourceRepository
                //    .GetText("Projects/TEI_Memoirs", "ML_personography-transformMap.json")
                //    .Result
                //    .FromJson<MapDefinition>();

                config.MemberMapping = _pl;
            })
            .SourceModel(raw =>
            {
                // First - Persons.
                var source = SourceRepository
                             .GetDynamic("Projects/TEI_Memoirs/personography/XML", "ML_personography.xml")
                             .Result;

                raw.Source = source;

                // Select and Typecast the entries.
                var items = ((JArray)source.SelectToken("TEI.text.body.listPerson"))
                            .Select(i => i.ToContentEntry(Configuration.SourceIdentifierPath))
                            .ToList();

                raw.Items = items;
            })
            .SourceValue((item, path) => item.Contents.SelectTokens(path).FirstOrDefault()?.ToString())
            .ConvertToModelType(item =>
            {
                if (item.Result == null)
                {
                    return;
                }

                item.Result.Success = false;

                switch (item.HandlerType)
                {
                case "HistoricString":
                    item.Result.Value   = (HistoricString)item.Source;
                    item.Result.Success = true;
                    break;

                case "Historical.Geography":
                    Geography tempValue = item.Source;
                    item.Result.Value   = tempValue;
                    item.Result.Success = true;
                    break;
                }
            })
            .ResolveReference(source =>
            {
                //Let's first try to identify if the item is already present on our database as a reference.
                // We'll receive a source item and try to resolve it to its 1:1 Data model.

                var sourceId = GetIdentifier(source);
                var domain   = $"{Configuration.Collection}.{Configuration.Set}";

                return(_personReference.ResolveReference(domain, sourceId, null));
            })
            .ComplexTransform(entry =>
            {
                if (entry.targetModel == null)
                {
                    return;
                }
                if (entry.sourceData?.Contents == null)
                {
                    return;
                }

                var a = entry.sourceData.Contents.ToJson();
                var b = entry.targetModel.ToJson();

                var source = entry.sourceData?.Contents;

                // First - name.

                var firstName = source?.StringValue("person.persName.forename");
                var lastName  = source?.StringValue("person.persName.surname.#text");

                var fullName = $"{firstName} {lastName}";

                // Birth

                var bd = new BirthData
                {
                    Token = source?.JValue(new[]
                    {
                        "person.birth.date[?(@.@type == 'birth' && @.@calendar == 'Gregorian' && @.@resp == 'memoir')]",
                        "person.birth.date[?(@.@type == 'birth' && @.@calendar == 'Gregorian')]",
                        "person.birth.date[?(@.@type == 'birth' && @.@calendar != 'Julian')]"
                    })
                };


                bd.Text      = bd.Token.StringValue("#text");
                bd.Timestamp = bd.Text;

                entry.targetModel.Name = $"{firstName} {lastName}";

                if (bd.Timestamp != null)
                {
                    var targetNameVariant = entry.targetModel.Name.Variants.FirstOrDefault().Value.Variants.FirstOrDefault();
                    if (targetNameVariant != null)
                    {
                        targetNameVariant.Period     = bd.Timestamp;
                        targetNameVariant.Period.End = null;

                        var nameResp = bd.Token.StringValue("@resp");
                        if (nameResp != null)
                        {
                            targetNameVariant.Comments ??= $"Source: {nameResp}";
                        }
                    }
                }

                var bpIdentifier = source.StringValue("person.birth.placeName.@ref");
                var bpName       = source.StringValue("person.birth.placeName.#text");

                if (bpIdentifier != null)
                {
                    bd.Location = _locationReference.ResolveReference(Placeography.DefaultDomain, bpIdentifier, bpName);
                }
            })
            .OnCommit(() =>
            {
                _personReference.Save();
                _locationReference.Save();
            });
        }
Beispiel #6
0
 /**
  * @apiGroup Birthday
  * @api {Post} /Birthday/Add Store a birthday for current user
  *
  * @apiParam {object} name				Name Info
  * @apiParam {string} name.firstname		The person's first name
  * @apiParam {string} name.lastinitial		The person's last initial
  * @apiParam {string} birthday			The person's birthday
  * @apiParam {string} birthdayformat		The optional format of the birthday (i.e. MM-DD)
  *
  * @apiSuccess {string} message			A description of what happened during the attempt to add the birthday
  */
 public object Add(BirthData birthData)
 {
     return(TheModel.Add(HttpContext.Current.User.Identity.Name, birthData));
 }