Monitoring NET MVC
***********************************************
MonitoringRepositories.cs
***********************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EightElements.CMT.Data.Models;
using EightElements.CMT.Data.Repository;
namespace EightElements.CMT.Data.Repository
{
public class MonitoringRepository
{
public static List<PortalManagementDTO> GetPortalManagement(int userId)
{
using (var dc = new Entities())
{
var list = new List<PortalManagementDTO>();
var countPortalManagement = (from obj1 in dc.PortalManagements where obj1.IsActive == true select obj1).OrderByDescending(x => x.Title).ToList();
var objPortalId = countPortalManagement.Select(x => x.PortalID).ToList();
var objKey = new string[] { "AffiliateDailyLimit", "DailySubscriptionLimit" };
var queryData = (from obj2 in dc.PortalPageTexts where obj2.LanguageCode == "en" && objKey.Contains(obj2.Key) && objPortalId.Contains(obj2.PortalId) select obj2).ToList();
for (var i = 0; countPortalManagement.Count > i; i++) {
var getPortalId = countPortalManagement[i].PortalID;
var GetPortalLimitLocal = queryData.Where(x => x.Key == "DailySubscriptionLimit" && x.PortalId == getPortalId).Select(x => x.Text).FirstOrDefault();
var GetAffiliateLimitLocal = queryData.Where(x => x.Key == "AffiliateDailyLimit" && x.PortalId == getPortalId).Select(x => x.Text).FirstOrDefault();
var data = new PortalManagementDTO()
{
Id = countPortalManagement[i].ID,
PortalId = getPortalId,
PortalName = countPortalManagement[i].Title,
PortalLimit = GetPortalLimitLocal,
AffiliateLimit = GetAffiliateLimitLocal
};
list.Add(data);
}
var getPortalRanking = (from objPortalRanking in dc.UserInfoProjects where objPortalRanking.ID == userId select objPortalRanking.PortalRanking).FirstOrDefault();
if (!string.IsNullOrEmpty(getPortalRanking))
{
var ranking = getPortalRanking.Split(',').Select(Int32.Parse).ToList();
list = list.OrderBy(x => ranking.IndexOf(x.Id)).ToList();
}
return list ;
}
}
public static void UpdateRanking(string ranking, int getIdUserInfo)
{
using (var dc = new Entities())
{
var data = (from obj1 in dc.UserInfoProjects where obj1.ID == getIdUserInfo select obj1).FirstOrDefault();
if (data != null)
{
data.PortalRanking = ranking;
dc.SaveChanges();
}
}
}
}
}
***********************************************
MonitoringController.cs
***********************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EightElements.CMT.Data;
using EightElements.CMT.Data.Models;
using EightElements.CMT.Data.Repository;
namespace EightElements.CampaingManagementTools.Controllers
{
public class MonitoringController : Controller
{
// GET: Monitoring
public ActionResult Index()
{
if (Session["UserInfoProject"] == null) return RedirectToAction("LoginPage", "Home");
return View();
}
public ActionResult GetPortalManagement()
{
var list = new List<PortalManagementDTO>();
var userInfo = (UserInfoProject)Session["UserInfoProject"];
var getIdUserInfo = userInfo.ID;
var data = MonitoringRepository.GetPortalManagement(getIdUserInfo);
foreach (var row in data)
{
if (!string.IsNullOrEmpty(row.AffiliateLimit))
{
var GetSplitAffiliateLimit = row.AffiliateLimit.Split('|');
row.SplitAffiliateLimit = GetSplitAffiliateLimit;
}
list.Add(row);
}
return Json(new { Success = true, Data = list }, JsonRequestBehavior.AllowGet);
}
public ActionResult UpdateRanking(string ranking)
{
var userInfo = (UserInfoProject)Session["UserInfoProject"];
var getIdUserInfo = userInfo.ID;
MonitoringRepository.UpdateRanking(ranking, getIdUserInfo);
return Content("Success");
}
}
}
***********************************************
(Campaign Management Tool/MMT)
monitoring/index
***********************************************
@using System.Configuration;
@{
ViewBag.Title = "Index";
string prefix = ConfigurationManager.AppSettings["PrefixUrl"];
}
<div class="col-xs-12 no-pad">
<h2>Monitoring</h2>
</div>
<div class="row monitoring-wrap">
<div id="txtBody"></div>
</div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script>
$(document).ready(function () {
GetPortalManagement();
});
function GetPortalManagement() {
$.ajax({
url: '@prefix/Monitoring/getportalManagement',
success: function (response) {
if (response.Success) {
var content = "";
var sortData = "";
for (var i = 0; i < response.Data.length; i++) {
var getData = response.Data[i];
@* sortData += i;*@
@*const array5 = [1, 70, 3];
array5.sort((a, b) => {
return a - b;
});*@
content += `<div draggable="true" class="box col-xs-12 col-sm-4 col-md-4"><div class="column"><div class="card">`;
content += `<h3 class="idportal" style="display:none;">${getData.Id}</h3>`;
content += `<h3>${getData.PortalName}</h3>`;
content += `<div class="port-limit"><p>Portal Limit : <strong>${getData.PortalLimit}</strong></p>`;
var limitData = "-";
if (getData.SplitAffiliateLimit != null) {
limitData = getData.SplitAffiliateLimit[0].replace(":", "");
getData.SplitAffiliateLimit.splice(0, 1);
}
content += `<p>Affiliate Limit : <strong>${limitData}</strong></p></div>`;
content += `<div class='aff-body'>`;
const arrayDesc = getData.SplitAffiliateLimit;
if (getData.SplitAffiliateLimit != null) {
arrayDesc.sort((a, b) => {
var a1 = a.split(":");
var b1 = b.split(":");
return parseInt(b1[1]) - parseInt(a1[1]);
});
for (var a = 0; a < arrayDesc.length; a++) {
var splitText = arrayDesc[a].split(":");
content += `<p><span>${splitText[0]} </span> <span>${splitText[1]}</span> </p>`;
}
}
content += `</div></div></div></div>`;
}
@*const array1 = ["Gorilla:500", "Xsparrow:300", "TimeRose:100"];
array1.sort((a, b) => {
var a1 = a.split(":");
var b1 = b.split(":");
return parseInt(a1[1]) - parseInt(b1[1]);
});*@
$("#txtBody").html(content);
}
let items = document.querySelectorAll('.row .box');
items.forEach(function (item) {
item.addEventListener('dragstart', handleDragStart, false);
item.addEventListener('dragenter', handleDragEnter, false);
item.addEventListener('dragover', handleDragOver, false);
item.addEventListener('dragleave', handleDragLeave, false);
item.addEventListener('drop', handleDrop, false);
item.addEventListener('dragend', handleDragEnd, false);
});
},
error: function () { alert("ERROR PAGE") }
});
}
var dragSrcEl = null;
function handleDragStart(e) {
this.style.opacity = '0.4';
dragSrcEl = this;
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', this.innerHTML);
}
function handleDragOver(e) {
if (e.preventDefault) {
e.preventDefault();
}
e.dataTransfer.dropEffect = 'move';
return false;
}
function handleDragEnter(e) {
this.classList.add('over');
}
function handleDragLeave(e) {
this.classList.remove('over');
}
function handleDrop(e) {
if (e.stopPropagation) {
e.stopPropagation(); // stops the browser from redirecting.
}
if (dragSrcEl != this) {
dragSrcEl.innerHTML = this.innerHTML;
this.innerHTML = e.dataTransfer.getData('text/html');
}
return false;
}
function handleDragEnd(e) {
this.style.opacity = '1';
let items = document.querySelectorAll('.row .box');
items.forEach(function (item) {
item.classList.remove('over');
});
rankingProses();
}
function rankingProses() {
a = $(".idportal");
var conArray = [];
for (i = 0; i < a.length; i++) {
conArray[i] = parseInt($(a[i]).html());
}
console.log(conArray);
var conArrayToString = conArray.toString();
console.log(conArrayToString);
$.ajax({
url: '@prefix/Monitoring/UpdateRanking?ranking=' + conArrayToString,
success: function (response) { console.log(response) },
error: function () { alert("Error Page")}
});
}
//Drag And Drop Function
document.addEventListener('DOMContentLoaded', (event) => {
});
</script>
Tidak ada komentar