コード例 #1
0
        public HttpResponseMessage SaveResxEntries(UpdateTransaltionsRequest request)
        {
            try
            {
                var pid = request.PortalId ?? this.PortalId;
                if (!this.UserInfo.IsSuperUser && pid != this.PortalId)
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, AuthFailureMessage));
                }

                LanguageResourceMode resourceMode;
                Enum.TryParse(request.Mode, false, out resourceMode);

                if (!this.UserInfo.IsSuperUser && (resourceMode == LanguageResourceMode.Host || resourceMode == LanguageResourceMode.System))
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, AuthFailureMessage));
                }

                var language = this._localeController.GetLocale(request.Locale);

                switch (resourceMode)
                {
                case LanguageResourceMode.System:
                case LanguageResourceMode.Host:
                case LanguageResourceMode.Portal:
                    break;

                default:
                    return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "UnsupportedMode"));
                }

                if (language == null)
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                            string.Format(LocalizeString("InvalidLocale.ErrorMessage"), request.Locale)));
                }

                if (string.IsNullOrEmpty(request.ResourceFile))
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                            string.Format(LocalizeString("MissingResourceFileName"), request.Locale)));
                }

                this._selectedResourceFile = HttpContext.Current.Server.MapPath("~/" + request.ResourceFile);
                var message = this.SaveResourceFileFile(pid, resourceMode, request.Locale, request.Entries);
                return(this.Request.CreateResponse(HttpStatusCode.OK, new { Message = message }));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
コード例 #2
0
        public static ActionResult SaveResxEntries(int PortalId, UserInfo UserInfo, int lid, UpdateTransaltionsRequest request)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                Enum.TryParse(request.Mode, false, out LanguageResourceMode resourceMode);

                if (!UserInfo.IsSuperUser && resourceMode == LanguageResourceMode.Host)
                {
                    actionResult.AddError("AuthFailureMessage", Components.Constants.AuthFailureMessage);
                    return(actionResult);
                }

                Locale language = LocaleController.Instance.GetLocale(lid);

                switch (resourceMode)
                {
                case LanguageResourceMode.System:
                case LanguageResourceMode.Host:
                case LanguageResourceMode.Portal:
                    break;

                default:
                    actionResult.AddError("BadRequest", "UnsupportedMode");
                    return(actionResult);
                }

                if (language == null)
                {
                    actionResult.AddError("BadRequest", Localization.GetString("InvalidLocale.ErrorMessage", Locale_ResourceFile));
                    return(actionResult);
                }
                string resourceFile = request.ResourceFile.ToString();
                if (request.ResourceFile.ToString().IndexOf("_/", StringComparison.Ordinal) == 0)
                {
                    resourceFile = resourceFile.Substring(2);
                }
                if (string.IsNullOrEmpty(resourceFile))
                {
                    actionResult.AddError("BadRequest", string.Format(Localization.GetString("MissingResourceFileName", Locale_ResourceFile), language.Code));
                    return(actionResult);
                }

                selectedResourceFile = HttpContext.Current.Server.MapPath("~/" + resourceFile);
                string message = SaveResourceFileFile(PortalId, resourceMode, language.Code, request.Entries);
                actionResult.IsSuccess = true;
                actionResult.Message   = message;
                return(actionResult);
            }
            catch (Exception ex)
            {
                actionResult.AddError("", "", ex);
                return(actionResult);
            }
        }
コード例 #3
0
 public ActionResult SaveResxEntries(int lid, UpdateTransaltionsRequest request)
 {
     return(ResourcesManager.SaveResxEntries(PortalSettings.PortalId, UserInfo, lid, request));
 }