private async Task <NewsCategories> GetNewsCategories()
        {
            try
            {
                var cachedCategories = _cacheManager.Get <NewsCategories>("NewsCategories");

                if (cachedCategories != null && cachedCategories.Categories != null && cachedCategories.Categories.Any())
                {
                    return(cachedCategories);
                }

                var newsCategories = await _fileUploader.GetFileFromS3(@"News/NewsCategories.json");

                if (newsCategories == null)
                {
                    return(new NewsCategories());
                }

                var categoriesFromS3 = DeserializeObject <NewsCategories>(newsCategories);
                _cacheManager.Set("NewsCategories", categoriesFromS3);
                _newsCategories = categoriesFromS3;
                return(categoriesFromS3);
            }
            catch (Exception ex)
            {
                //ignore
            }

            return(null);
        }
 public AdminController(IFileUploader fileUploader, ICacheManager cacheManager)
 {
     _fileUploader   = fileUploader;
     _cacheManager   = cacheManager;
     _newsCategories = GetNewsCategories().Result;
     _random         = new Random();
 }
    private void BindData()
    {
        var _Cate = new NewsCategories();

        rptList.DataSource = _Cate.GetList();
        rptList.DataBind();
    }
Beispiel #4
0
        public ActionResult NewsCategoriesDelete(int deleteId)
        {
            NewsCategories newsCategories = new NewsCategories();

            switch (newsCategories.Delete(deleteId))
            {
            case 0:
                ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyDeleted);
                break;

            case 2:
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist);
                break;

            case 3:
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemUsedSomewhereElse);
                break;

            default:
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError);
                break;
            }

            return(RedirectToAction("NewsCategories"));
        }
Beispiel #5
0
    private void GetDrpFather()
    {
        var _Cate = new NewsCategories();

        drpFather.DataSource = _Cate.GetList();
        drpFather.DataBind();
        drpFather.Items.Insert(0, new ListItem("N/A", "0"));
    }
        // GET: Admin/NewsCategories

        public ActionResult Index(string seachString, int page = 1, int pageSize = 10)
        {
            var categories = new NewsCategories();
            var model      = categories.ListAllPaging(seachString, page, pageSize);

            ViewBag.SearchString = seachString;
            return(View(model));
        }
        private async Task <bool> UpdateCategoryInS3(NewsCategories model)
        {
            var jsonString = JsonSerializer.Serialize(model);

            var isSaved = await _fileUploader.SaveFileAsync(@"News/NewsCategories.json", jsonString)
                          .ConfigureAwait(false);

            return(true);
        }
Beispiel #8
0
        public ActionResult NewsCategories(BackEndNewsCategoryList backEndNewsCategoryList)
        {
            NewsCategories newsCategories = new NewsCategories();

            backEndNewsCategoryList.NewsCategoryList = newsCategories.GetNewsCategories(backEndNewsCategoryList.CategoryName, backEndNewsCategoryList.IsActive);
            if (backEndNewsCategoryList.NewsCategoryList.IsNull() || backEndNewsCategoryList.NewsCategoryList.Count == 0)
            {
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.NoDataFound);
            }

            return(View(backEndNewsCategoryList));
        }
Beispiel #9
0
    private void GetDrpOrder()
    {
        drpOrder.Items.Clear();
        drpOrder.Items.Insert(0, new ListItem("N/A (0)", "0"));
        var _Cate = new NewsCategories();
        List <NewsCategories> list = _Cate.GetList(Convert.ToInt32(drpFather.SelectedValue));

        for (int i = 0; i < list.Count; i++)
        {
            _Cate = list[i];
            drpOrder.Items.Add(new ListItem(_Cate.Alias + " (" + _Cate.Order.ToString() + ")", _Cate.Order.ToString()));
        }
    }
    protected void btAdd_Click(object sender, EventArgs e)
    {
        var _Cate = new NewsCategories();

        _Cate.Name      = txtName.Text.Trim();
        _Cate.Alias     = txtAlias.Text.Trim();
        _Cate.Url       = txtUrl.Text.Trim();
        _Cate.FatherID  = Convert.ToInt32(drpFather.SelectedValue);
        _Cate.Order     = Convert.ToInt32(drpOrder.SelectedValue) + 1;
        _Cate.Note      = txtNote.Text.Trim();
        _Cate.IsDisplay = cbxIsActive.Checked;
        _Cate.Add();
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.NewsCategoriesList);
    }
        public ActionResult Category(int cateId)
        {
            var newArticles = new NewsArticles();

            ViewBag.NewsArticles1 = newArticles.ListNewsArticle1(1);
            ViewBag.NewsArticles6 = newArticles.ListNewsArticle6(1);
            ViewBag.NewsArticles2 = newArticles.ListNewsArticle2(5);
            ViewBag.NewsArticles3 = newArticles.ListNewsArticle3(1);
            ViewBag.NewsArticles4 = newArticles.ListNewsArticle4(5);
            ViewBag.NewsArticles5 = newArticles.ListNewsArticle5(7);

            var category = new NewsCategories().ViewDetail(cateId);

            return(View(category));
        }
Beispiel #12
0
        public void Execute(CreateNewsDto request)
        {
            var news = Context.News.Find(request.NewsId);

            if (news == null)
            {
                throw new EntityNotFoundException("News");
            }
            if (request.CategoryIds.Any(x => !Context.Categories.Any(y => y.Id == x)))
            {
                throw new EntityNotFoundException("Categories");
            }
            //if (!Context.Users.Any(x => x.Id == HttpContext.UserId))
            //{
            //    throw new EntityNotFoundException("User");
            //}

            var picture = new Picture
            {
                Path      = request.Path,
                CreatedAt = DateTime.Now,
                NewsId    = request.NewsId
            };

            news.Heading    = request.Heading;
            news.Content    = request.Content;
            news.ModifiedAt = DateTime.Now;
            news.UserId     = /*request.UserId*/ 1;
            Context.SaveChanges();

            Context.Pictures.Add(picture);

            var foundNewsCategories = Context.NewsCategories.Where(x => x.NewsId == request.NewsId);

            Context.NewsCategories.RemoveRange(foundNewsCategories);
            Context.SaveChanges();

            foreach (var cat in request.CategoryIds)
            {
                var newsCategories = new NewsCategories()
                {
                    CategoryId = cat,
                    NewsId     = request.NewsId
                };
                Context.NewsCategories.Add(newsCategories);
                Context.SaveChanges();
            }
        }
Beispiel #13
0
        private void CreateNewNewsCategory(CreateNewsDto request, int id)
        {
            request.NewsId = id;
            RemoveExistsRelastionship(request);

            foreach (var cat in request.CategoryIds)
            {
                var newsCategories = new NewsCategories()
                {
                    CategoryId = cat,
                    NewsId     = request.NewsId
                };
                Context.NewsCategories.Add(newsCategories);
                Context.SaveChanges();
            }
        }
Beispiel #14
0
        public NewsCategories GetByShortName(NewsCategories dummy)
        {
            var comm = this.GetCommand("sp_NewsCategoryGetByShortName");

            if (comm == null)
            {
                return(null);
            }
            comm.AddParameter <string>(this.Factory, "NewCategoryShortName", dummy.NewCategoryShortName);
            comm.AddParameter <int>(this.Factory, "NewCategoryId", dummy.NewCategoryId);
            var dt           = this.GetTable(comm);
            var htmlPageCate = EntityBase.ParseListFromTable <NewsCategories>(dt).FirstOrDefault();

            return(htmlPageCate ?? null);
            //throw new NotImplementedException();
        }
 public ActionResult Edit(NewsCategory category)
 {
     if (ModelState.IsValid)
     {
         var  ncategory = new NewsCategories();
         bool result    = ncategory.Update(category);
         if (result)
         {
             return(RedirectToAction("Index", "NewsCategories"));
         }
         else
         {
             ModelState.AddModelError("", "Cập nhật danh mục không thành công!");
         }
     }
     return(View("Index"));
 }
 public ActionResult Create(NewsCategory category)
 {
     if (ModelState.IsValid)
     {
         var  dao = new NewsCategories();
         long id  = dao.Insert(category);
         if (id > 0)
         {
             return(RedirectToAction("Index", "NewsCategories"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm danh mục không thành công!");
         }
     }
     return(View());
 }
Beispiel #17
0
        public IActionResult AddNews(News news, FormHelper formhelper)
        {
            if (news.Header == null || formhelper.CategoryId == null)
            {
                return(BadRequest(ModelState)); // TODO: Märk upp meddelande för modelstate
                                                // TODO: Validera att rubrik och kategori är unik(?)
            }

            using (var context = new NewsContext())
            {
                news.Created = DateTime.Now;
                news.Updated = DateTime.Now;

                context.Add(news);

                var author = context.Authors.Single(x => x.Id == formhelper.AuthorId);

                var authornews = new AuthorsNews(news, author);

                context.Add(authornews);

                context.SaveChanges();


                for (int i = 0; i < formhelper.CategoryId.Length; i++)
                {
                    var tmpnewscategory = new NewsCategories()
                    {
                        NewsId     = news.Id,
                        CategoryId = formhelper.CategoryId[i]
                    };

                    context.Add(tmpnewscategory);
                    context.SaveChanges();
                }
            }

            var addedMessage = string.Format("Nyheten fick ID {0}", news.Id);

            return(Json(new
            {
                success = true,
                Message = addedMessage
            }));
        }
Beispiel #18
0
    protected void btUpdate_Click(object sender, EventArgs e)
    {
        var _Cate = new NewsCategories()
        {
            CateID = AppUtils.Request("id")
        };

        _Cate          = _Cate.Get();
        _Cate.Name     = txtName.Text.Trim();
        _Cate.Alias    = txtAlias.Text.Trim();
        _Cate.Url      = txtUrl.Text.Trim();
        _Cate.FatherID = Convert.ToInt32(drpFather.SelectedValue);
        if (Convert.ToInt32(drpOrder.SelectedValue) != _Cate.Order)
        {
            _Cate.Order = Convert.ToInt32(drpOrder.SelectedValue) + 1;
        }
        _Cate.Note      = txtNote.Text.Trim();
        _Cate.IsDisplay = cbxIsActive.Checked;
        _Cate.Update();

        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.NewsCategoriesList);
    }
Beispiel #19
0
    private void init()
    {
        var _Cate = new NewsCategories()
        {
            CateID = AppUtils.Request("id")
        };

        _Cate = _Cate.Get();
        if (_Cate == null)
        {
            Response.Redirect(Constant.ADMIN_PATH + Resources.Url.NewsCategoriesList);
        }
        txtName.Text            = _Cate.Name;
        txtAlias.Text           = _Cate.Alias;
        txtUrl.Text             = _Cate.Url;
        drpFather.SelectedValue = _Cate.FatherID.ToString();
        txtNote.Text            = _Cate.Note;
        cbxIsActive.Checked     = _Cate.IsDisplay;

        GetDrpOrder();
        drpOrder.SelectedValue = _Cate.Order.ToString();
    }
Beispiel #20
0
    private void GetDrpCate()
    {
        List <NewsCategories> list = new NewsCategories().GetListDrp();

        drpCate1.DataSource = list;
        drpCate1.DataBind();
        drpCate1.Items.Insert(0, new ListItem("Chuyên mục:", "0"));

        drpCate2.DataSource = list;
        drpCate2.DataBind();
        drpCate2.Items.Insert(0, new ListItem("Chuyên mục:", "0"));

        drpCate3.DataSource = list;
        drpCate3.DataBind();
        drpCate3.Items.Insert(0, new ListItem("Chuyên mục:", "0"));

        drpCate4.DataSource = list;
        drpCate4.DataBind();
        drpCate4.Items.Insert(0, new ListItem("Chuyên mục:", "0"));

        drpCate5.DataSource = list;
        drpCate5.DataBind();
        drpCate5.Items.Insert(0, new ListItem("Chuyên mục:", "0"));
    }
Beispiel #21
0
        public ActionResult NewsCategoriesAddEdit(int?id)
        {
            BackEndNewsCategoryAddEdit backEndNewsCategoryAddEdit = new BackEndNewsCategoryAddEdit();

            NewsCategories newsCategories = new NewsCategories();
            NewsCategory   newsCategory;

            BackEndNewsCategoryLanguagesAddEdit backEndNewsCategoryLanguagesAddEdit;

            List <Language> allActiveLanguages = new Languages().GetAllLanguages(isActive: true);

            if (allActiveLanguages.IsNotNull() && allActiveLanguages.Count > 0)
            {
                if (id.IsNotNull())
                {
                    List <NewsCategory> backEndNewsCategoryList = newsCategories.GetNewsCategories(id);
                    if (backEndNewsCategoryList.IsNotNull() && backEndNewsCategoryList.Count > 0)
                    {
                        backEndNewsCategoryAddEdit.CategoryId = id;
                        backEndNewsCategoryAddEdit.IsActive   = backEndNewsCategoryList[0].IsActive;

                        foreach (Language language in allActiveLanguages)
                        {
                            backEndNewsCategoryLanguagesAddEdit = new BackEndNewsCategoryLanguagesAddEdit();
                            backEndNewsCategoryLanguagesAddEdit.LanguageCode = language.LanguageCode;
                            backEndNewsCategoryLanguagesAddEdit.LanguageName = language.LanguageName;

                            newsCategory = newsCategories.GetNewsCategory(id, language.LanguageCode);
                            if (newsCategory.IsNotNull())
                            {
                                backEndNewsCategoryLanguagesAddEdit.CategoryName = newsCategory.CategoryName;
                            }

                            backEndNewsCategoryAddEdit.NewsCategoryLanguages.Add(backEndNewsCategoryLanguagesAddEdit);
                        }
                    }
                    else
                    {
                        ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist);
                        ViewData.IsFormVisible(false);
                    }
                }
                else
                {
                    foreach (Language language in allActiveLanguages)
                    {
                        backEndNewsCategoryLanguagesAddEdit = new BackEndNewsCategoryLanguagesAddEdit();
                        backEndNewsCategoryLanguagesAddEdit.LanguageCode = language.LanguageCode;
                        backEndNewsCategoryLanguagesAddEdit.LanguageName = language.LanguageName;

                        backEndNewsCategoryAddEdit.NewsCategoryLanguages.Add(backEndNewsCategoryLanguagesAddEdit);
                    }
                }
            }
            else
            {
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError);
            }

            return(View(backEndNewsCategoryAddEdit));
        }
Beispiel #22
0
 public NewsCategories GetByShortName(NewsCategories model)
 {
     return(NewCategoriesProvider.GetByShortName(model));
 }
Beispiel #23
0
        public ActionResult FooterMenu()
        {
            var model = new NewsCategories().GetCategory();

            return(PartialView(model));
        }
        public ActionResult Edit(int id)
        {
            var user = new NewsCategories().ViewDetail(id);

            return(View(user));
        }
Beispiel #25
0
        public ActionResult NewsCategoriesAddEdit(BackEndNewsCategoryAddEdit backEndNewsCategoryAddEdit)
        {
            if (ModelState.IsValidOrRefresh())
            {
                NewsCategories newsCategories = new NewsCategories();
                int?           result;
                bool           isLoopSuccessful = true;
                int?           lastInsertedId   = null;
                int?           currentId        = backEndNewsCategoryAddEdit.CategoryId;
                foreach (BackEndNewsCategoryLanguagesAddEdit backEndNewsCategoryLanguagesAddEdit in backEndNewsCategoryAddEdit.NewsCategoryLanguages)
                {
                    if (currentId.IsNull())
                    {
                        currentId = lastInsertedId;
                    }
                    result = newsCategories.AddEdit(currentId,
                                                    backEndNewsCategoryLanguagesAddEdit.LanguageCode,
                                                    backEndNewsCategoryAddEdit.IsActive,
                                                    backEndNewsCategoryLanguagesAddEdit.CategoryName,
                                                    out lastInsertedId);
                    switch (result)
                    {
                    case 0:
                        //success
                        break;

                    case 2:
                        isLoopSuccessful = false;
                        ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist);
                        ViewData.IsFormVisible(false);
                        break;

                    case 3:
                        isLoopSuccessful = false;
                        ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings_News.CategoryNameAlreadyExists + " (" + backEndNewsCategoryLanguagesAddEdit.LanguageName + ")");
                        break;

                    default:
                        isLoopSuccessful = false;
                        ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError);
                        break;
                    }
                    if (!isLoopSuccessful)
                    {
                        break;
                    }
                }
                if (isLoopSuccessful)
                {
                    News news = new News();
                    news.ForceCache();

                    if (backEndNewsCategoryAddEdit.CategoryId.IsNull())
                    {
                        ModelState.Clear();
                        backEndNewsCategoryAddEdit = new BackEndNewsCategoryAddEdit();
                        BackEndNewsCategoryLanguagesAddEdit backEndNewsCategoryLanguagesAddEdit;
                        List <Language> allActiveLanguages = new Languages().GetAllLanguages(isActive: true);
                        foreach (Language language in allActiveLanguages)
                        {
                            backEndNewsCategoryLanguagesAddEdit = new BackEndNewsCategoryLanguagesAddEdit();
                            backEndNewsCategoryLanguagesAddEdit.LanguageCode = language.LanguageCode;
                            backEndNewsCategoryLanguagesAddEdit.LanguageName = language.LanguageName;

                            backEndNewsCategoryAddEdit.NewsCategoryLanguages.Add(backEndNewsCategoryLanguagesAddEdit);
                        }

                        ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyAdded);
                    }
                    else
                    {
                        ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyEdited);
                    }
                }
            }

            return(View(backEndNewsCategoryAddEdit));
        }
Beispiel #26
0
        public void SeedTheNews()
        {
            var context = new NewsContext();

            var news1 = new News();

            news1.Header   = "En fotbollsartikel";
            news1.Intro    = "Lorem ipsum dolor sit amet.";
            news1.Paragraf = "Some more text.";
            news1.Created  = DateTime.Now;
            news1.Updated  = DateTime.Now;

            var news2 = new News();

            news2.Header   = "En lokal artikel";
            news2.Intro    = "Lorem ipsum dolor sit amet.";
            news2.Paragraf = "Some more text.";
            news2.Created  = DateTime.Now;
            news2.Updated  = DateTime.Now;

            var news3 = new News();

            news3.Header   = "En krönika";
            news3.Intro    = "Lorem ipsum dolor sit amet.";
            news3.Paragraf = "Some more text.";
            news3.Created  = DateTime.Now;
            news3.Updated  = DateTime.Now;

            var news4 = new News();

            news4.Header   = "Ett reportage om Kicki Danielsson";
            news4.Intro    = "Lorem ipsum dolor sit amet.";
            news4.Paragraf = "Some more text.";
            news4.Created  = DateTime.Now;
            news4.Updated  = DateTime.Now;

            var news5 = new News();

            news5.Header   = "Ny kungabäbis";
            news5.Intro    = "Lorem ipsum dolor sit amet.";
            news5.Paragraf = "Some more text.";
            news5.Created  = DateTime.Now;
            news5.Updated  = DateTime.Now;

            using (context)
            {
                context.AddRange(news1, news2, news3, news4, news5);

                var result1 = context.Categories.Single(x => x.Id == 3);

                var result2 = context.Categories.Single(x => x.Id == 4);

                var result3 = context.Authors.Single(x => x.Id == 1);


                var newscategory1 = new NewsCategories()
                {
                    NewsId     = news1.Id,
                    CategoryId = result1.Id
                };

                var newscategory2 = new NewsCategories()
                {
                    NewsId     = news1.Id,
                    CategoryId = result2.Id
                };

                var newscategory3 = new NewsCategories()
                {
                    NewsId     = news2.Id,
                    CategoryId = result1.Id
                };

                var newscategory4 = new NewsCategories()
                {
                    NewsId     = news3.Id,
                    CategoryId = result1.Id
                };

                var authornews = new AuthorsNews(news1, result3);

                var authornews1 = new AuthorsNews(news2, result3);

                context.AddRange(newscategory1, newscategory2, newscategory3, newscategory4, authornews, authornews1);

                context.SaveChanges();
            }
        }