コード例 #1
0
        /// <summary>
        /// The index page.
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> Index()
        {
            if (Session["ConnectedUser"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            bool isAuthorizedUser = await AuthorizeUserAttribute.AuthorizeSettings();

            if (!isAuthorizedUser)
            {
                return(RedirectToAction("NoAccess", "Errors"));
            }

            LanguageViewData   languageViewData = new LanguageViewData();
            LanguageResultData result           =
                await WebApiClient.GetAsync <LanguageResultData>(Constant.WebApiControllerLanguages,
                                                                 Constant.WebApiLanguageList);

            if (result?.LanguageDtoList != null && result.OperationSuccess)
            {
                languageViewData.Languages = result.LanguageDtoList;
            }

            ViewBag.Settings = "active";
            return(View(languageViewData));
        }
コード例 #2
0
        public async Task <OmsJsonResult> UpdateLanguage(UpdateLanguageFormData languageFormData)
        {
            LanguageRequestData request = languageFormData.ToUpdateRequestData();
            LanguageResultData  result  = await WebApiClient.PostFormJsonAsync <LanguageRequestData, LanguageResultData>(Constant.WebApiControllerLanguages, Constant.WebApiUpdateLanguage, request);

            JsonReturnData data = new JsonReturnData();

            if (result == null)
            {
                data.ErrorMessage     = SharedResources.ServerError;
                data.OperationSuccess = false;
            }
            else if (!result.OperationSuccess && result.Errors != null && result.Errors.Count > 0)
            {
                data.ErrorMessage     = result.Errors.First();
                data.OperationSuccess = false;
            }
            else if (result.OperationSuccess)
            {
                if (!Directory.Exists(Server.MapPath($"~/Images/Languages/" + languageFormData.LanguageId)))
                {
                    Directory.CreateDirectory(
                        Server.MapPath($"~/Images/Languages/" + languageFormData.LanguageId));
                }
                languageFormData.LanguagePicture?.SaveAs(
                    Server.MapPath($"~/Images/Languages/" + languageFormData.LanguageId + $"/") +
                    languageFormData.LanguagePicture.FileName);

                data.SuccessMessage   = LanguageResources.ok;
                data.OperationSuccess = true;
            }
            return(new OmsJsonResult(data));
        }
コード例 #3
0
        /// <summary>
        /// Get news form to create.
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> GetCreateNews()
        {
            NewsFormData newsFormData = new NewsFormData
            {
                NewsDate         = DateTime.Now.ToString("dd/MM/yyyy"),
                TranslationsList = new List <NewsTranslationFormData>()
            };
            LanguageResultData result =
                await WebApiClient.GetAsync <LanguageResultData>(Constant.WebApiControllerLanguages,
                                                                 Constant.WebApiLanguageList);

            if (result != null && result.OperationSuccess && result.LanguageDtoList != null)
            {
                foreach (var language in result.LanguageDtoList)
                {
                    var translation = new NewsTranslationFormData
                    {
                        LanguagePrefix = language.LanguagePrefix,
                        LanguageId     = language.LanguageId,
                    };
                    newsFormData.TranslationsList.Add(translation);
                }
            }
            ViewBag.Action = "CreateNews";
            return(PartialView("Partials/_ManageNews", newsFormData));
        }
コード例 #4
0
        /// <summary>
        /// Get country form to create.
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> GetCreateCountry()
        {
            CreateCountryFormData countryFormData =
                new CreateCountryFormData {
                TranslationsList = new List <CountryTranslationFormData>()
            };
            LanguageResultData result =
                await WebApiClient.GetAsync <LanguageResultData>(Constant.WebApiControllerLanguages,
                                                                 Constant.WebApiLanguageList);

            if (result != null && result.OperationSuccess && result.LanguageDtoList != null)
            {
                foreach (var language in result.LanguageDtoList)
                {
                    var translation = new CountryTranslationFormData
                    {
                        LanguagePrefix = language.LanguagePrefix,
                        LanguageId     = language.LanguageId,
                    };
                    countryFormData.TranslationsList.Add(translation);
                }
            }
            ViewBag.Action = "CreateCountry";
            return(PartialView("Partials/_CreateCountry", countryFormData));
        }
コード例 #5
0
        /// <summary>
        /// Get the view to create  sheet.
        /// </summary>
        /// <param name="countryId">the activivity id</param>
        /// <returns>action view result.</returns>
        public async Task <ActionResult> GetCreateSheet(int countryId)
        {
            SheetFormData sheetFormData = new SheetFormData
            {
                TranslationsList = new List <SheetTranslationFormData>(),
                CountryId        = countryId
            };

            LanguageResultData result = await WebApiClient.GetAsync <LanguageResultData>(Constant.WebApiControllerLanguages, Constant.WebApiLanguageList);

            if (result != null && result.OperationSuccess && result.LanguageDtoList != null)
            {
                foreach (var language in result.LanguageDtoList)
                {
                    var translation = new SheetTranslationFormData
                    {
                        LanguagePrefix = language.LanguagePrefix,
                        LanguageId     = language.LanguageId,
                    };
                    sheetFormData.TranslationsList.Add(translation);
                }
            }
            ViewBag.Action = "CreateSheet";
            return(PartialView("Partials/_ManageSheet", sheetFormData));
        }
コード例 #6
0
        /// <summary>
        /// language section list.
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> GetLanguages()
        {
            LanguageViewData   languageViewData = new LanguageViewData();
            LanguageResultData result           = await WebApiClient.GetAsync <LanguageResultData>(Constant.WebApiControllerLanguages, Constant.WebApiLanguageList);

            if (result?.LanguageDtoList != null && result.OperationSuccess)
            {
                languageViewData.Languages = result.LanguageDtoList;
            }

            return(PartialView("Partials/_LanguagesList", languageViewData));
        }
コード例 #7
0
        /// <summary>
        /// From Langue result data to connection form data
        /// </summary>
        /// <param name="resultData">the Langue result data from web api.</param>
        /// <returns>the form data.</returns>
        public static UpdateLanguageFormData ToUpdateLangueFormData(this LanguageResultData resultData)
        {
            UpdateLanguageFormData formData = new UpdateLanguageFormData();

            if (resultData?.LanguageDto != null)
            {
                formData = new UpdateLanguageFormData
                {
                    LanguageId     = resultData.LanguageDto.LanguageId,
                    LanguagePrefix = resultData.LanguageDto.LanguagePrefix
                };
            }
            return(formData);
        }
コード例 #8
0
        /// <summary>
        /// The update langue view.
        /// </summary>
        /// <param name="languageId">the langue id to update.</param>
        /// <returns>updating view</returns>
        public async Task <ActionResult> GetUpdateLanguage(int languageId)
        {
            UpdateLanguageFormData languageFormData = new UpdateLanguageFormData();
            LanguageRequestData    findRequest      = new LanguageRequestData
            {
                LanguageDto = new LanguageItemData
                {
                    LanguageId = languageId
                },
                FindLanguageDtoEnum = FindLanguageItemData.LanguageId
            };

            LanguageResultData result = await WebApiClient.PostFormJsonAsync <LanguageRequestData, LanguageResultData>(Constant.WebApiControllerLanguages, Constant.WebApiFindLanguage, findRequest);

            if (result != null && result.OperationSuccess && result.LanguageDto != null)
            {
                languageFormData = result.ToUpdateLangueFormData();
            }
            return(PartialView("Partials/_UpdateLanguage", languageFormData));
        }
コード例 #9
0
        public async Task <OmsJsonResult> DeleteLanguage(int languageId)
        {
            JsonReturnData data = new JsonReturnData();

            if (languageId > 0)
            {
                string             param  = $"{nameof(languageId)}={languageId}";
                LanguageResultData result = await WebApiClient.DeleteAsync <LanguageResultData>(Constant.WebApiControllerLanguages, Constant.WebApiRemoveLanguage, param);

                if (result == null)
                {
                    data.ErrorMessage     = SharedResources.ServerError;
                    data.OperationSuccess = false;
                }
                else if (!result.OperationSuccess && result.Errors != null && result.Errors.Count > 0)
                {
                    data.ErrorMessage     = result.Errors.First();
                    data.OperationSuccess = false;
                }
                else if (result.OperationSuccess)
                {
                    if (Directory.Exists(Server.MapPath($"~/Images/Languages/" + languageId)))
                    {
                        Directory.Delete(Server.MapPath($"~/Images/Languages/" + languageId), true);
                    }

                    data.SuccessMessage   = LanguageResources.ok;
                    data.OperationSuccess = true;
                }
            }
            else
            {
                data.ErrorMessage     = LanguageResources.RequiredId;
                data.OperationSuccess = false;
            }
            return(new OmsJsonResult(data));
        }