145 lines
5.1 KiB
C#
145 lines
5.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Data.Entity;
|
|
using Weee.DAL;
|
|
using Weee.Models.Paramemter;
|
|
using Weee.Models;
|
|
using System.Data.Entity.Core.Objects;
|
|
using Weee.ViewModels;
|
|
|
|
namespace Weee.Service
|
|
{
|
|
public class WeeeSiteInfoService
|
|
{
|
|
private WeeeDataContext _db;
|
|
|
|
public WeeeSiteInfoService(WeeeDataContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
public WebSiteInfoViewModel GetWebSiteInfo()
|
|
{
|
|
string sysAdminUserId = GetSysAdminUserId();
|
|
if (string.IsNullOrWhiteSpace(sysAdminUserId))
|
|
return null;
|
|
|
|
var list = _db.UserAccountType.Where(x => x.UserId == sysAdminUserId).ToList();
|
|
if (list != null && list.Count() > 0)
|
|
{
|
|
return (from a in list
|
|
select new WebSiteInfoViewModel
|
|
{
|
|
ID = a.ID,
|
|
footerAddress = a.footerAddress,
|
|
footerPhone = a.footerPhone,
|
|
footerFax = a.footerFax,
|
|
footerEmail = a.footerEmail,
|
|
footerCopyright = a.footerCopyright,
|
|
loginImagePath = a.loginImagePath,
|
|
loginImageStyle = a.loginImageStyle,
|
|
text1welcome = a.text1welcome,
|
|
text2Qcarbon = a.text2Qcarbon,
|
|
loginImageBackGroundColor = a.loginImageBackGroundColor
|
|
}).FirstOrDefault();
|
|
}
|
|
else
|
|
return null;
|
|
|
|
}
|
|
|
|
public UserAccountType SaveWebSiteInfo(WebSiteInfoViewModel sour, out string ErrMsg)
|
|
{
|
|
var re = new UserAccountType();
|
|
|
|
string sysAdminUserId = GetSysAdminUserId();
|
|
if (string.IsNullOrWhiteSpace(sysAdminUserId))
|
|
{
|
|
ErrMsg = "尚未設定SystemAdmin使用者";
|
|
return null;
|
|
}
|
|
|
|
var userAccountTypes = _db.UserAccountType.Where(x => x.UserId == sysAdminUserId).ToList();
|
|
if (userAccountTypes != null && userAccountTypes.Count > 0)
|
|
{
|
|
var uat = userAccountTypes.FirstOrDefault();
|
|
uat.footerAddress = sour.footerAddress;
|
|
uat.footerPhone = sour.footerPhone;
|
|
uat.footerFax = sour.footerFax;
|
|
uat.footerEmail = sour.footerEmail;
|
|
uat.footerCopyright = sour.footerCopyright;
|
|
uat.loginImageStyle = sour.loginImageStyle;
|
|
uat.loginImageBackGroundColor = sour.loginImageBackGroundColor;
|
|
uat.text1welcome = sour.text1welcome;
|
|
uat.text2Qcarbon = sour.text2Qcarbon;
|
|
_db.SaveChanges();
|
|
re = uat;
|
|
}
|
|
else
|
|
{
|
|
UserAccountType it = new UserAccountType
|
|
{
|
|
UserId = sysAdminUserId,
|
|
AccountType =(ACCOUNT_TYPE) 1,
|
|
StartTime = new DateTime(2022, 1, 1),
|
|
EndTime = new DateTime(2032, 1, 1),
|
|
Enabled = true,
|
|
footerAddress = sour.footerAddress,
|
|
footerPhone = sour.footerPhone,
|
|
footerFax = sour.footerFax,
|
|
footerEmail = sour.footerEmail,
|
|
footerCopyright = sour.footerCopyright,
|
|
loginImageStyle = sour.loginImageStyle,
|
|
text1welcome = sour.text1welcome,
|
|
text2Qcarbon = sour.text2Qcarbon
|
|
};
|
|
|
|
_db.UserAccountType.Add(it);
|
|
_db.SaveChanges();
|
|
re = it;
|
|
}
|
|
|
|
ErrMsg = "";
|
|
return re;
|
|
}
|
|
|
|
public string GetSysAdminUserId()
|
|
{
|
|
var list = _db.Users.Where(x => x.IsSystemAdmin == true).ToList();
|
|
if (list != null && list.Count() > 0)
|
|
{
|
|
list = list.OrderBy(x => x.Id).ToList();
|
|
return list.FirstOrDefault().Id;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public bool IsSysAdmin(string UserId)
|
|
{
|
|
if(!string.IsNullOrWhiteSpace(UserId))
|
|
{
|
|
var list = _db.Users.Where(x => x.Id == UserId && x.IsSystemAdmin == true).ToList();
|
|
if (list != null && list.Count > 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void DelSiteImg()
|
|
{
|
|
string sysAdminUserId = GetSysAdminUserId();
|
|
var userAccountTypes = _db.UserAccountType.Where(x => x.UserId == sysAdminUserId).ToList();
|
|
if (userAccountTypes != null && userAccountTypes.Count > 0)
|
|
{
|
|
var uat = userAccountTypes.FirstOrDefault();
|
|
uat.loginImagePath = "";
|
|
_db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
}
|
|
} |