Example #1
0
        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);
        }
Example #2
0
        private DocumentParameter GetOrCreateDocumentParameter(bool shouldSave, Document doc, PrmFactName paramName, string strValue = null, int?intValue = null, float?floatValue = null, DateTime?dateValue = null)
        {
            strValue = strValue ?? string.Empty;

            var docPrm = _db.DocumentParameters.SingleOrDefault(d => d.DocumentId == doc.Id && d.ParameterId == paramName.Id);

            if (docPrm == null)
            {
                docPrm = new DocumentParameter()
                {
                    DateValue   = dateValue,
                    IntValue    = intValue,
                    FloatValue  = floatValue,
                    StringValue = strValue,
                    DocumentId  = doc.Id,
                    ParameterId = paramName.Id
                };
                _db.DocumentParameters.Add(docPrm);
            }
            else
            {
                docPrm.DateValue   = dateValue;
                docPrm.IntValue    = intValue;
                docPrm.FloatValue  = floatValue;
                docPrm.StringValue = strValue;
                docPrm.DocumentId  = doc.Id;
                docPrm.ParameterId = paramName.Id;
            }

            if (shouldSave)
            {
                _db.SaveChanges();
            }
            return(docPrm);
        }