Пример #1
0
        public void AccessLog_Get_External()
        {
            var externalId = "Access50";
            var id         = 1;
            var locationId = 1;

            using (var context = new RSMDB.RSMDataModelDataContext())
            {
                var person = DataFactory.CreatePerson("first", "last", "middle");
                context.Persons.InsertOnSubmit(person);
                context.SubmitChanges();
                var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, person.PersonID);
                context.ExternalApplicationKeys.InsertOnSubmit(keys);

                var location = DataFactory.CreateLocation("Location1");
                context.Locations.InsertOnSubmit(location);
                context.SubmitChanges();
                locationId = location.LocationID;

                var portal = DataFactory.CreatePortal("Portal1", locationId);
                context.Portals.InsertOnSubmit(portal);
                context.SubmitChanges();
                keys = DataFactory.CreateExternalApplicationKey(EntityType.Portal, externalId, S2In.Id, portal.Id);
                context.ExternalApplicationKeys.InsertOnSubmit(keys);

                var reader = DataFactory.CreateReader("Reader50", portal.Id);
                context.Readers.InsertOnSubmit(reader);
                context.SubmitChanges();
                keys = DataFactory.CreateExternalApplicationKey(EntityType.Reader, externalId, S2In.Id, reader.Id);
                context.ExternalApplicationKeys.InsertOnSubmit(keys);

                var access = DataFactory.CreateAccessHistory("Access50", person.PersonID, portal.Id, reader.Id, 30);
                context.AccessHistories.InsertOnSubmit(access);
                context.SubmitChanges();
                keys = DataFactory.CreateExternalApplicationKey(EntityType.AccessLog, externalId, S2In.Id, access.Id);
                context.ExternalApplicationKeys.InsertOnSubmit(keys);
                context.SubmitChanges();

                id = access.Id;
            }

            var criteria = new AccessLog
            {
                EntityType       = EntityType.AccessLog,
                ExternalSystemId = S2In.Id,
                ExternalId       = externalId
            };

            var result = criteria.Get();

            Assert.IsNotNull(result, "Missing results");
            Assert.IsTrue(result.Succeeded, result.ToString());
            Assert.IsNotNull(result.Entity, "Missing entity");
            Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity");
            Assert.IsTrue(result.Entity.EntityType == EntityType.AccessLog, "EntityType mismatch");
            Assert.IsTrue((result.Entity as ExternalEntity).InternalId == id, "Incorrect id for entity");
        }
Пример #2
0
        public static Result <AccessLog> Add(this AccessLog from)
        {
            var result = Result <AccessLog> .Success();

            var exists = from.Get();

            if (exists.Succeeded)
            {
                exists.Set(ResultType.Warning, "AccessLog already exists {0}", from.InternalId.ToString());
                return(exists);
            }

            try
            {
                using (var db = new RSMDB.RSMDataModelDataContext())
                {
                    using (var transaction = new TransactionScope(TransactionScopeOption.Required, TransactionTimeout))
                    {
                        var row = from.Insert(db);
                        if (row == null)
                        {
                            return(result.Fail("Add AccessLog failed"));
                        }

                        from.InternalId = row.Id;
                        from.KeysAdded  = DateTime.Now;

                        var keys = (from as ExternalEntity).InsertKeys(db);

                        if (row == null || keys == null)
                        {
                            return(result.Fail("Add AccessLog failed"));
                        }

                        result.Entity = row.ToModel();
                        keys.ToModel(result.Entity);

                        transaction.Complete();
                    }
                }
            }
            catch (Exception e)
            {
                return(result.Set(ResultType.TechnicalError, e, "Add AccessLog failed. {0}", e.ToString()));
            }

            return(result);
        }