Exemple #1
0
        /// <summary>
        /// Method to get a list of associated Sections of an User.
        /// </summary>
        /// <returns>WPF Web Server response data of list of Sections.</returns>
        public override WebServerResponseData Index()
        {
            log.Debug($"{GetType().Name}.{MethodBase.GetCurrentMethod().Name}");
            log.Info($"{MethodBase.GetCurrentMethod().Name} : Serving section request. Please wait...");

            if (!IsAuth())
            {
                log.Info($"{MethodBase.GetCurrentMethod().Name} : Return response user not auth.");
                return(ResponseNotAuth());
            }

            try
            {
                var a = Uri.QueryString;

                // Check if request params are correct.
                if (Uri.QueryString.Count == 0)
                {
                    log.Info($"{MethodBase.GetCurrentMethod().Name} : Request empty.");
                    log.Info($"{MethodBase.GetCurrentMethod().Name} : Return response => Section not found or doesn't exists.");
                    return(ResponseError404("Section not found or doesn't exists."));
                }

                // Check if request params are correct.
                if (!Uri.QueryString.Keys.Cast <string>().Contains("id"))
                {
                    log.Info($"{MethodBase.GetCurrentMethod().Name} : Request param [id] not fount.");
                    log.Info($"{MethodBase.GetCurrentMethod().Name} : Return response => Section not found or doesn't exists.");
                    return(ResponseError404("Section not found or doesn't exists."));
                }

                int id = int.Parse(Uri.QueryString["id"]);

                // Get user and dependencies.
                UserEntity    user   = GetAuthUser();
                SectionEntity entity = RouteHelper.GetUserSection(id, user);

                // Check if folder is associated or not.
                if (entity == null)
                {
                    log.Info($"{MethodBase.GetCurrentMethod().Name} : Section not found in user association.");
                    log.Info($"{MethodBase.GetCurrentMethod().Name} : Return response Section not found or doesn't exists.");
                    return(ResponseError404("Section not found or doesn't exists."));
                }

                // Ensure to select dependencies.
                log.Info("Api : Creating section informations. Please wait...");
                entity = Database.Sections.SingleOrNull
                         (
                    new SectionOptionsSelect
                {
                    PrimaryKey   = entity.PrimaryKey,
                    Dependencies = new List <EnumEntitiesDependencies> {
                        EnumEntitiesDependencies.All
                    }
                }
                         );

                Content["Authentication"] = true;
                Content["Response"]       = ConvertJsonAuthSection(entity);
                return(ResponseContentToJson());
            }
            catch (Exception e)
            {
                log.Fatal($"{MethodBase.GetCurrentMethod().Name} : Serving section request failed.", e);
                return(ResponseError500());
            }
        }