Exemple #1
0
    public void AddLink(LinkBuilder linkInfo)
    {
        var linkContainer = new LinkContainer(linkInfo, Schemes[linkInfo.SourceName], Schemes[linkInfo.TargetName]);

        Links.Add(linkContainer);

        linkContainer.Design = SchemeDesigner.Instance.CreateLinkDesign(linkContainer);
    }
        public IHttpActionResult GetUsers()
        {
            Exception ex = null;
            LinkContainer <UserViewModel> users = null;

            try {
                var requestUri = Request.RequestUri;
                users = new LinkContainer <UserViewModel>(_dataConnector.GetUsers().Select(x => new UserViewModel(x)).ToList());

                foreach (var user in users.Items)
                {
                    user.AddLink(new Link(requestUri, HttpMethod.Get, RelValues.Self, ActionValues.Load, "auth/user/" + user.UserId));
                }

                users.AddLink(new Link(requestUri, HttpMethod.Post, RelValues.Child, ActionValues.Create, "auth/user"));
            } catch (Exception e) {
                ex = e;
            }

            return(GetHttpActionResult(users, ex));
        }
Exemple #3
0
        public IHttpActionResult GetEvents()
        {
            Exception ex = null;
            LinkContainer <EventViewModel> result = null;

            try {
                var events = _dataProvider.GetEntities <Event>().Select(x => new EventViewModel(x)).ToList();
                result = new LinkContainer <EventViewModel>(events);

                result.AddLink(new Link(Request.RequestUri, HttpMethod.Get, RelValues.Self, ActionValues.Refresh, "Events"));
                result.AddLink(new Link(Request.RequestUri, HttpMethod.Post, RelValues.Child, ActionValues.Save, "Events"));

                foreach (var item in result.Items)
                {
                    item.AddLink(new Link(Request.RequestUri, HttpMethod.Get, RelValues.Self, ActionValues.Load, "Events/" + item.Id));
                }
            } catch (Exception e) {
                ex = e;
            }

            return(GetHttpActionResult(result, ex));
        }
Exemple #4
0
        public IHttpActionResult GetInstances()
        {
            Exception ex = null;
            LinkContainer <InstanceViewModel> instances = null;

            try {
                var requestUri = Request.RequestUri;
                // todo -> save in auth token after authorization is implemented
                var cultureInfo = new CultureInfo("de-CH");
                instances = new LinkContainer <InstanceViewModel>(_dataConnector.GetInstances().Select(x => new InstanceViewModel(x, cultureInfo)).ToList());

                foreach (var instance in instances.Items)
                {
                    instance.AddLink(new Link(requestUri, HttpMethod.Get, RelValues.Self, ActionValues.Load, "environment/instance/" + instance.InstanceId));
                }

                instances.AddLink(new Link(requestUri, HttpMethod.Post, RelValues.Child, ActionValues.Create, "environment/instance"));
            } catch (Exception e) {
                ex = e;
            }

            return(GetHttpActionResult(instances, ex));
        }
        public IEnumerable <Link> CreateLinks(Method method, WhoAreWeViewModel content = null)
        {
            var linkContainer = new LinkContainer();

            if (_urlHelper != null)
            {
                var getAll = new Link()
                {
                    Method = "GET", Rel = "get all 'who are we'", Href = _urlHelper.Link("GetAllWhoAreWe", new { })
                };
                var insert = new Link()
                {
                    Method = "POST", Rel = "insert ''who are we''", Href = _urlHelper.Link("InsertWhoAreWe", new { })
                };

                var getById = new Link();
                var update  = new Link();
                var delete  = new Link();

                if (content != null)
                {
                    getById = new Link()
                    {
                        Method = "GET", Rel = "get ''who are we'' by id", Href = _urlHelper.Link("GetWhoAreWeById", new { id = content.Id })
                    };
                    update = new Link()
                    {
                        Method = "PUT", Rel = "update ''who are we''", Href = _urlHelper.Link("UpdateWhoAreWe", new { id = content.Id })
                    };
                    delete = new Link()
                    {
                        Method = "DELETE", Rel = "delete ''who are we''", Href = _urlHelper.Link("DeleteWhoAreWe", new { id = content.Id })
                    };
                }

                switch (method)
                {
                case Method.GetAll:
                    linkContainer.AddLink(getAll);
                    linkContainer.AddLink(insert);
                    break;

                case Method.Get:
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Post:
                    linkContainer.AddLink(insert);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Put:
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(delete);
                    break;
                }
                linkContainer.Links[0].Rel = "self";
            }
            return(linkContainer.Links);
        }
Exemple #6
0
        public IEnumerable <Link> CreateLinks(Method method, CollaboratorViewModel content = null)
        {
            var linkContainer = new LinkContainer();

            if (_urlHelper != null)
            {
                var getAll = new Link()
                {
                    Method = "GET", Rel = "get all collaborators pages", Href = _urlHelper.Link("GetAllCollaboratorsPages", new { })
                };
                var insert = new Link()
                {
                    Method = "POST", Rel = "insert collaborator page", Href = _urlHelper.Link("InsertCollaboratorPage", new { })
                };

                var getById = new Link();
                var update  = new Link();
                var delete  = new Link();

                if (content != null)
                {
                    getById = new Link()
                    {
                        Method = "GET", Rel = "get collaborator page by id", Href = _urlHelper.Link("GetCollaboratorPageById", new { id = content.Id })
                    };
                    update = new Link()
                    {
                        Method = "PUT", Rel = "update collaborator page", Href = _urlHelper.Link("UpdateCollaboratorPage", new { id = content.Id })
                    };
                    delete = new Link()
                    {
                        Method = "DELETE", Rel = "delete collaborator page", Href = _urlHelper.Link("DeleteCollaboratorPage", new { id = content.Id })
                    };
                }

                switch (method)
                {
                case Method.GetAll:
                    linkContainer.AddLink(getAll);
                    linkContainer.AddLink(insert);
                    break;

                case Method.Get:
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Post:
                    linkContainer.AddLink(insert);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Put:
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(delete);
                    break;
                }
                linkContainer.Links[0].Rel = "self";
            }
            return(linkContainer.Links);
        }
Exemple #7
0
        public IEnumerable <Link> CreateLinks(Method method, MenuViewModel content = null)
        {
            var linkContainer = new LinkContainer();

            if (_urlHelper != null)
            {
                var getAll = new Link()
                {
                    Method = "GET", Rel = "get all menus", Href = _urlHelper.Link("GetAllMenus", new { })
                };
                var insert = new Link()
                {
                    Method = "POST", Rel = "insert menu", Href = _urlHelper.Link("InsertMenu", new { })
                };

                var getById = new Link();
                var update  = new Link();
                var delete  = new Link();

                if (content != null)
                {
                    getById = new Link()
                    {
                        Method = "GET", Rel = "get menu by id", Href = _urlHelper.Link("GetMenuByInstitution", new { })
                    };
                    update = new Link()
                    {
                        Method = "PUT", Rel = "update menu", Href = _urlHelper.Link("UpdateMenu", new { id = content.Id })
                    };
                    delete = new Link()
                    {
                        Method = "DELETE", Rel = "delete menu", Href = _urlHelper.Link("DeleteMenu", new { id = content.Id })
                    };
                }

                switch (method)
                {
                case Method.GetAll:
                    linkContainer.AddLink(getAll);
                    linkContainer.AddLink(insert);
                    break;

                case Method.Get:
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Post:
                    linkContainer.AddLink(insert);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Put:
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(delete);
                    break;
                }
                linkContainer.Links[0].Rel = "self";
            }
            return(linkContainer.Links);
        }