231 lines
9.3 KiB
C#
231 lines
9.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Data.Entity;
|
|
using Weee.Models;
|
|
using Microsoft.AspNet.Identity.EntityFramework;
|
|
using Microsoft.AspNet.Identity;
|
|
using Weee.DAL;
|
|
using PagedList;
|
|
using Weee.ViewModels;
|
|
using Resources;
|
|
using CScommon;
|
|
using System.Net;
|
|
|
|
namespace Weee.Areas.Certification.Controllers
|
|
{
|
|
[Authorize(Roles = ProgramConstants.certification)]
|
|
public class HomeController : CertificationControllerBase
|
|
{
|
|
|
|
//private WeeeDataContext _db;
|
|
private int? currentcompanyid;
|
|
|
|
public HomeController(WeeeDataContext db)
|
|
: base(db)
|
|
{
|
|
//this._db = db;
|
|
}
|
|
|
|
// GET: /Consultant/Home/
|
|
public ActionResult Index()
|
|
{
|
|
//Start CFT-30
|
|
//var verifyLCAs = _db.LCAs
|
|
// .Where(x => x.Status == LCAStatus.Waiting
|
|
// && x.VerifierCompanyID == currentcompanyid)
|
|
// .OrderByDescending(x => x.ID)
|
|
// .ToList();
|
|
var verifyLCAs = GetVerifyLCADataList((int)currentcompanyid, LCAStatus.Waiting);
|
|
//End CFT-30
|
|
//var verifyLCAs = (from a in _db.LCAs
|
|
// join b in _db.ProductLCAs on a.ID equals b.ID into ab
|
|
// from c in ab.DefaultIfEmpty()
|
|
// join d in _db.Products on c.ProductID equals d.ID into cd
|
|
// from e in cd.DefaultIfEmpty()
|
|
// where a.Status == LCAStatus.Waiting
|
|
// && a.VerifierCompanyID == currentcompanyid
|
|
// select new CertificationViewModel
|
|
// {
|
|
// ID = a.ID,
|
|
// LCAname = a.LCAname,
|
|
// StartDate = a.StartDate,
|
|
// EndDate = a.EndDate,
|
|
// LCATypeName = (c == null) ? Resource.StaticLabelOrganizationLCA
|
|
// : Resource.StaticLabelProductLCA,
|
|
// Description = a.Description,
|
|
// CreatedDate = a.CreatedDate,
|
|
// LCAitemName = e.Name
|
|
// })
|
|
// .OrderByDescending(x => x.ID)
|
|
// .ToList();
|
|
return View(verifyLCAs);
|
|
}
|
|
public ActionResult All(int page = 1, string searchString = "")
|
|
{
|
|
var query = db.LCAs
|
|
.Where(x => x.VerifierCompanyID == currentcompanyid)
|
|
//.Where(x => x.Status != LCAStatus.Waiting || x.Status != LCAStatus.New);
|
|
;
|
|
if (searchString != "")
|
|
query = query.Where(x => x.Description.Contains(searchString));
|
|
var LCAs = query.OrderByDescending(x => x.ID).ToPagedList(page, 20);
|
|
var onePage = LCAs;
|
|
ViewBag.SearchString = searchString;
|
|
return View(LCAs);
|
|
}
|
|
|
|
public ActionResult LCAStatusNew()
|
|
{
|
|
//Start CFT-30
|
|
//var verifyLCAs = _db.LCAs
|
|
// .Where(x => x.Status == LCAStatus.New
|
|
// && x.VerifierCompanyID == currentcompanyid)
|
|
// .OrderByDescending(x => x.ID)
|
|
// .ToList();
|
|
var verifyLCAs = GetVerifyLCADataList((int)currentcompanyid, LCAStatus.New);
|
|
//End CFT-30
|
|
return View(verifyLCAs);
|
|
}
|
|
public ActionResult LCAStatusProcessing()
|
|
{
|
|
//Start CFT-30
|
|
//var verifyLCAs = _db.LCAs
|
|
// .Where(x => x.Status == LCAStatus.Processing
|
|
// && x.VerifierCompanyID == currentcompanyid)
|
|
// .OrderByDescending(x => x.ID)
|
|
// .ToList();
|
|
var verifyLCAs = GetVerifyLCADataList((int)currentcompanyid, LCAStatus.Processing);
|
|
//End CFT-30
|
|
return View(verifyLCAs);
|
|
}
|
|
|
|
public ActionResult LCAStatusRejected()
|
|
{
|
|
//Start CFT-30
|
|
//var verifyLCAs = _db.LCAs
|
|
// .Where(x => x.Status == LCAStatus.Rejected
|
|
// && x.VerifierCompanyID == currentcompanyid)
|
|
// .OrderByDescending(x => x.ID)
|
|
// .ToList();
|
|
var verifyLCAs = GetVerifyLCADataList((int)currentcompanyid, LCAStatus.Rejected);
|
|
//End CFT-30
|
|
return View(verifyLCAs);
|
|
}
|
|
|
|
public ActionResult LCAStatusConfirmed()
|
|
{
|
|
//Start CFT-30
|
|
//var verifyLCAs = _db.LCAs
|
|
// .Where(x => x.Status == LCAStatus.Confirmed
|
|
// && x.VerifierCompanyID == currentcompanyid)
|
|
// .OrderByDescending(x => x.ID)
|
|
// .ToList();
|
|
|
|
var verifyLCAs = GetVerifyLCADataList((int)currentcompanyid, LCAStatus.Confirmed);
|
|
//End CFT-30
|
|
return View(verifyLCAs);
|
|
}
|
|
public ActionResult LCAStatusCompleted()
|
|
{
|
|
//Start CFT-30
|
|
//var verifyLCAs = _db.LCAs
|
|
// .Where(x => x.Status == LCAStatus.Completed
|
|
// && x.VerifierCompanyID == currentcompanyid)
|
|
// .OrderByDescending(x => x.ID)
|
|
// .ToList();
|
|
var verifyLCAs = GetVerifyLCADataList((int)currentcompanyid, LCAStatus.Completed);
|
|
//End CFT-30
|
|
return View(verifyLCAs);
|
|
}
|
|
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
|
{
|
|
var loggedInUserId = User.Identity.GetUserId();
|
|
currentcompanyid = db.Users.AsNoTracking().First(x => x.Id == loggedInUserId).CompanyID;
|
|
base.OnActionExecuting(filterContext);
|
|
}
|
|
|
|
//CFT-30
|
|
public List<CertificationViewModel> GetVerifyLCADataList( int companyID, LCAStatus status)
|
|
{
|
|
var verifyLCAs = (from a in db.LCAs
|
|
join b in db.ProductLCAs on a.ID equals b.ID into ab
|
|
from c in ab.DefaultIfEmpty()
|
|
join d in db.Products on c.ProductID equals d.ID into cd
|
|
from e in cd.DefaultIfEmpty()
|
|
where a.Status == status
|
|
&& a.VerifierCompanyID == companyID
|
|
select new CertificationViewModel
|
|
{
|
|
ID = a.ID,
|
|
LCAname = a.LCAname,
|
|
StartDate = a.StartDate,
|
|
EndDate = a.EndDate,
|
|
LCATypeName = (c == null) ? Resource.StaticLabelOrganizationLCA
|
|
: Resource.StaticLabelProductLCA,
|
|
Description = a.Description,
|
|
CreatedDate = a.CreatedDate,
|
|
LCAitemName = e.Name
|
|
})
|
|
.OrderByDescending(x => x.ID)
|
|
.ToList();
|
|
|
|
return verifyLCAs;
|
|
}
|
|
|
|
public ActionResult UploadFileFA(int updType)
|
|
{
|
|
if (Request == null)
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
|
|
HttpPostedFileBase file = Request.Files["UploadedFile"];
|
|
|
|
try
|
|
{
|
|
if (file.ContentLength == 0)
|
|
{
|
|
TempData["ErrMsg"] = "未選擇檔案";
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
if (file != null)
|
|
{
|
|
var userNm = User.Identity.GetUserName();
|
|
|
|
string newFileName = "";
|
|
if (updType == 1) newFileName = ProgramConstants.OrganizationLCAApplicationFile;
|
|
else if (updType == 2) newFileName = ProgramConstants.ProductLCAApplicationFile;
|
|
|
|
string extesion = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1);
|
|
if (extesion.ToLower() != "zip")
|
|
{
|
|
TempData["ErrMsg"] = "僅支持zip類型";
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
var storage = System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(Storage.AzureStorage)) as Storage.AzureStorage;
|
|
var uri = storage.SaveToAzure(file.InputStream, file.FileName, baseUrl, userNm, false
|
|
, newFileName);
|
|
|
|
TempData["SuccessMsg"] = "[" + newFileName + "]上傳成功";
|
|
return RedirectToAction("Index");
|
|
}
|
|
else
|
|
{
|
|
TempData["ErrMsg"] = "上傳失敗";
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TempData["ErrMsg"] = ex.Message;
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|