Exemplo n.º 1
0
        public async Task <OmsJsonResult> UpdateSheet(SheetFormData sheetFormData)
        {
            JsonReturnData data = new JsonReturnData();

            if (ModelState.IsValid)
            {
                SheetRequestData request = sheetFormData.ToRequestData();
                SheetResultData  result  = await WebApiClient.PostFormJsonAsync <SheetRequestData, SheetResultData>(Constant.WebApiControllerOffices, Constant.WebApiUpdateSheet, request);

                if (result != null && result.OperationSuccess)
                {
                    SheetTranslationRequestData translationRequest = new SheetTranslationRequestData
                    {
                        SheetTranslationDtoList = sheetFormData.TranslationsList.ToItemDataList()
                    };

                    SheetTranslationResultData sheetTranslationResultData = await WebApiClient.PostFormJsonAsync <SheetTranslationRequestData, SheetTranslationResultData>(Constant.WebApiControllerOffices, Constant.WebApiUpdateSheetTranslationRange, translationRequest);

                    if (sheetTranslationResultData == null)
                    {
                        data.ErrorMessage     = SharedResources.ServerError;
                        data.OperationSuccess = false;
                    }
                    else if (sheetTranslationResultData.Errors != null && (!sheetTranslationResultData.OperationSuccess || sheetTranslationResultData.Errors != null || sheetTranslationResultData.Errors.Count > 0))
                    {
                        data.ErrorMessage     = sheetTranslationResultData.Errors.FirstOrDefault();
                        data.OperationSuccess = false;
                    }
                    else if (sheetTranslationResultData.OperationSuccess)
                    {
                        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 if (result.OperationSuccess)
                {
                    data.SuccessMessage   = UserResources.Ok;
                    data.OperationSuccess = true;
                }
            }
            else
            {
                data = new JsonReturnData
                {
                    ErrorMessage     = CountryResources.RequiredFields,
                    OperationSuccess = false
                };
            }
            return(new OmsJsonResult(data));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
 /// <summary>
 /// From SheetFormData to SheetRequestData
 /// </summary>
 /// <param name="sheetFormData"></param>
 /// <returns></returns>
 public static SheetRequestData ToRequestData(this SheetFormData sheetFormData)
 {
     if (sheetFormData == null)
     {
         return(new SheetRequestData());
     }
     return(new SheetRequestData
     {
         SheetDto = sheetFormData.ToItemData()
     });
 }
Exemplo n.º 4
0
 public static SheetItemData ToItemData(this SheetFormData sheetFormData)
 {
     if (sheetFormData == null)
     {
         return(new SheetItemData());
     }
     return(new SheetItemData
     {
         TranslationItemDataList = sheetFormData.TranslationsList.ToItemDataList(),
         SheetId = sheetFormData.SheetId,
         CountryId = sheetFormData.CountryId
     });
 }
Exemplo n.º 5
0
        /// <summary>
        /// validate create  sheet.
        /// </summary>
        /// <param name="sheetFormData">the sheetFormData to validate.</param>
        /// <returns>true if the proportises are valide.</returns>
        public bool ValidateSheet(SheetFormData sheetFormData)
        {
            List <string> errors = new List <string>();

            if (sheetFormData == null)
            {
                errors.Add(SharedResources.NullFormData);
            }
            else
            {
                errors.AddRange(GenericValidationAttribute <SheetFormData> .ValidateAttributes("CountryId", sheetFormData.CountryId.ToString()));
            }
            return(errors.Count == 0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get the view to create sheet.
        /// </summary>
        /// <param name="sheetId">the sheet id to update.</param>
        /// <returns>action view result.</returns>
        public async Task <ActionResult> GetUpdateSheet(int sheetId)
        {
            SheetFormData sheetFormData = new SheetFormData
            {
                TranslationsList = new List <SheetTranslationFormData>(),
                SheetId          = sheetId
            };

            SheetTranslationRequestData sheetTranslationRequestData = new SheetTranslationRequestData
            {
                SheetTranslationDto = new SheetTranslationItemData {
                    SheetId = sheetId
                },
                FindSheetTranslationDto = FindSheetTranslationItemData.SheetId
            };

            SheetTranslationResultData sheetTranslation = await WebApiClient.PostFormJsonAsync <SheetTranslationRequestData, SheetTranslationResultData>(Constant.WebApiControllerOffices, Constant.WebApiFindSheetTranslations, sheetTranslationRequestData);

            if (sheetTranslation != null && sheetTranslation.OperationSuccess && sheetTranslation.SheetTranslationDtoList != null)
            {
                foreach (var item in sheetTranslation.SheetTranslationDtoList)
                {
                    sheetFormData.CountryId = item.Sheet?.CountryId;

                    var translation = new SheetTranslationFormData
                    {
                        LanguagePrefix = item.Language?.LanguagePrefix,
                        LanguageId     = item.Language?.LanguageId,
                        TranslationId  = item.TranslationId,
                        SheetValue     = item.SheetValue,
                        SheetTitle     = item.SheetTitle,
                        SheetId        = item.SheetId
                    };
                    sheetFormData.TranslationsList.Add(translation);
                }
            }
            ViewBag.Action = "UpdateSheet";
            return(PartialView("Partials/_ManageSheet", sheetFormData));
        }