using EasyBL.WebApi.Message;
using EasyBL.WEBAPP.ShowEasy;
using EasyBL.WEBAPP.SYS;
using Entity.Sugar;
using Entity.ViewModels;
using Newtonsoft.Json;
using SqlSugar.Base;
using System;
using System.Collections.Generic;
using System.Linq;
namespace EasyBL.WEBAPP.WSM
{
public class ExhibMaintain_UpdService : ServiceBase
{
#region 展覽維護(單筆查詢 call ExhibMaintain_QryService QueryOne)
///
/// 展覽維護(單筆查詢 call ExhibMaintain_QryService QueryOne)
///
///
///
/// Origtek framwork API
public ResponseMessage QueryOne(RequestMessage i_crm)
{
ExhibMaintain_QryService em_qry = new ExhibMaintain_QryService();
ResponseMessage rm = em_qry.QueryOne(i_crm);
return rm;
}
#endregion 展覽維護(單筆查詢 call ExhibMaintain_QryService QueryOne)
public ResponseMessage SaveExhibition(RequestMessage i_crm) {
ResponseMessage rm = null;
var sExhibitionID = _fetchString(i_crm, @"ExhibitionID");
if (string.IsNullOrEmpty(sExhibitionID))
{
sExhibitionID = Guid.NewGuid().ToString();
i_crm.DATA["ExhibitionID"] = sExhibitionID;
Insert(i_crm);
}
else {
Update(i_crm);
}
ExhibMaintain_QryService em_qry = new ExhibMaintain_QryService();
rm = em_qry.QueryOne(i_crm);
return rm;
}
#region 展覽維護(新增)
///
/// 展覽維護(新增)
///
/// todo: describe i_crm parameter on UpdImportCustomers
///
/// Origtek framwork API
public ResponseMessage Insert(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
var sExhibitionID = _fetchString(i_crm, @"ExhibitionID");
if (string.IsNullOrEmpty(sExhibitionID))
{
sExhibitionID = Guid.NewGuid().ToString();
}
LanguageMaintain_QryService lm_qry = new LanguageMaintain_QryService();
List saLanguageList = lm_qry.QueryLanguageList(i_crm);
var iRel = 0;
foreach (SETB_SYS_Language language in saLanguageList)
{
iRel = InsertByLanguage(i_crm, sExhibitionID, language.LanguageID);
}
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ExhibMaintain_UpdService), "", "Insert 展覽維護(新增)", "", "", "");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展覽維護(新增)
#region 展覽維護(以語言新增)
///
/// 展覽維護(以語言新增)
///
///
///
///
public int InsertByLanguage(RequestMessage i_crm, string sExhibitionID, string sLanguage)
{
ResponseMessage rm = null;
string sMsg = null;
var db = SugarBase.GetIntance();
var iRel = 0;
try
{
do
{
if (string.IsNullOrEmpty(sExhibitionID))
{
sExhibitionID = Guid.NewGuid().ToString();
}
var sMainCategoryID = _fetchString(i_crm, @"MainCategoryID");
var sSubCategoryID = _fetchString(i_crm, @"SubCategoryID");
var oEntity = _fetchEntity(i_crm);
_setEntityBase(oEntity, i_crm);
oEntity.ExhibitionID = sExhibitionID;
oEntity.LanguageID = sLanguage;
//oEntity.MainCategoryIDs = sMainCategoryID;
//oEntity.SubCategoryIDs = sSubCategoryID;
oEntity.DelStatus = "N";
if (sLanguage == WebAppGlobalConstWord.EN_US)
{
oEntity.ExhibitionName = _fetchString(i_crm, @"ExhibitionName");
}
iRel = db.Insertable(oEntity).ExecuteCommand();
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ExhibMaintain_UpdService), "", "InsertByLanguage 展覽維護(以語言新增)", "", "", "");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return iRel;
}
#endregion 展覽維護(以語言新增)
#region 展覽維護(修改)
///
/// 展覽維護(修改)
///
/// todo: describe i_crm parameter on UpdImportCustomers
///
/// Origtek framwork API
public ResponseMessage Update(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
var sMainCategoryID = _fetchString(i_crm, @"MainCategoryID");
var sSubCategoryID = _fetchString(i_crm, @"SubCategoryID");
ExhibMaintain_QryService em_qry = new ExhibMaintain_QryService();
var oNewEntity = _fetchEntity(i_crm);
_setEntityBase(oNewEntity, i_crm);
oNewEntity.DelStatus = "N";
var oOldEntity = em_qry.FindOneByIDs(oNewEntity.ExhibitionID, oNewEntity.LanguageID);
if (oNewEntity.OrderByValue > oOldEntity.OrderByValue)
{
var iRelUp = db.Updateable()
.UpdateColumns(x => new SETB_CMS_Exhibition { OrderByValue = x.OrderByValue - 1 })
.Where(x => x.OrgID == oNewEntity.OrgID && x.ExhibitionID == oNewEntity.ExhibitionID && x.OrderByValue <= oNewEntity.OrderByValue && x.OrderByValue > oOldEntity.OrderByValue).ExecuteCommand();
}
else
{
var iRelDown = db.Updateable()
.UpdateColumns(x => new SETB_CMS_Exhibition { OrderByValue = x.OrderByValue + 1 })
.Where(x => x.OrgID == oNewEntity.OrgID && x.ExhibitionID == oNewEntity.ExhibitionID && x.OrderByValue >= oNewEntity.OrderByValue && x.OrderByValue < oOldEntity.OrderByValue).ExecuteCommand();
}
// Update all
var iRelAll = db.Updateable(oNewEntity).IgnoreColumns(x => new
{
x.CreateUser,
x.CreateDate,
x.LanguageID,
x.ExhibitionName,
x.AbbreviatedName
}).Where(x => x.OrgID == oNewEntity.OrgID && x.ExhibitionID == oNewEntity.ExhibitionID).ExecuteCommand();
// Update self
var iRel = db.Updateable(oNewEntity)
.IgnoreColumns(x => new
{
x.CreateUser,
x.CreateDate
}).ExecuteCommand();
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ExhibMaintain_UpdService), "", "Update 展覽維護(修改)", "", "", "");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展覽維護(修改)
#region 展覽維護(刪除)
///
/// 展覽維護(刪除)
///
///
///
/// Origtek framwork API
public ResponseMessage Delete(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
// hard delete Exhibition
var sExhibitionID = _fetchString(i_crm, @"ExhibitionID");
var iRel = db.Deleteable()
.Where(t1 => t1.ExhibitionID == sExhibitionID)
.ExecuteCommand();
// hard delete ExhibInfo
ExhibInfoMaintain_UpdService em_upd = new ExhibInfoMaintain_UpdService();
em_upd.Delete(i_crm);
// hard delete ExhibStatistics
ExhibStatMaintain_UpdService esm_upd = new ExhibStatMaintain_UpdService();
esm_upd.Delete(i_crm);
// hard delete ExhibMedia
ExhibMediaMaintain_UpdService emm_upd = new ExhibMediaMaintain_UpdService();
emm_upd.Delete(i_crm);
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ExhibMaintain_UpdService), "", "Delete 展覽維護(刪除)", "", "", "");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展覽維護(刪除)
#region 展覽維護(更新排序)
///
/// 展覽維護(更新排序)
///
///
///
/// Origtek framwork API
public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
var sExhibitionID = _fetchString(i_crm, @"Id");
if (!String.IsNullOrEmpty(_fetchString(i_crm, @"ExhibitionID")))
{
sExhibitionID = _fetchString(i_crm, @"ExhibitionID");
}
var sLanguageID = _fetchString(i_crm, @"LanguageID");
if (string.IsNullOrEmpty(sLanguageID))
{
sLanguageID = WebAppGlobalConstWord.DEFAULT_LANGUAGE;
}
var iOldOrderByValue = _fetchInt(i_crm, @"OldOrderByValue");
var iNewOrderByValue = _fetchInt(i_crm, @"NewOrderByValue");
var oOrderEntity = db.Queryable().Single(x => x.OrgID == i_crm.ORIGID && x.ExhibitionID == sExhibitionID && x.LanguageID == sLanguageID);
if (iNewOrderByValue > iOldOrderByValue)
{
var iRelUp = db.Updateable()
.UpdateColumns(x => new SETB_CMS_Exhibition { OrderByValue = x.OrderByValue - 1 })
.Where(x => x.OrgID == oOrderEntity.OrgID && x.OrderByValue <= iNewOrderByValue && x.OrderByValue > iOldOrderByValue)
.ExecuteCommand();
}
else
{
var iRelDown = db.Updateable()
.UpdateColumns(x => new SETB_CMS_Exhibition { OrderByValue = x.OrderByValue + 1 })
.Where(x => x.OrgID == oOrderEntity.OrgID && x.OrderByValue >= iNewOrderByValue && x.OrderByValue < iOldOrderByValue)
.ExecuteCommand();
}
var iRelSelf = db.Updateable(new SETB_CMS_Exhibition { OrderByValue = iNewOrderByValue })
.UpdateColumns(x => x.OrderByValue)
.Where(x => x.OrgID == i_crm.ORIGID && x.ExhibitionID == sExhibitionID).ExecuteCommand();
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRelSelf);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ExhibMaintain_UpdService), "", "UpdateOrderByValue 展覽維護(更新排序)", "", "", "");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展覽維護(更新排序)
#region 展覽維護(查詢筆數 call ExhibMaintain_QryService QueryCout)
///
/// 展覽維護(查詢筆數 call ExhibMaintain_QryService QueryCout)
///
///
///
/// Origtek framwork API
public ResponseMessage QueryCout(RequestMessage i_crm)
{
ExhibMaintain_QryService em_qry = new ExhibMaintain_QryService();
ResponseMessage rm = em_qry.QueryCout(i_crm);
return rm;
}
#endregion 展覽維護(查詢筆數 call ExhibMaintain_QryService QueryCout)
#region 展覽主類別查詢 (List call ExhibMainCategoryMaintain_QryService QueryExhibMainCategoryList)
public ResponseMessage QueryExhibMainCategoryList(RequestMessage i_crm)
{
ExhibMainCategoryMaintain_QryService emcm_qry = new ExhibMainCategoryMaintain_QryService();
ResponseMessage rm = emcm_qry.QueryExhibMainCategoryList(i_crm);
return rm;
}
#endregion 展覽主類別查詢 (List call ExhibMainCategoryMaintain_QryService QueryExhibMainCategoryList)
#region 展覽子類別查詢 (List call ExhibSubCategoryMaintain_QryService QueryExhibSubCategoryList)
public ResponseMessage QueryExhibSubCategoryList(RequestMessage i_crm)
{
ExhibSubCategoryMaintain_QryService escm_qry = new ExhibSubCategoryMaintain_QryService();
ResponseMessage rm = escm_qry.QueryExhibSubCategoryList(i_crm);
return rm;
}
#endregion 展覽子類別查詢 (List call ExhibSubCategoryMaintain_QryService QueryExhibSubCategoryList)
#region 展覽維護(查詢展覽資訊 call ExhibInfoMaintain_QryService QueryExhibInfo)
///
/// 展覽維護(查詢展覽資訊 call ExhibMaintain_QryService QueryExhibInfo)
///
///
///
///
public ResponseMessage QueryOneExhibInfo(RequestMessage i_crm)
{
ExhibInfoMaintain_QryService eim_qry = new ExhibInfoMaintain_QryService();
ResponseMessage rm = eim_qry.QueryOneExhibInfo2(i_crm);
return rm;
}
#endregion 展覽維護(查詢展覽資訊 call ExhibInfoMaintain_QryService QueryExhibInfo)
#region 展覽維護(處存展覽資訊 call ExhibInfoMaintain_UpdService Insert/Update)
///
/// 展覽維護(處存展覽資訊 call ExhibInfoMaintain_UpdService Insert/Update)
///
///
///
///
public ResponseMessage SaveExhibInfo(RequestMessage i_crm)
{
ResponseMessage rm = null;
var ExhibInfo = _fetchEntity(i_crm);
System.Diagnostics.Debug.WriteLine("ExhibInfo.ExhibitionInfoID" + ": " + ExhibInfo.ExhibitionInfoID);
ExhibInfoMaintain_UpdService eim_upd = new ExhibInfoMaintain_UpdService();
if (string.IsNullOrEmpty(ExhibInfo.ExhibitionInfoID))
{
rm = eim_upd.Insert(i_crm);
}
else
{
rm = eim_upd.Update(i_crm);
}
return rm;
}
#endregion 展覽維護(處存展覽資訊 call ExhibInfoMaintain_UpdService Insert/Update)
#region 展覽維護(處存統計 call ExhibInfoMaintain_UpdService Insert/Update)
///
/// 展覽維護(處存統計 call ExhibInfoMaintain_UpdService Insert/Update)
///
///
///
///
public ResponseMessage SaveStat(RequestMessage i_crm)
{
ResponseMessage rm = null;
var Stats = JsonConvert.DeserializeObject>(_fetchString(i_crm, @"Stats"));
ExhibStatMaintain_UpdService esm_upd = new ExhibStatMaintain_UpdService();
ExhibStatMaintain_QryService esm_qry = new ExhibStatMaintain_QryService();
// Hard delete all
esm_upd.HardDeleteAll(i_crm, Stats.FirstOrDefault().ExhibitionID);
foreach (var stat in Stats)
{
if (esm_qry.Exists(i_crm, stat.ExhibitionID, stat.Year))
{
rm = esm_upd.Update(i_crm, stat);
}
else
{
rm = esm_upd.Insert(i_crm, stat);
}
}
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, Stats);
return rm;
}
#endregion 展覽維護(處存統計 call ExhibInfoMaintain_UpdService Insert/Update)
#region 展覽維護(List 查詢展覽統計 call ExhibStatMaintain_QryService QueryStatisticList)
/// 展覽維護(List 查詢展覽統計 call ExhibStatMaintain_QryService QueryStatisticList)
///
///
///
///
public ResponseMessage QueryStatisticsList(RequestMessage i_crm)
{
ExhibStatMaintain_QryService esm_qry = new ExhibStatMaintain_QryService();
ResponseMessage rm = esm_qry.QueryStatisticsList(i_crm);
return rm;
}
#endregion 展覽維護(List 查詢展覽統計 call ExhibStatMaintain_QryService QueryStatisticList)
#region 展覽維護(List 查詢洲別選單 call RegionMaintain_QryService QueryRegionList)
/// 展覽維護(List 查詢洲別選單 call RegionMaintain_QryService QueryRegionList)
///
///
///
///
public ResponseMessage QueryRegionList(RequestMessage i_crm)
{
RegionMaintain_QryService rm_qry = new RegionMaintain_QryService();
ResponseMessage rm = rm_qry.QueryRegionList(i_crm);
return rm;
}
#endregion 展覽維護(List 查詢洲別選單 call RegionMaintain_QryService QueryRegionList)
#region 展覽維護(List 查詢國家選單 call CountryMaintain_QryService QueryCountryList)
/// 展覽維護(List 查詢國家選單 call CountryMaintain_QryService QueryCountryList)
///
///
///
///
public ResponseMessage QueryCountryList(RequestMessage i_crm)
{
CountryMaintain_QryService cm_qry = new CountryMaintain_QryService();
ResponseMessage rm = cm_qry.QueryCountryList(i_crm);
return rm;
}
#endregion 展覽維護(List 查詢國家選單 call CountryMaintain_QryService QueryCountryList)
#region 展覽維護(List 查詢國家選單 call CityMaintain_QryService QueryCityList)
/// 展覽維護(List 查詢國家選單 call CityMaintain_QryService QueryCityList)
///
///
///
///
public ResponseMessage QueryCityList(RequestMessage i_crm)
{
CityMaintain_QryService cm_qry = new CityMaintain_QryService();
ResponseMessage rm = cm_qry.QueryCityList(i_crm);
return rm;
}
#endregion 展覽維護(List 查詢國家選單 call CityMaintain_QryService QueryCityList)
#region 展覽維護(List 查詢展館選單 call VenueMaintain_QryService QueryVenueList)
/// 展覽維護(List 查詢展館選單 call VenueMaintain_QryService QueryVenueList)
///
///
///
///
public ResponseMessage QueryVenueList(RequestMessage i_crm)
{
VenueMaintain_QryService vm_qry = new VenueMaintain_QryService();
ResponseMessage rm = vm_qry.QueryVenueList(i_crm);
return rm;
}
#endregion 展覽維護(List 查詢展館選單 call VenueMaintain_QryService QueryVenueList)
#region 展覽維護(List 查詢主辦單位選單 call OrganizerMaintain_QryService QueryOrganizerList)
/// 展覽維護(List 查詢主辦單位選單 call OrganizerMaintain_QryService QueryOrganizerList)
///
///
///
///
public ResponseMessage QueryOrganizerList(RequestMessage i_crm)
{
OrganizerMaintain_QryService om_qry = new OrganizerMaintain_QryService();
ResponseMessage rm = om_qry.QueryOrganizerList(i_crm);
return rm;
}
#endregion 展覽維護(List 查詢主辦單位選單 call OrganizerMaintain_QryService QueryOrganizerList)
#region 語言選單(call LanguageMaintainQryService QueryList)
///
/// 語言選單(call LanguageMaintainQryService QueryList)
///
///
///
public ResponseMessage QueryLanguageList(RequestMessage i_crm)
{
LanguageMaintain_QryService lm_upd = new LanguageMaintain_QryService();
ResponseMessage rm = lm_upd.QueryList(i_crm);
return rm;
}
#endregion 語言選單(call LanguageMaintainQryService QueryList)
#region 展覽管理(List 查詢展覽狀態 call ExhibMaintain_QryService QueryShowStatusList)
///
/// 展覽管理(List 查詢展覽狀態 call ExhibMaintain_QryService QueryShowStatusList)
///
///
///
public ResponseMessage QueryShowStatusList(RequestMessage i_crm)
{
ExhibMaintain_QryService em_qry = new ExhibMaintain_QryService();
ResponseMessage rm = em_qry.QueryShowStatusList(i_crm);
return rm;
}
#endregion 展覽管理(List 查詢展覽狀態 call ExhibMaintain_QryService QueryShowStatusList)
#region 展覽管理(List 查詢展覽週期選單 call ExhibMaintain_QryService QueryFrequencyList)
///
/// 展覽管理(List 查詢展覽週期選單 call ExhibMaintain_QryService QueryFrequencyList)
///
///
///
public ResponseMessage QueryFrequencyList(RequestMessage i_crm)
{
ExhibMaintain_QryService em_qry = new ExhibMaintain_QryService();
ResponseMessage rm = em_qry.QueryFrequencyList(i_crm);
return rm;
}
#endregion 展覽管理(List 查詢展覽週期選單 call ExhibMaintain_QryService QueryFrequencyList)
#region 展覽管理(List 查詢多媒體 call ExhibMaintain_QryService QueryMediaList)
///
/// 展覽管理(List 查詢多媒體 call ExhibMaintain_QryService QueryMediaList)
///
///
///
public ResponseMessage QueryMediaList(RequestMessage i_crm)
{
ExhibMediaMaintain_QryService emm_qry = new ExhibMediaMaintain_QryService();
ResponseMessage rm = emm_qry.QueryMediaList(i_crm);
return rm;
}
#endregion 展覽管理(List 查詢多媒體 call ExhibMaintain_QryService QueryMediaList)
#region 展覽維護(處存展覽多媒體 call ExhibMediaMaintain_UpdService Insert/Update)
///
/// 展覽維護(處存展覽多媒體 call ExhibMediaMaintain_UpdService Insert/Update)
///
///
///
///
public ResponseMessage SaveMediaList(RequestMessage i_crm)
{
ResponseMessage rm = null;
var MediaList = JsonConvert.DeserializeObject>(_fetchString(i_crm, @"MediaList"));
ExhibMediaMaintain_UpdService emm_upd = new ExhibMediaMaintain_UpdService();
ExhibMediaMaintain_QryService emm_qry = new ExhibMediaMaintain_QryService();
// Hard delete all
emm_upd.HardDeleteAll(i_crm, MediaList.FirstOrDefault().ExhibitionID);
foreach (var Media in MediaList)
{
if (emm_qry.Exists(i_crm, Media.MediaID, Media.ExhibitionID))
{
rm = emm_upd.Update(i_crm, Media);
}
else
{
rm = emm_upd.Insert(i_crm, Media);
}
}
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, MediaList);
return rm;
}
#endregion 展覽維護(處存展覽多媒體 call ExhibMediaMaintain_UpdService Insert/Update)
}
}