示例#1
0
        public object Post(CommunityCreateRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            try {
                context.Open();
                if (string.IsNullOrEmpty(request.Identifier))
                {
                    throw new Exception("Invalid request - missing community identifier");
                }

                context.LogInfo(this, string.Format("/community POST Identifier='{0}'", request.Identifier));

                ThematicCommunity domain = new ThematicCommunity(context);
                domain = request.ToEntity(context, domain);
                domain.Store();

                var  manager = Role.FromIdentifier(context, RoleTep.MANAGER);
                User usr     = User.FromId(context, context.UserId);
                manager.GrantToUser(usr, domain);

                domain.UpdateAppsLinks(request.Apps);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }

            return(new WebResponseBool(true));
        }
示例#2
0
        public object Put(CommunityUpdateRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            try {
                context.Open();
                if (string.IsNullOrEmpty(request.Identifier))
                {
                    throw new Exception("Invalid request - missing community identifier");
                }

                context.LogInfo(this, string.Format("/community PUT Identifier='{0}'", request.Identifier));

                ThematicCommunity domain = ThematicCommunity.FromIdentifier(context, request.Identifier);

                if (!domain.CanUserManage(context.UserId))
                {
                    throw new UnauthorizedAccessException("Action only allowed to manager of the domain");
                }

                domain = request.ToEntity(context, domain);
                domain.Store();

                domain.UpdateAppsLinks(request.Apps);
                domain.UpdateDomainsLinks(domain.Links);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }

            return(new WebResponseBool(true));
        }