demo20230512/Controllers/HomeController.cs
2023-05-12 10:20:28 +08:00

117 lines
4.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using Microsoft.AspNet.Identity;
using Weee.Models;
using Weee.DAL;
using Weee.Areas.Admin.Supports;
using Weee.Filter;
using Resources.Helper;
using PagedList;
using CScommon;
using Weee.ViewModels;
using Weee.Service;
using Customize.ViewModels.Insynerger;
using System.Configuration;
namespace Weee.Controllers
{
[Authorize(Roles = ProgramConstants.normalcompany)]
//[MvcMultilanguage]disable obsolete warning, not sure OK or not
public class HomeController : QcarbonControllerBase
{
protected WeeeSiteInfoService _siteInfoService;
private readonly string baseUrl = "";
public HomeController(WeeeDataContext db,
WeeeSiteInfoService siteInfoService)
:base(db)
{
//_db = db;
_siteInfoService = siteInfoService;
baseUrl = ConfigurationManager.AppSettings["InsynergerAPIurl"];
}
[Route("")]
[AllowAnonymous]
public ActionResult Index()
{
return RedirectToAction("Login", "Account");
//return View(db.PublicMessages.OrderByDescending(x => x.UpdatedTime).Take(5).ToList().Select(x=>x.DisplayName));
}
[Route("Insynerger")]
[AllowAnonymous]
public ActionResult Insynerger()
{
ViewBag.baseUrl = baseUrl;
//這裡拿來做Qcarbon轉址思納捷的預先登入
var synergerVM=Session["synergerVM"];
InsynergerPreloginVM viewModel;
if (synergerVM == null)
{
return RedirectToAction("WeeeCarbonFootprint", "Home", new { area = "" });
//viewModel = new InsynergerPreloginVM();
//viewModel.id = "weeerohsAdmin";
//viewModel.pd = "weeerohsAdmin";
}
else
viewModel = (InsynergerPreloginVM)synergerVM;
ViewBag.id=viewModel.id;
ViewBag.pd=viewModel.pd;
return View();
}
[Route("Insynerger")]
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Insynerger(InsynergerPreloginVM viewModel)
{
ViewBag.baseUrl = baseUrl;
// 完成思納捷戰情室登入後,轉址會員首頁
//RedirectToAction("WeeeCarbonFootprint", "Home", new { area = "" });
return View(viewModel);
}
[Route("app")]
public ActionResult WeeeCarbonFootprint()
{
if (User.IsInRole(ProgramConstants.admin)) return RedirectToAction("Index", "home", new { area = "admin" });
else if (User.IsInRole(ProgramConstants.certification)) return RedirectToAction("Index", "home", new { area = "certification" });
else if (User.IsInRole(ProgramConstants.normalcompany))
{
var re = GetWebSiteInfo();
return View(re);
}
else
return RedirectToAction("Forbidden", new { message = "Your Account has not yet actived" });
}
public ActionResult Forbidden(string message)
{
return View(message);
}
[AllowAnonymous]
[Route("PublicFiles")]
public ActionResult PublicFiles(int page = 1)
{
var files = db.PublicReferenceFiles.OrderBy(x => x.CreatedTime);
var onePageOfFiles = files.ToPagedList(page, 10);
//var qry = (from a in uow.actionLogRepository.Get()
// select a).AsQueryable();
return View(onePageOfFiles);
}
private WeeeCarbonFootprintViewModel GetWebSiteInfo()
{
var re = new WeeeCarbonFootprintViewModel();
var info = _siteInfoService.GetWebSiteInfo();
if(info != null)
re = JsonUtl.jsonCopy<WebSiteInfoViewModel, WeeeCarbonFootprintViewModel>(info);
return re;
}
}
}