Exemplo n.º 1
0
        /// <summary>
        /// Delete the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Delete(CommunityDeleteRequest request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/community/{{Identifier}} DELETE Identifier='{0}'", request.Identifier));
                ThematicCommunity domain = ThematicCommunity.FromIdentifier(context, request.Identifier);
                if (domain.CanUserManage(context.UserId))
                {
                    domain.Delete();
                }
                else
                {
                    throw new UnauthorizedAccessException(CustomErrorMessages.ADMINISTRATOR_ONLY_ACTION);
                }
                context.LogDebug(this, string.Format("Community {0} deleted by user {1}", domain.Identifier, User.FromId(context, context.UserId).Username));
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Exemplo n.º 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));
        }