public ActionResult Index()
        {
            var items = SystemMaintenanceNotificationDbContext.getInstance().findAllNotifications();

            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"];
            }

            return(View(items));
        }
 public ActionResult Edit(SystemMaintenanceNotification item)
 {
     if (ModelState.IsValid)
     {
         var error = SystemMaintenanceNotificationDbContext.getInstance().editNotification(item);
         if (error != null)
         {
             ModelState.AddModelError("", error);
             return(View(item));
         }
         else
         {
             ModelState.Clear();
             return(View(item));
         }
     }
     else
     {
         return(View(item));
     }
 }
 public ActionResult CreateScheduled(SystemMaintenanceNotification item)
 {
     if (ModelState.IsValid)
     {
         var error = SystemMaintenanceNotificationDbContext.getInstance().createScheduledNotification(item);
         if (error != null)
         {
             ModelState.AddModelError("", error);
             return(View());
         }
         else
         {
             ModelState.Clear();
             TempData["Message"] = "New notification successfully scheduled.";
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(View());
     }
 }
        public ActionResult Deactivate(int id = 0)
        {
            var item = SystemMaintenanceNotificationDbContext.getInstance().findNotificationByID(id);

            if (item == null)
            {
                return(HttpNotFound());
            }

            var error = SystemMaintenanceNotificationDbContext.getInstance().deactivateNotification(item);

            if (error != null)
            {
                ViewBag.Message = error;
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Message = "Successfully deactivated.";
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Edit(int id = 0)
        {
            var item = SystemMaintenanceNotificationDbContext.getInstance().findNotificationByID(id);

            return(View(item));
        }
Ejemplo n.º 6
0
        public static BaseViewModel make(string locale, string category, string id, HttpRequestBase request, BaseControllerSession session)
        {
            // locale

            if (locale == null)
            {
                locale = "zh-HK";
            }

            string language = "zh";
            string culture  = "HK";

            try
            {
                language = locale.Split('-')[0];
                culture  = locale.Split('-')[1];
            }
            catch (Exception e)
            {
            }

            if (culture != null && culture == "CN")
            {
                language = "cn";
            }

            if (culture != null && culture == "HK")
            {
                language = "zh";
            }

            if (culture != null && culture == "TW")
            {
                language = "zh";
            }


            GlobalData globalData = new GlobalData();

            globalData.implement_lbls(language);


            BaseViewModel vm = new BaseViewModel();

            vm.lang         = new Lang();
            vm.lang.locale  = locale;
            vm.lang.lang    = language;
            vm.lang.culture = culture;

            vm.globalData = globalData;

            vm.currentYear = DateTime.Now.Year.ToString();

            // sessions
            vm.current = new Current(session, null, null);



            // top warning

            vm.topWarningMessages = new List <string>();
            var systemMaintenanceNotifications = SystemMaintenanceNotificationDbContext.getInstance().findAllActivatedNotifications();

            foreach (var item in systemMaintenanceNotifications)
            {
                vm.topWarningMessages.Add(item.GetDesc(language));
            }

            // constants


            vm.constants = new List <Constant>();
            var constants = WebApplication2.Context.ConstantDbContext.getInstance().findActiveNoTracking();

            foreach (var constant in constants)
            {
                vm.constants.Add(constant);
            }


            // queries

            vm.queries = new List <Constant>();
            var keys = request.QueryString.Keys;

            for (var i = 0; i < keys.Count; i++)
            {
                var      val      = request.QueryString[keys[i]];
                Constant constant = new Constant();
                constant.Key      = keys[i];
                constant.Value    = val;
                constant.isActive = true;
                vm.queries.Add(constant);
            }

            if (vm.GetQuery("stock_code") == null)
            {
                Constant constant = new Constant();
                constant.Key      = "stock_code";
                constant.Value    = "00001";
                constant.isActive = true;
                vm.queries.Add(constant);
            }


            int articlelist_page = 1;
            int articlelist_size = 10;

            foreach (Constant constant in vm.queries)
            {
                if (constant.Key == "page")
                {
                    articlelist_page = int.Parse(constant.Value);
                }
                if (constant.Key == "size")
                {
                    articlelist_size = int.Parse(constant.Value);
                }
            }



            // category

            var db = WebApplication2.Context.InfrastructureCategoryDbContext.getInstance();

            WebApplication2.Models.Infrastructure.Category cat = null;


            // header data

            vm.headerData       = new ViewCategory(null, null);
            vm.headerData.title = "Geminis";


            // header menu

            vm.headerMenu = createHeaderMenu(0, vm.lang);

            vm.headerMenuRight = createHeaderMenuRight(0, vm.lang);

            // footer menu

            vm.footerMenu = createFooterMenu(0, vm.lang);


            // bottom menu

            vm.bottomMenu = createBottomMenu(0, vm.lang);


            // shortcut menu

            vm.shortcutMenu = createShortcutMenu(0, vm.lang);


            // jumbotron menu

            vm.jumbotronMenu = createJumbotronMenu(0, vm.lang);



            if (category != null && locale != null)
            {
                cat = db.findCategoryByURL(category);

                vm.category = new ViewCategory(cat, vm.lang);



                // breadcrumb data

                vm.breadcrumbData = createBreadcrumbData(vm.category.categoryItemID, vm.lang);


                // top bar menu

                if (cat != null && cat.pageShouldShowTopbarmenu && cat.parentItemID.HasValue)
                {
                    vm.topbarMenu = createSubmenu(cat.parentItemID.Value, vm.lang, false, false, false, false, false);
                }

                if (vm.topbarMenu != null && vm.topbarMenu.Count <= 0)
                {
                    vm.topbarMenu = null;
                }
                else if (vm.topbarMenu != null)
                {
                    foreach (Menu menuItem in vm.topbarMenu)
                    {
                        if (menuItem.category.categoryItemID == cat.ItemID)
                        {
                            menuItem.is_highlighted = true;
                        }
                        else
                        {
                            menuItem.is_highlighted = false;
                        }
                    }
                }
            }


            // content

            vm.content = null;

            if (cat != null)
            {
                if (cat.isArticleList)
                {
                    vm.category.type = "ArticleList";

                    WebApplication2.Models.ArticlePublished articlePublished = null;

                    if (id != null)
                    {
                        articlePublished = WebApplication2.Context.ArticlePublishedDbContext.getInstance().getArticlePublishedBySlugAndCategoryID(cat.ItemID, id, vm.lang.lang);
                    }

                    if (articlePublished != null)
                    {
                        vm.content                         = new ViewContent();
                        vm.content.name                    = articlePublished.Name;
                        vm.content.desc                    = articlePublished.Desc;
                        vm.content.slug                    = articlePublished.Slug;
                        vm.content.link                    = new Link(vm.lang.locale, cat.getUrl(), null, articlePublished.Slug);
                        vm.content.link.is_absolute        = false;
                        vm.content.link.is_external        = false;
                        vm.content.type                    = "Article";
                        vm.content.datetime                = articlePublished.datePublished;
                        vm.content.datetime_representation = articlePublished.getDatePublished();

                        var nextArticlePublished = WebApplication2.Context.ArticlePublishedDbContext.getInstance().getNextArticlePublishedBySlugAndCategoryID(cat.ItemID, id, vm.lang.lang);
                        var prevArticlePublished = WebApplication2.Context.ArticlePublishedDbContext.getInstance().getPrevArticlePublishedBySlugAndCategoryID(cat.ItemID, id, vm.lang.lang);

                        if (nextArticlePublished != null)
                        {
                            vm.nextContent      = new ViewContent();
                            vm.nextContent.name = nextArticlePublished.Name;
                            vm.nextContent.slug = nextArticlePublished.Slug;
                        }

                        if (prevArticlePublished != null)
                        {
                            vm.prevContent      = new ViewContent();
                            vm.prevContent.name = prevArticlePublished.Name;
                            vm.prevContent.slug = prevArticlePublished.Slug;
                        }
                    }
                    else
                    {
                        vm.content             = new ViewContent();
                        vm.content.articleList = new List <Listitem>();
                        var articleList = WebApplication2.Context.ArticlePublishedDbContext.getInstance().getArticlesPublishedByCategoryPaginated(cat, articlelist_size, articlelist_page, vm.lang.lang);
                        foreach (var article in articleList)
                        {
                            Listitem item = new Listitem();
                            item.name             = article.Name;
                            item.summary          = article.Excerpt;
                            item.link             = new Link(vm.lang.locale, cat.getUrl(), null, article.Slug);
                            item.link.is_absolute = false;
                            item.link.is_external = false;
                            vm.content.articleList.Add(item);
                        }
                        vm.content.articleListTotal       = WebApplication2.Context.ArticlePublishedDbContext.getInstance().getArticlesPublishedByCategoryTotalCount(cat, vm.lang.lang);
                        vm.content.articleListTotalPages  = vm.content.articleListTotal / articlelist_size;
                        vm.content.articleListPageSize    = articlelist_size;
                        vm.content.articleListCurrentPage = articlelist_page;
                        vm.content.articleListHasPrevPage = articlelist_page <= 1;
                        vm.content.articleListHasNextPage = articlelist_page >= vm.content.articleListTotalPages;
                        vm.content.type = "ArticleList";
                    }
                }

                else if (cat.isContentPage)
                {
                    vm.category.type = "ContentPage";

                    WebApplication2.Models.ArticlePublished contentPage = null;
                    var contentPages = WebApplication2.Context.ArticlePublishedDbContext.getInstance().getArticlesPublishedByCategory(cat, vm.lang.lang);
                    if (contentPages.Count > 0)
                    {
                        contentPage = contentPages[0];
                    }

                    if (contentPage != null)
                    {
                        vm.content                         = new ViewContent();
                        vm.content.name                    = contentPage.Name;
                        vm.content.desc                    = contentPage.Desc;
                        vm.content.slug                    = contentPage.Slug;
                        vm.content.link                    = new Link(vm.lang.locale, cat.getUrl(), contentPage.BaseArticleID + "", null);
                        vm.content.link.is_absolute        = false;
                        vm.content.link.is_external        = false;
                        vm.content.type                    = "ContentPage";
                        vm.content.datetime                = contentPage.datePublished;
                        vm.content.datetime_representation = contentPage.getDatePublished();
                    }
                }

                else

                {
                    vm.content = null;
                }
            }


            if (vm.content == null)
            {
                var error404cat = db.findCategoryByURL("page-not-found");

                if (error404cat != null)
                {
                    WebApplication2.Models.ArticlePublished contentPage = null;
                    var contentPages = WebApplication2.Context.ArticlePublishedDbContext.getInstance().getArticlesPublishedByCategory(error404cat, vm.lang.lang);
                    if (contentPages.Count > 0)
                    {
                        contentPage = contentPages[0];
                    }

                    if (contentPage != null)
                    {
                        vm.category.type = "ContentPage";

                        vm.content                         = new ViewContent();
                        vm.content.name                    = contentPage.Name;
                        vm.content.desc                    = contentPage.Desc;
                        vm.content.slug                    = contentPage.Slug;
                        vm.content.link                    = new Link(vm.lang.locale, cat.getUrl(), contentPage.BaseArticleID + "", null);
                        vm.content.link.is_absolute        = false;
                        vm.content.link.is_external        = false;
                        vm.content.type                    = "ContentPage";
                        vm.content.datetime                = contentPage.datePublished;
                        vm.content.datetime_representation = contentPage.getDatePublished();
                    }
                }
            }


            if (vm.content == null)
            {
                if (vm.category == null)
                {
                    vm.category = new ViewCategory();
                }

                vm.category.isNoContent = true;
                vm.isError      = true;
                vm.errorCode    = 404;
                vm.errorMessage = "Error: Page not found";
            }
            else
            {
                if (vm.category == null)
                {
                    vm.category = new ViewCategory();
                }

                vm.category.isNoContent = false;

                if (cat.pageClassName != null)
                {
                    vm.content.pageClassName = cat.pageClassName;
                }

                if (cat.isUseNewsArticleDetailsTemplate)
                {
                    vm.content.showArticleDetailsTemplate = true;
                }
                else
                {
                    vm.content.showArticleDetailsTemplate = false;
                }
            }


            return(vm);
        }