예제 #1
0
파일: CSVImport.cs 프로젝트: szwork2013/fms
        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);
        }
예제 #2
0
 private static PersonFactModel GetFactModel(PersonFact fact)
 {
     return(fact != null ? new PersonFactModel
     {
         Id = fact.Id,
         id_Person = fact.id_Person,
         id_FactType = fact.id_FactType,
         FactType = new PersonFactTypeModel {
             Id = fact.FactType.Id, Name = fact.FactType.Name, Descript = fact.FactType.Descript ?? ""
         },
         FactText = fact.FactText,
         Status = fact.Status,
         Source = fact.Source
     } : new PersonFactModel());
 }
예제 #3
0
        public static void AssertAreEqual(Term expected, PersonFact actual)
        {
            if (expected == null)
            {
                throw new ArgumentNullException("expected", "expected is null.");
            }
            if (actual == null)
            {
                throw new ArgumentNullException("actual", "actual is null.");
            }

            Assert.AreEqual <int>(expected.Id, actual.Id, "Id");
            Assert.AreEqual <string>(expected.Role, actual.FactType, "Role");
            Assert.AreEqual <DateTime>(expected.Start, actual.StartDate, "Start");
            Assert.AreEqual <DateTime>(expected.End, actual.EndDate, "End");
            Assert.AreEqual <string>(expected.Number.ToString(),
                                     actual.FactValue,
                                     "President number did not match fact value.");
        }
예제 #4
0
        public void RemoveFactById()
        {
            var removeThisId = 123;
            var fact0        = new PersonFact()
            {
                Id = removeThisId
            };
            var fact1 = new PersonFact()
            {
                Id = 456
            };

            SystemUnderTest.Facts.Add(fact0);
            SystemUnderTest.Facts.Add(fact1);

            SystemUnderTest.RemoveFact(removeThisId);

            Assert.IsFalse(SystemUnderTest.Facts.Contains(fact0),
                           "Should not contain this fact after remove.");
        }
예제 #5
0
 /// <see cref="IPersonRepository.UpdatePersonFact" />
 public PersonFact UpdatePersonFact(PersonFact fact, int userId)
 {
     if (fact.Id == 0)
     {
         db.Entry(fact).State = System.Data.Entity.EntityState.Added;
     }
     else if (fact.Id > 0)
     {
         var pr = db.PersonFacts.FirstOrDefault(o => o.Id == fact.Id);
         SaveLog(pr, fact, fact.id_Person, userId, LogType.Fact);
         db.Entry(pr).CurrentValues.SetValues(fact);
     }
     try
     {
         db.SaveChanges();
     }
     catch (Exception e)
     {
         return(null);
     }
     return(fact);
 }
예제 #6
0
 public static void AssertAreEqual(PersonFact expectedFact, string actualValue)
 {
     Assert.AreEqual <string>(expectedFact.FactValue, actualValue, "FactValue didn't match.");
 }
예제 #7
0
 public static void AssertAreEqual(string expected, PersonFact actual)
 {
     Assert.AreEqual <string>(expected, actual.FactValue, "FactValue was wrong.");
 }
예제 #8
0
 public static void AssertAreEqual(PersonFact expectedFact, DateTime actualValue)
 {
     Assert.AreEqual <DateTime>(expectedFact.StartDate, actualValue, "StartDate was wrong.");
 }
예제 #9
0
 public static void AssertAreEqual(DateTime expected, PersonFact actual)
 {
     Assert.AreEqual <DateTime>(expected, actual.StartDate, "StartDate was wrong.");
     Assert.AreEqual <DateTime>(expected, actual.EndDate, "EndDate was wrong.");
 }