public PersonViewModel(Person p) : this() { Id = p.Id; Name = p.Name; Birthday = p.Birthday; Category = p.Category; Type = p.Type; }
public IPerson FactoryMethod(Action<IPerson> initializer) { // Create a new Person var person = new Person(); // Apply our initializer properties initializer(person); // Return return person; }
protected override void OnInit(System.EventArgs e) { base.OnInit(e); Configuration configuration = new Configuration(); configuration.Configure(); try { _log.Debug("Creating database..."); RecreateDatabase(configuration); _log.Debug("...database created"); } catch (HibernateException exc) { _log.Fatal("Did you forget to modify 'connection.connection_string' in web.config to point to a valid database?", exc); return; } using (ISessionFactory factory = configuration.BuildSessionFactory()) { int homePhoneNumberId; int personId; using (ISession session = factory.OpenSession()) { Person person; PhoneNumber homePhoneNumber; _log.Debug("Writing data to database..."); using (ITransaction trans = session.BeginTransaction()) { person = new Person(); person.Name = "Lazy"; session.Save(person); homePhoneNumber = new PhoneNumber(); homePhoneNumber.Number = "867-5309"; homePhoneNumber.PhoneType = "Cell"; homePhoneNumber.Person = person; session.Save(homePhoneNumber); trans.Commit(); } _log.Debug("...data written"); personId = person.Id; homePhoneNumberId = homePhoneNumber.Id; } try { using (ISession session = factory.OpenSession()) { Person lazyPerson = session.Load<Person>(personId); _log.Debug("Lazy loading an entity..."); string lazyName = lazyPerson.Name; _log.Debug("...entity loaded"); } using (ISession session = factory.OpenSession()) { PhoneNumber home = session.Get<PhoneNumber>(homePhoneNumberId); _log.Debug("Lazy loading a related entity..."); Person lazyPerson = home.Person; _log.Debug("...related entity loaded"); } _log.Debug("Comment out 'proxyfactory.factory_class' in web.config and try again."); } catch (HibernateException exc) { _log.Error("Cannot generate lazy loading proxies in a Medium Trust environment. Try using NHibernate.ProxyGenerators :)", exc); } } }
private void UpdatePersonFacts(Person person, IDictionary<string, FactViewModel> facts) { var names = _repParameterFactNames.FindAll(p => p.Category == ParameterCategory.Person && p.IsFact == true).ToList(); var allFacts = _repPersonFacts.FindAll(p => p.PersonId == person.Id).ToList(); var list = new List<PersonFact>(); foreach (var key in facts.Keys) { var fact = facts[key]; var fn = names.Single(f => string.Compare(f.Name, key, true) == 0); var dbFact = allFacts.Where(p => p.FactId == fn.Id).OrderByDescending(f => f.FactDate).FirstOrDefault(); if (dbFact == null || dbFact.FloatValue != fact.FloatValue || dbFact.IntValue != fact.MiscId || dbFact.StringValue != fact.StringValue || dbFact.DateValue != fact.DateValue) { dbFact = new PersonFact { FactDate = DateTime.Now, FactId = fn.Id, PersonId = person.Id, DateValue = fact.DateValue, FloatValue = fact.FloatValue, IntValue = fact.MiscId, StringValue = fact.StringValue }; list.Add(dbFact); } }; _repPersonFacts.AddRange(list); }
private void UpdatePersonParams(Person person, IDictionary<string, ParameterViewModel> parameters) { var names = _repParameterFactNames.FindAll(p => p.Category == ParameterCategory.Person && p.IsFact == false).ToList(); var allPrms = _repPersonParams.FindAll(p => p.PersonId == person.Id).ToList(); var list = new List<PersonParameter>(); foreach (var key in parameters.Keys) { var prm = parameters[key]; var pn = names.Single(p => string.Compare(p.Name, key, true) == 0); var dbParam = allPrms.SingleOrDefault(p => p.ParameterId == pn.Id); if (dbParam != null) { dbParam.DateValue = prm.DateValue; dbParam.FloatValue = prm.FloatValue; dbParam.IntValue = prm.MiscId; dbParam.StringValue = prm.StringValue; } else { dbParam = new PersonParameter { ParameterId = pn.Id, PersonId = person.Id, DateValue = prm.DateValue, FloatValue = prm.FloatValue, IntValue = prm.MiscId, StringValue = prm.StringValue }; } list.Add(dbParam); }; _repPersonParams.AddRange(list.Where(p => p.Id == 0).AsEnumerable()); _repPersonParams.UpdateRange(list.Where(p => p.Id != 0).AsEnumerable()); }
public async Task<HttpResponseMessage> CreatePerson([FromBody] Person p) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (_repPeople.GetAll().Any(pr => (pr.Name == p.Name && pr.Birthday == p.Birthday && pr.Category == PersonCategory.Individual) || (pr.Code == p.Code && pr.Name == p.Name && pr.Category == PersonCategory.Legal))) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException("Анкета с такими данными уже существует")); } var person = new Person { Name = p.Name, Birthday = p.Birthday, Code = p.Code, Type = p.Type, Category = p.Category }; await _repPeople.AddAsync(person); return Request.CreateResponse(HttpStatusCode.OK, person); }
private PersonFact GetOrCreatePersonFact(bool shouldSave, Person person, PrmFactName factName, string strValue = null, int? intValue = null, float? floatValue = null, DateTime? dateValue = null) { var fact = _db.PersonFacts.SingleOrDefault(f => f.PersonId == person.Id && f.FactId == factName.Id && f.StringValue == strValue && f.IntValue == intValue && f.FloatValue == floatValue && f.DateValue == dateValue); if (fact == null) { fact = new PersonFact() { PersonId = person.Id, FactId = factName.Id, FactDate = DateTime.Now, StringValue = strValue, IntValue = intValue, FloatValue = floatValue, DateValue = dateValue }; _db.PersonFacts.Add(fact); } else { fact.FactDate = DateTime.Now; } if (shouldSave) { _db.SaveChanges(); } return fact; }
private Document GetOrCreateDocument(Person person, DocumentType type, string number, string userid) { var doc = _db.Documents.SingleOrDefault(d => d.Number == number && d.Type == type); if (doc == null) { var now = DateTime.Now; doc = new Document() { ApplicantPersonId = (person.Type == PersonType.Applicant) ? person.Id : (int?)null, HostPersonId = (person.Type == PersonType.Host) ? person.Id : (int?)null, Number = number, CreatedById = userid, UpdatedById = userid, CreatedDate = now, UpdatedDate = now, Type = type }; _db.Documents.Add(doc); _db.SaveChanges(); } return doc; }
private Person GetOrCreatePerson(string name, DateTime birthday, PersonCategory category, PersonType type) { var person = _db.People.SingleOrDefault(p => p.Name == name && p.Birthday == birthday); if (person == null) { person = new Person { Name = name, Birthday = birthday, Type = type, Category = category }; _db.People.Add(person); _db.SaveChanges(); } return person; }
public static void AddPeople(Chapter chapter, ICollection<ChapterPersonRel> list) { foreach (var r in list) { var p = r.BeholderPerson; Gender gender; Enum.TryParse(p.CommonPerson.GenderId.ToString(), out gender); MaritialStatus maritialStatus; Enum.TryParse(p.CommonPerson.MaritialStatusId.ToString(), out maritialStatus); var person = new Person() { Id = p.CommonPersonId, PrefixId = p.CommonPerson.PrefixId, SuffixId = p.CommonPerson.SuffixId, FirstName = p.CommonPerson.FName, MiddleName = p.CommonPerson.MName, LastName = p.CommonPerson.LName, DOB = p.CommonPerson.DOB, ActualDOB = p.CommonPerson.ActualDOBIndicator, DeceasedDate = p.CommonPerson.DeceasedDate, ActualDeceasedDate = p.CommonPerson.ActualDeceasedDateIndicator, Height = p.CommonPerson.Height, Weight = p.CommonPerson.Weight, SSN = p.CommonPerson.SSN, LicenseType = Helpers.GetLicenseType(p.CommonPerson.LicenseTypeId), DriversLicenseNumber = p.CommonPerson.DriversLicenseNumber, DriversLicenseStateId = p.CommonPerson.DriversLicenseStateId, MaritialStatus = maritialStatus, Gender = gender, HairColorId = p.CommonPerson.HairColorId, HairPatternId = p.CommonPerson.HairPatternId, EyeColorId = p.CommonPerson.EyeColorId, RaceId = p.CommonPerson.RaceId, SecurityLevel = p.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open, DistinguishableMarks = p.DistinguishableMarks, Movement = Helpers.ConvertMovementId(p.MovementClassId), DateCreated = p.CommonPerson.DateCreated, DateUpdated = p.CommonPerson.DateModified, LogEntries = new List<PersonLogEntry>() }; person.LogEntries.Add(new PersonLogEntry() { Note = $"Added person {person.ReverseFullName}" }); chapter.Persons.Add(person); chapter.LogEntries.Add(new ChapterLogEntry() { Note = $"Added Chapter {chapter.Name} person relationship {person.ReverseFullName}" }); } }
private PersonFact UpdateOrCreatePersonFact(Person person, ParameterName factName, string strValue = null, int? intValue = null, float? floatValue = null, DateTime? dateValue = null) { strValue = NormalizeString(strValue, true); var fact = _db.PersonFacts.FirstOrDefault(f => f.PersonId == person.Id && f.FactId == factName.Id && f.StringValue == strValue && f.IntValue == intValue && f.FloatValue == floatValue && f.DateValue == dateValue); if (fact == null) { fact = new PersonFact() { PersonId = person.Id, FactId = factName.Id, FactDate = DateTime.Now, StringValue = strValue, IntValue = intValue, FloatValue = floatValue, DateValue = dateValue }; _db.PersonFacts.Add(fact); } else { fact.FactDate = DateTime.Now; }; _db.SaveChanges(); return fact; }
private Document UpdateOrCreateDocumentByApplicantDateNumber(Person person, DocumentType type, DateTime date, string number, string userid) { number = NormalizeString(number, false); var doc = _db.Documents.SingleOrDefault(d => d.CreatedDate == date && d.Number == number && d.ApplicantPersonId == person.Id && d.Type == type); if (doc == null) { doc = new Document() { ApplicantPersonId = person.Id, HostPersonId = null, Number = number, CreatedById = userid, UpdatedById = userid, CreatedDate = date, UpdatedDate = DateTime.Now, Type = type }; _db.Documents.Add(doc); _db.SaveChanges(); } return doc; }
private Document UpdateOrCreateDocumentByNumber(Person applicant, Person host, DocumentType type, string number, string userid) { number = NormalizeString(number, false); var doc = _db.Documents.SingleOrDefault(d => d.Number == number && d.Type == type); if (doc == null) { var now = DateTime.Now; doc = new Document() { ApplicantPersonId = applicant.Id, HostPersonId = host.Id, Number = number, CreatedById = userid, UpdatedById = userid, CreatedDate = now, UpdatedDate = now, Type = type }; _db.Documents.Add(doc); _db.SaveChanges(); } return doc; }
private Person GetOrCreatePerson(string name, string code, PersonCategory category, PersonType type) { var person = _db.People.SingleOrDefault(p => p.Name == name && p.Code == code); if (person == null) { person = new Person { Name = name, Type = type, Category = category, Code = code }; _db.People.Add(person); _db.SaveChanges(); } return person; }