예제 #1
0
        /// <summary>
        /// Get Country Model for Update
        /// </summary>
        /// <param name="countryId"></param>
        /// <returns></returns>
        public async Task <ActionResult> GetUpdateCountry(int?countryId)
        {
            UpdateCountryFormData countryFormData = new UpdateCountryFormData
            {
                TranslationsList = new List <CountryTranslationFormData>()
            };

            if (countryId.HasValue)
            {
                CountryRequestData findCountryRequest = new CountryRequestData
                {
                    CountryDto = new CountryItemData {
                        CountryId = countryId.Value
                    },
                    FindCountryDto = FindCountryItemData.CountryId
                };
                CountryResultData resultCountry =
                    await WebApiClient.PostFormJsonAsync <CountryRequestData, CountryResultData>(
                        Constant.WebApiControllerOffices, Constant.WebApiFindCountries, findCountryRequest);

                if (resultCountry != null && resultCountry.OperationSuccess && resultCountry.CountryDto != null)
                {
                    countryFormData = resultCountry.CountryDto.ToUpdateFormData();
                    CountryTranslationRequestData findCountryTranslationRequest = new CountryTranslationRequestData()
                    {
                        CountryTranslationDto = new CountryTranslationItemData {
                            CountryId = countryId.Value
                        },
                        FindCountryTranslationDto = FindCountryTranslationItemData.CountryId
                    };
                    CountryTranslationResultData resultCountryTranslation =
                        await WebApiClient
                        .PostFormJsonAsync <CountryTranslationRequestData, CountryTranslationResultData>(
                            Constant.WebApiControllerOffices, Constant.WebApiFindCountryTranslations,
                            findCountryTranslationRequest);

                    if (resultCountryTranslation != null && resultCountryTranslation.OperationSuccess && resultCountryTranslation.CountryTranslationDtoList != null)
                    {
                        countryFormData.TranslationsList = resultCountryTranslation.CountryTranslationDtoList.ToFormDataList();
                    }
                }
            }
            ViewBag.Action = "UpdateCountry";
            return(PartialView("Partials/_UpdateCountry", countryFormData));
        }
예제 #2
0
        /// <summary>
        /// Find the country translations
        /// </summary>
        /// <param name="countryId">the country id to search.</param>
        /// <returns>the transalations</returns>
        private async Task <List <CountryTranslationItemData> > GetCountryTranslations(int countryId)
        {
            List <CountryTranslationItemData> translationsList = new List <CountryTranslationItemData>();
            CountryTranslationRequestData     findCountryTranslationRequest = new CountryTranslationRequestData()
            {
                CountryTranslationDto = new CountryTranslationItemData {
                    CountryId = countryId
                },
                FindCountryTranslationDto = FindCountryTranslationItemData.CountryId
            };
            CountryTranslationResultData resultCountryTranslation = await WebApiClient.PostFormJsonAsync <CountryTranslationRequestData, CountryTranslationResultData>(Constant.WebApiControllerOffices, Constant.WebApiFindCountryTranslations, findCountryTranslationRequest);

            if (resultCountryTranslation != null && resultCountryTranslation.OperationSuccess && resultCountryTranslation.CountryTranslationDtoList != null)
            {
                translationsList.AddRange(resultCountryTranslation.CountryTranslationDtoList);
            }
            return(translationsList);
        }
예제 #3
0
        public async Task <OmsJsonResult> UpdateCountry(UpdateCountryFormData countryFormData)
        {
            JsonReturnData data = new JsonReturnData();

            if (ModelState.IsValid)
            {
                CountryRequestData request       = countryFormData.ToRequestData();
                CountryResultData  countryResult =
                    await WebApiClient.PostFormJsonAsync <CountryRequestData, CountryResultData>(
                        Constant.WebApiControllerOffices, Constant.WebApiUpdateCountry, request);

                if (countryResult != null && countryResult.OperationSuccess)
                {
                    CountryTranslationRequestData countryTranslationRequestData = new CountryTranslationRequestData
                    {
                        CountryTranslationDtoList = countryFormData.TranslationsList.ToItemDataList()
                    };

                    CountryTranslationResultData countryTranslationResultData =
                        await WebApiClient
                        .PostFormJsonAsync <CountryTranslationRequestData, CountryTranslationResultData>(
                            Constant.WebApiControllerOffices, Constant.WebApiUpdateCountryTranslationRange,
                            countryTranslationRequestData);

                    if (countryTranslationResultData == null)
                    {
                        data.ErrorMessage     = SharedResources.ServerError;
                        data.OperationSuccess = false;
                    }
                    else if (!countryTranslationResultData.OperationSuccess && countryTranslationResultData.Errors != null && countryTranslationResultData.Errors.Count > 0)
                    {
                        data.ErrorMessage     = countryTranslationResultData.Errors.First();
                        data.OperationSuccess = false;
                    }
                    else if (countryTranslationResultData.OperationSuccess)
                    {
                        if (!Directory.Exists(Server.MapPath($"~/Images/Countries/" + countryFormData.CountryId)))
                        {
                            Directory.CreateDirectory(
                                Server.MapPath($"~/Images/Countries/" + countryFormData.CountryId));
                        }

                        countryFormData.CountryImage?.SaveAs(
                            Server.MapPath($"~/Images/Countries/" + countryFormData.CountryId + $"/") +
                            countryFormData.CountryImage?.FileName);

                        data.SuccessMessage   = UserResources.Ok;
                        data.OperationSuccess = true;
                    }
                }
                else if (countryResult == null)
                {
                    data.ErrorMessage     = SharedResources.ServerError;
                    data.OperationSuccess = false;
                }
                else if (!countryResult.OperationSuccess && countryResult.Errors != null && countryResult.Errors.Count > 0)
                {
                    data.ErrorMessage     = countryResult.Errors.First();
                    data.OperationSuccess = false;
                }
            }
            else
            {
                data = new JsonReturnData
                {
                    ErrorMessage     = CountryResources.RequiredFields,
                    OperationSuccess = false
                };
            }
            return(new OmsJsonResult(data));
        }
예제 #4
0
        public async Task <OmsJsonResult> CreateCountry(CreateCountryFormData countryFormData)
        {
            JsonReturnData data = new JsonReturnData();

            if (ModelState.IsValid)
            {
                CountryRequestData request = countryFormData.ToRequestData();
                if (request.CountryDto.CountryImage == null)
                {
                    request.CountryDto.CountryImage = "default-image-country.jpg";
                }

                CountryResultData result =
                    await WebApiClient.PostFormJsonAsync <CountryRequestData, CountryResultData>(
                        Constant.WebApiControllerOffices, Constant.WebApiCreateCountry, request);

                if (result != null && result.OperationSuccess && result.CountryDto != null)
                {
                    foreach (var translation in countryFormData.TranslationsList.ToList())
                    {
                        translation.CountryId = result.CountryDto.CountryId;
                    }
                    CountryTranslationRequestData translationRequest = new CountryTranslationRequestData
                    {
                        CountryTranslationDtoList = countryFormData.TranslationsList.ToItemDataList()
                    };

                    CountryTranslationResultData countryTranslationResultData =
                        await WebApiClient
                        .PostFormJsonAsync <CountryTranslationRequestData, CountryTranslationResultData>(
                            Constant.WebApiControllerOffices, Constant.WebApiCreateCountryTranslationRange,
                            translationRequest);

                    if (countryTranslationResultData == null)
                    {
                        data.ErrorMessage     = SharedResources.ServerError;
                        data.OperationSuccess = false;
                    }
                    else if (!countryTranslationResultData.OperationSuccess && countryTranslationResultData.Errors != null && countryTranslationResultData.Errors.Count > 0)
                    {
                        data.ErrorMessage     = countryTranslationResultData.Errors.First();
                        data.OperationSuccess = false;
                    }
                    else if (countryTranslationResultData.OperationSuccess)
                    {
                        Directory.CreateDirectory(
                            Server.MapPath($"~/Images/Countries/" + result.CountryDto.CountryId));

                        countryFormData.CountryImage?.SaveAs(
                            Server.MapPath($"~/Images/Countries/" + result.CountryDto.CountryId + $"/") +
                            countryFormData.CountryImage?.FileName);

                        System.IO.File.Copy(Server.MapPath($"~/Images/Default/default-image-country.jpg"),
                                            Server.MapPath($"~/Images/Countries/" + result.CountryDto.CountryId +
                                                           $"/default-image-country.jpg"));
                        data.SuccessMessage   = UserResources.Ok;
                        data.OperationSuccess = true;
                    }
                }
                else 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
            {
                data = new JsonReturnData
                {
                    ErrorMessage     = CountryResources.RequiredFields,
                    OperationSuccess = false
                };
            }
            return(new OmsJsonResult(data));
        }