/// <summary>
        /// Get the news list.
        /// </summary>
        /// <returns></returns>
        private async Task <NewsViewDatas> GetNews()
        {
            NewsResultData newsResultData =
                await WebApiClient.GetAsync <NewsResultData>(Constant.WebApiControllerNews, Constant.WebApiNewsList);

            List <NewsViewData> newsViewDataList = new List <NewsViewData>();

            if (newsResultData == null || !newsResultData.OperationSuccess ||
                newsResultData.NewsDtoList == null)
            {
                return(null);
            }
            foreach (var newsDto in newsResultData.NewsDtoList)
            {
                NewsViewData newsViewData = new NewsViewData
                {
                    TranslationsList = new List <NewsTranslationItemData>(),
                    News             = newsDto
                };
                newsViewData.TranslationsList = await GetNewsTranslations(newsDto.NewsId);

                newsViewDataList.Add(newsViewData);
            }
            NewsViewDatas newlistdatas = new NewsViewDatas {
                NewsViewDataList = newsViewDataList
            };

            return(newlistdatas);
        }
Beispiel #2
0
        /// <summary>
        /// Find the news by id.
        /// </summary>
        /// <param name="newsId">the news id to find.</param>
        /// <returns></returns>
        private async Task <NewsViewData> FindNews(int newsId)
        {
            NewsViewData newsViewData = new NewsViewData()
            {
                TranslationsList = new List <NewsTranslationItemData>(),
                News             = new NewsItemData()
            };
            NewsRequestData findNewsRequest = new NewsRequestData
            {
                NewsDto = new NewsItemData {
                    NewsId = newsId
                },
                FindNewsDto = FindNewsItemData.NewsId
            };
            NewsResultData resultNews = await WebApiClient.PostFormJsonAsync <NewsRequestData, NewsResultData>(Constant.WebApiControllerNews, Constant.WebApiFindNews, findNewsRequest);

            if (resultNews != null && resultNews.OperationSuccess && resultNews.NewsDto != null)
            {
                newsViewData.News = resultNews.NewsDto;
                NewsTranslationRequestData findNewsTranslationRequest = new NewsTranslationRequestData()
                {
                    NewsTranslationDto = new NewsTranslationItemData {
                        NewsId = newsId
                    },
                    FindNewsTranslationDto = FindNewsTranslationItemData.NewsId
                };
                NewsTranslationResultData resultNewsTranslation = await WebApiClient.PostFormJsonAsync <NewsTranslationRequestData, NewsTranslationResultData>(Constant.WebApiControllerNews, Constant.WebApiFindNewsTranslations, findNewsTranslationRequest);

                if (resultNewsTranslation != null && resultNewsTranslation.OperationSuccess && resultNewsTranslation.NewsTranslationDtoList != null)
                {
                    newsViewData.TranslationsList.Add(resultNewsTranslation.NewsTranslationDtoList.First(t => t.LanguageId == _lang));
                }
            }
            return(newsViewData);
        }
Beispiel #3
0
        /// <summary>
        /// Get News Model for Update
        /// </summary>
        /// <param name="newsId"></param>
        /// <returns></returns>
        public async Task <ActionResult> GetUpdateNews(int?newsId)
        {
            NewsFormData newsFormData = new NewsFormData
            {
                TranslationsList = new List <NewsTranslationFormData>()
            };

            if (newsId.HasValue)
            {
                NewsRequestData findNewsRequest = new NewsRequestData
                {
                    NewsDto = new NewsItemData {
                        NewsId = newsId.Value
                    },
                    FindNewsDto = FindNewsItemData.NewsId
                };
                NewsResultData resultNews = await WebApiClient.PostFormJsonAsync <NewsRequestData, NewsResultData>(Constant.WebApiControllerNews, Constant.WebApiFindNews, findNewsRequest);

                if (resultNews != null && resultNews.OperationSuccess && resultNews.NewsDto != null)
                {
                    newsFormData.NewsId   = resultNews.NewsDto.NewsId;
                    newsFormData.NewsDate = resultNews.NewsDto.NewsDate.ToString("dd/MM/yyyy");
                    NewsTranslationRequestData findNewsTranslationRequest = new NewsTranslationRequestData()
                    {
                        NewsTranslationDto = new NewsTranslationItemData {
                            NewsId = newsId.Value
                        },
                        FindNewsTranslationDto = FindNewsTranslationItemData.NewsId
                    };
                    NewsTranslationResultData resultNewsTranslation = await WebApiClient.PostFormJsonAsync <NewsTranslationRequestData, NewsTranslationResultData>(Constant.WebApiControllerNews, Constant.WebApiFindNewsTranslations, findNewsTranslationRequest);

                    if (resultNewsTranslation != null && resultNewsTranslation.OperationSuccess && resultNewsTranslation.NewsTranslationDtoList != null)
                    {
                        newsFormData.TranslationsList = resultNewsTranslation.NewsTranslationDtoList.ToFormDataList();
                    }
                }
            }
            ViewBag.Action = "UpdateNews";
            return(PartialView("Partials/_ManageNews", newsFormData));
        }
Beispiel #4
0
        /// <summary>
        /// Delete News
        /// </summary>
        /// <param name="newsId"></param>
        /// <returns></returns>
        public async Task <ActionResult> DeleteNews(int newsId)
        {
            JsonReturnData data = new JsonReturnData();

            if (newsId > 0)
            {
                string         param  = $"{nameof(newsId)}={newsId}";
                NewsResultData result = await WebApiClient.DeleteAsync <NewsResultData>(Constant.WebApiControllerNews, Constant.WebApiRemoveNews, 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/News/" + newsId)))
                    {
                        Directory.Delete(Server.MapPath($"~/Images/News/" + newsId), true);
                    }
                    data.SuccessMessage   = UserResources.Ok;
                    data.OperationSuccess = true;
                }
            }
            else
            {
                data.ErrorMessage     = UserResources.RequiredUserId;
                data.OperationSuccess = false;
            }
            return(new OmsJsonResult(data));
        }
Beispiel #5
0
        public async Task <OmsJsonResult> UpdateNews(NewsFormData newsFormData)
        {
            JsonReturnData data = new JsonReturnData();

            if (ModelState.IsValid)
            {
                NewsRequestData request    = newsFormData.ToRequestData();
                NewsResultData  newsResult = await WebApiClient.PostFormJsonAsync <NewsRequestData, NewsResultData>(Constant.WebApiControllerNews, Constant.WebApiUpdateNews, request);

                if (newsResult != null && newsResult.OperationSuccess)
                {
                    NewsTranslationRequestData newsTranslationRequestData = new NewsTranslationRequestData
                    {
                        NewsTranslationDtoList = newsFormData.TranslationsList.ToItemDataList()
                    };

                    NewsTranslationResultData newsTranslationResultData = await WebApiClient.PostFormJsonAsync <NewsTranslationRequestData, NewsTranslationResultData>(Constant.WebApiControllerNews, Constant.WebApiUpdateNewsTranslationRange, newsTranslationRequestData);

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

                        newsFormData.NewsImage?.SaveAs(
                            Server.MapPath($"~/Images/News/" + newsFormData.NewsId + $"/") +
                            newsFormData.NewsImage.FileName);

                        data.SuccessMessage   = UserResources.Ok;
                        data.OperationSuccess = true;
                    }
                }
                else if (newsResult == null)
                {
                    data.ErrorMessage     = SharedResources.ServerError;
                    data.OperationSuccess = false;
                }
                else if (!newsResult.OperationSuccess && newsResult.Errors != null && newsResult.Errors.Count > 0)
                {
                    data.ErrorMessage     = newsResult.Errors.First();
                    data.OperationSuccess = false;
                }
                else if (newsResult.OperationSuccess)
                {
                    data.SuccessMessage   = UserResources.Ok;
                    data.OperationSuccess = true;
                }
            }
            else
            {
                data = new JsonReturnData
                {
                    ErrorMessage     = NewsResources.RequiredFields,
                    OperationSuccess = false
                };
            }
            return(new OmsJsonResult(data));
        }
Beispiel #6
0
        public async Task <OmsJsonResult> CreateNews(NewsFormData newsFormData)
        {
            JsonReturnData data = new JsonReturnData();

            if (ModelState.IsValid)
            {
                NewsRequestData request = newsFormData.ToRequestData();

                if (request.NewsDto.NewsImage == null)
                {
                    request.NewsDto.NewsImage = "default-image-news.jpg";
                }

                NewsResultData result =
                    await WebApiClient.PostFormJsonAsync <NewsRequestData, NewsResultData>(Constant.WebApiControllerNews,
                                                                                           Constant.WebApiCreateNews, request);

                if (result != null && result.OperationSuccess && result.NewsDto != null)
                {
                    foreach (var translation in newsFormData.TranslationsList.ToList())
                    {
                        translation.NewsId = result.NewsDto.NewsId;
                    }
                    NewsTranslationRequestData translationRequest = new NewsTranslationRequestData
                    {
                        NewsTranslationDtoList = newsFormData.TranslationsList.ToItemDataList()
                    };

                    NewsTranslationResultData newsTranslationResultData =
                        await WebApiClient.PostFormJsonAsync <NewsTranslationRequestData, NewsTranslationResultData>(
                            Constant.WebApiControllerNews, Constant.WebApiCreateNewsTranslationRange,
                            translationRequest);

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

                        newsFormData.NewsImage?.SaveAs(
                            Server.MapPath($"~/Images/News/" + result.NewsDto.NewsId + $"/") +
                            newsFormData.NewsImage.FileName);

                        System.IO.File.Copy(Server.MapPath($"~/Images/Default/default-image-news.jpg"),
                                            Server.MapPath($"~/Images/News/" + result.NewsDto.NewsId +
                                                           $"/default-image-news.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     = NewsResources.RequiredFields,
                    OperationSuccess = false
                };
            }
            return(new OmsJsonResult(data));
        }