示例#1
0
        public IActionResult Get()
        {
            RepositoryXml <User> userRepository = new RepositoryXml <User>(userXmlPath);
            IEnumerable <User>   users          = userRepository.GetAll();

            return(new ObjectResult(users));
        }
示例#2
0
        public IActionResult Get(string id)
        {
            RepositoryXml <User> userRepository = new RepositoryXml <User>(userXmlPath);
            User user = userRepository.Get(id);

            return(new ObjectResult(user));
        }
示例#3
0
        public IActionResult Post(string email, string password, string name)
        {
            RepositoryXml <User> userRepository = new RepositoryXml <User>(userXmlPath);
            User user = new User
            {
                Id           = Guid.NewGuid().ToString(),
                EmailAddress = email,
                Name         = name,
                Password     = password
            };

            bool success = false;

            try
            {
                userRepository.Add(user);
                success = true;
            }
            catch
            {
                success = false;
            }

            return(new ObjectResult(new { success }));
        }
示例#4
0
        public IActionResult Delete(string id)
        {
            RepositoryXml <User> userRepository = new RepositoryXml <User>(userXmlPath);

            userRepository.Remove(id);

            return(NoContent());
        }
示例#5
0
        public IActionResult Login(string email, string password)
        {
            // TODO: Handle login using tokens instead of user Id.

            RepositoryXml <User> userRepository = new RepositoryXml <User>(userXmlPath);
            User user = userRepository.GetAll().FirstOrDefault(x => x.EmailAddress.ToLower() == email.ToLower());

            bool success = user?.Password == password;

            if (success)
            {
                return(new ObjectResult(new { success, userId = user.Id }));
            }
            else
            {
                return(new ObjectResult(new { success }));
            }
        }
示例#6
0
        private static void CrudXml()
        {
            IRepository repository = new RepositoryXml();

            MenuCrud(repository);
        }
        private void Init(bool create)
        {
            this.DirectoryInfo.Refresh();

            this.repositoryBySuperId = new Dictionary <Guid, Repository>();

            this.unresolvedObjectTypeIds = new ArrayList();

            this.relationTypesWithNewIds = new HashSet <RelationType>();

            this.fileInfo = new FileInfo(Path.Combine(this.DirectoryInfo.FullName, FileName));
            this.fileInfo.Refresh();

            if (create)
            {
                if (!this.DirectoryInfo.Exists)
                {
                    this.DirectoryInfo.Create();
                }

                if (this.fileInfo.Exists)
                {
                    throw new Exception("Repository already exists");
                }

                this.xml = new RepositoryXml(this.fileInfo);
                this.xml.Save();
            }
            else
            {
                if (!this.fileInfo.Exists)
                {
                    throw new Exception("Repository not found in location " + this.fileInfo.Directory);
                }

                this.xml = RepositoryXml.Load(this.fileInfo);
            }

            if (Domain.Version.Major != this.Allors.Major && Domain.Version.Minor != this.Allors.Minor)
            {
                throw new Exception("Incompatible version. Excpected " + Domain.Version + ", but was " + this.Allors);
            }

            this.objectTypesDirectoryInfo = new DirectoryInfo(Path.Combine(this.DirectoryInfo.FullName, ObjectTypesDirectory));
            this.objectTypesDirectoryInfo.Refresh();
            if (!this.objectTypesDirectoryInfo.Exists)
            {
                this.objectTypesDirectoryInfo.Create();
            }

            this.inheritancesDirectoryInfo = new DirectoryInfo(Path.Combine(this.DirectoryInfo.FullName, InheritancesDirectory));
            this.inheritancesDirectoryInfo.Refresh();
            if (!this.inheritancesDirectoryInfo.Exists)
            {
                this.inheritancesDirectoryInfo.Create();
            }

            this.relationsDirectoryInfo = new DirectoryInfo(Path.Combine(this.DirectoryInfo.FullName, RelationTypesDirectory));
            this.relationsDirectoryInfo.Refresh();
            if (!this.relationsDirectoryInfo.Exists)
            {
                this.relationsDirectoryInfo.Create();
            }

            this.domainFileInfo = new FileInfo(Path.Combine(this.DirectoryInfo.FullName, DomainFileName));
            this.domainFileInfo.Refresh();

            if (this.domainFileInfo.Exists)
            {
                this.domainXml = DomainXml.Load(this.domainFileInfo);

                this.domain = Domain.Create(this.domainXml.id);

                this.domainXml.SyncToMeta(this.domain);

                foreach (IdrefXml partIdRef in this.domainXml.supers)
                {
                    var superDomainId          = new Guid(partIdRef.idRef);
                    var superDomainLocationXml = this.xml.LookupSuperDomainLocation(superDomainId);
                    if (superDomainLocationXml == null)
                    {
                        throw new ArgumentException("No location for super domain with id " + superDomainId);
                    }

                    var superDomainDirectoryInfo = new DirectoryInfo(Path.Combine(this.DirectoryInfo.FullName, superDomainLocationXml.location));
                    var repository = new Repository(superDomainDirectoryInfo);
                    this.AddSuper(repository);
                }
            }
            else
            {
                this.domain = Domain.Create();
            }

            this.inheritanceXmlsById  = new Dictionary <Guid, InheritanceXml>();
            this.objectTypeXmlsById   = new Dictionary <Guid, ObjectTypeXml>();
            this.relationTypeXmlsById = new Dictionary <Guid, RelationTypeXml>();

            // first create ObjectTypes
            foreach (var typeFileInfo in this.objectTypesDirectoryInfo.GetFiles(ObjectTypeWildcard))
            {
                var objectTypeXml = ObjectTypeXml.Load(typeFileInfo);
                this.objectTypeXmlsById[objectTypeXml.id] = objectTypeXml;

                this.domain.AddDeclaredObjectType(objectTypeXml.id);
            }

            // then sync ObjectTypes
            foreach (var objectTypeXml in this.objectTypeXmlsById.Values)
            {
                var contentsObjectType = (ObjectType)this.domain.Domain.Find(objectTypeXml.id);
                objectTypeXml.SyncToMeta(this, contentsObjectType);
            }

            foreach (var inheritanceFileInfo in this.inheritancesDirectoryInfo.GetFiles(InheritanceWildcard))
            {
                var inheritanceXml = InheritanceXml.Load(inheritanceFileInfo);
                this.inheritanceXmlsById[inheritanceXml.id] = inheritanceXml;

                var inheritance = this.domain.AddDeclaredInheritance(inheritanceXml.id);
                inheritanceXml.SyncToMeta(this, inheritance);
            }

            // first create RelationTypes
            foreach (var relationFileInfo in this.relationsDirectoryInfo.GetFiles(RelationTypeWildcard))
            {
                var relationTypeXml = RelationTypeXml.Load(relationFileInfo);
                this.relationTypeXmlsById[relationTypeXml.id] = relationTypeXml;

                var associationTypeId = Guid.Empty;
                var roleTypeId        = Guid.Empty;

                if (relationTypeXml.associationType != null)
                {
                    associationTypeId = relationTypeXml.associationType.id;
                }

                if (relationTypeXml.roleType != null)
                {
                    roleTypeId = relationTypeXml.roleType.id;
                }

                var newIds = false;

                if (associationTypeId == Guid.Empty)
                {
                    associationTypeId = Guid.NewGuid();
                    newIds            = true;
                }

                if (roleTypeId == Guid.Empty)
                {
                    roleTypeId = Guid.NewGuid();
                    newIds     = true;
                }

                var relationType = this.domain.AddDeclaredRelationType(relationTypeXml.id, associationTypeId, roleTypeId);

                if (newIds)
                {
                    this.relationTypesWithNewIds.Add(relationType);
                }
            }

            // then sync RelationTypes
            foreach (var relationTypeXml in this.relationTypeXmlsById.Values)
            {
                var contentsRelationType = (RelationType)this.domain.Domain.Find(relationTypeXml.id);
                relationTypeXml.SyncToMeta(this, contentsRelationType);
            }

            this.templates = new List <Template>();

            if (!this.TemplatesDirectoryInfo.Exists)
            {
                this.TemplatesDirectoryInfo.Create();
            }

            foreach (var configurationFileInfo in this.TemplatesDirectoryInfo.GetFiles(Template.TemplatesWildcard))
            {
                var template = new Template(this, configurationFileInfo);
                this.templates.Add(template);
            }

            this.domain.MetaObjectChanged += this.DomainMetaObjectChanged;
            this.domain.MetaObjectDeleted += this.DomainMetaObjectDeleted;

            // set defaults
            if (!this.domain.ExistId)
            {
                this.domain.Id = Guid.NewGuid();
            }

            this.domain.SendChangedEvent();
        }