public override void RemoveChatRequest(ChatRequest req) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { db.LiveChat_ChatRequests.DeleteAllOnSubmit(db.LiveChat_ChatRequests.Where(x => x.ChatID == req.ChatId)); db.SubmitChanges(); } }
public override bool Delete(Operator op) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { db.LiveChat_Operators.DeleteAllOnSubmit(db.LiveChat_Operators.Where(x => x.OperatorID == op.OperatorId)); db.SubmitChanges(); return(true); } }
public override void UpdateStatus(int operatorId, bool isOnline) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var op = db.LiveChat_Operators.SingleOrDefault(x => x.OperatorID == operatorId); if (op != null) { op.IsOnline = isOnline; db.SubmitChanges(); } } }
public override void UpdateStatus(int operatorId, bool isOnline) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var op = db.LiveChat_Operators.SingleOrDefault(x => x.OperatorID == operatorId); if (op != null) { op.IsOnline = isOnline; db.SubmitChanges(); } } }
public override Guid RequestChat(ChatRequest request) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { if (request.Department == null) { request.Department = ""; } var existing = db.LiveChat_ChatRequests.SingleOrDefault(x => x.VisitorIP == request.VisitorIp && x.OperatorID == -1); if (existing != null) { return(existing.ChatID); } // Get the less busy operator int operatorId = -1; var results = from o in db.LiveChat_Operators join c in db.LiveChat_ChatRequests on o.OperatorID equals c.OperatorID into req from r in req.DefaultIfEmpty() where o.IsOnline && o.Department.Contains(request.Department) group o by o.OperatorID into g select new { Id = g.Key, Count = g.Count() }; if (results != null && results.Count() > 0) { operatorId = results.OrderBy(x => x.Count).First().Id; } else { // WTH operatorId = db.LiveChat_Operators.First(x => x.IsOnline).OperatorID; } LiveChat_ChatRequest entity = new LiveChat_ChatRequest(); entity.ChatID = request.ChatId; entity.Department = request.Department; entity.OperatorID = operatorId; entity.RequestDate = DateTime.Now; entity.VisitorEmail = request.VisitorEmail; entity.VisitorIP = request.VisitorIp; entity.VisitorName = request.VisitorName; entity.VisitorUserAgent = request.VisitorUserAgent.Length > 100 ? request.VisitorUserAgent.Substring(0, 100) : request.VisitorUserAgent; db.LiveChat_ChatRequests.InsertOnSubmit(entity); db.SubmitChanges(); return(entity.ChatID); } }
public override void AddChatMessage(ChatMessage msg) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { LiveChat_ChatMessage entity = new LiveChat_ChatMessage(); entity.ChatID = msg.ChatId; entity.FromName = msg.Name; entity.Message = msg.Message; //TODO: Change SentDate to DateTime //entity.SentDate = DateTime.Now; db.LiveChat_ChatMessages.InsertOnSubmit(entity); db.SubmitChanges(); } }
public override bool RejectInvite(ChatRequest req) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var entity = db.LiveChat_ChatRequests.SingleOrDefault(x => x.ChatID == req.ChatId); if (entity != null) { entity.ClosedDate = DateTime.Now; entity.Department = "visitor-rejected"; db.SubmitChanges(); return(true); } return(false); } }
public override bool LogRequest(WebRequest req) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { LiveChat_LogAccess webrequest = new LiveChat_LogAccess(); webrequest.DomainRequested = req.DomainName; webrequest.PageRequested = req.PageRequested; webrequest.Referrer = req.Referrer; webrequest.RequestedTime = DateTime.Now; webrequest.VisitorIP = req.VisitorIp; webrequest.VisitorUserAgent = req.VisitorUserAgent.Length > 100 ? req.VisitorUserAgent.Substring(0, 100) : req.VisitorUserAgent; db.LiveChat_LogAccesses.InsertOnSubmit(webrequest); db.SubmitChanges(); return true; } }
public override bool LogRequest(WebRequest req) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { LiveChat_LogAccess webrequest = new LiveChat_LogAccess(); webrequest.DomainRequested = req.DomainName; webrequest.PageRequested = req.PageRequested; webrequest.Referrer = req.Referrer; webrequest.RequestedTime = DateTime.Now; webrequest.VisitorIP = req.VisitorIp; webrequest.VisitorUserAgent = req.VisitorUserAgent.Length > 100 ? req.VisitorUserAgent.Substring(0, 100) : req.VisitorUserAgent; db.LiveChat_LogAccesses.InsertOnSubmit(webrequest); db.SubmitChanges(); return(true); } }
public override bool AcceptRequest(Guid id, int operatorId) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var req = db.LiveChat_ChatRequests.SingleOrDefault(x => x.ChatID == id); if (req != null) { req.AcceptDate = DateTime.Now; db.SubmitChanges(); return(true); } return(false); } }
public override ChatRequest InviteVisitor(int operatorId, string visitorIp, string prompt) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { LiveChat_ChatRequest invite = new LiveChat_ChatRequest(); invite.AcceptDate = null; invite.ChatID = Guid.NewGuid(); invite.ClosedDate = null; //HACK: this will serve as an indicator when visitor display chat button invite.Department = "op-invite"; invite.OperatorID = operatorId; invite.RequestDate = DateTime.Now; invite.VisitorEmail = ""; invite.VisitorIP = visitorIp; invite.VisitorName = "Me"; invite.VisitorUserAgent = ""; db.LiveChat_ChatRequests.InsertOnSubmit(invite); try { db.SubmitChanges(); ChatRequest req = new ChatRequest(); req.Accepted = null; req.ChatId = invite.ChatID; req.Closed = null; req.Department = invite.Department; req.OperatorId = invite.OperatorID; req.Requested = invite.RequestDate; req.VisitorEmail = invite.VisitorEmail; req.VisitorIp = invite.VisitorIP; req.VisitorName = invite.VisitorName; req.VisitorUserAgent = invite.VisitorUserAgent; req.WasAccepted = false; return(req); } catch { throw; } } }
public override ChatRequest CheckForInvites(string visitorIp) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var invites = db.LiveChat_ChatRequests.OrderByDescending(x => x.RequestDate).Where(x => x.VisitorIP == visitorIp && x.Department == "op-invite" && x.AcceptDate == null && x.ClosedDate == null).ToList(); if (invites != null && invites.Count() > 0) { // do they have more than 1 invite var invite = invites.First(); if (invites.Count() > 1) { invites.Remove(invite); foreach (var inv in invites) { inv.ClosedDate = DateTime.Now; inv.Department = "Visitor had more than 1 invite pending..."; } db.SubmitChanges(); } ChatRequest req = new ChatRequest(); req.Accepted = null; req.ChatId = invite.ChatID; req.Closed = null; req.Department = invite.Department; req.OperatorId = invite.OperatorID; req.Requested = invite.RequestDate; req.VisitorEmail = invite.VisitorEmail; req.VisitorIp = invite.VisitorIP; req.VisitorName = invite.VisitorName; req.VisitorUserAgent = invite.VisitorUserAgent; req.WasAccepted = false; return(req); } return(null); } }
public override bool Save(Operator op) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var entity = db.LiveChat_Operators.SingleOrDefault(x => x.OperatorID == op.OperatorId); if (entity == null) { entity = new LiveChat_Operator(); db.LiveChat_Operators.InsertOnSubmit(entity); } entity.Department = op.Department; entity.OperatorEmail = op.Email; entity.OperatorName = op.OperatorName; entity.OperatorPassword = op.Password.Length == 0 ? entity.OperatorPassword : op.Password; db.SubmitChanges(); return(true); } }
public override bool CreateDatabase(string password) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { //TODO: Refactor this db.ExecuteCommand(@" CREATE TABLE [dbo].[LiveChat_ChatMessages]( [MessageID] [bigint] IDENTITY(1,1) NOT NULL, [ChatID] [uniqueidentifier] NOT NULL, [FromName] [varchar](100) NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatMessages_FromName] DEFAULT (''), [Message] [varchar](3000) NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatMessages_Message] DEFAULT (''), [SentDate] [bigint] NOT NULL, CONSTRAINT [PK_ASPLiveSupport_ChatMessages] PRIMARY KEY CLUSTERED ( [MessageID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[LiveChat_ChatRequests]( [ChatID] [uniqueidentifier] NOT NULL, [VisitorIP] [varchar](50) NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatRequests_VisitorIP] DEFAULT (''), [VisitorName] [varchar](100) NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_VisitorName] DEFAULT (''), [VisitorEmail] [varchar](225) NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_VisitorEmail] DEFAULT (''), [VisitorUserAgent] [varchar](125) NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_VisitorUserAgent] DEFAULT (''), [OperatorID] [int] NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_OperatorID] DEFAULT ((-1)), [Department] varchar(100) NULL, [RequestDate] [smalldatetime] NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatRequests_RequestDate] DEFAULT (getdate()), [AcceptDate] [smalldatetime] NULL, [ClosedDate] [smalldatetime] NULL, CONSTRAINT [PK_ASPLiveSupport_ChatRequests] PRIMARY KEY CLUSTERED ( [ChatID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[LiveChat_LogAccess]( [LogAccessID] [int] IDENTITY(1,1) NOT NULL, [PageRequested] [varchar](500) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_PageRequested] DEFAULT (''), [DomainRequested] [varchar](250) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_DomainRequested] DEFAULT (''), [RequestedTime] [smalldatetime] NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_RequestedTime] DEFAULT (getdate()), [Referrer] [varchar](500) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_Referrer] DEFAULT (''), [VisitorUserAgent] [varchar](100) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_VisitorUserAgent] DEFAULT (''), [VisitorIP] [varchar](50) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_VisitorIP] DEFAULT (''), CONSTRAINT [PK_ASPLiveSupport_LogAccess] PRIMARY KEY CLUSTERED ( [LogAccessID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[LiveChat_Operators]( [OperatorID] [int] IDENTITY(1,1) NOT NULL, [OperatorName] [varchar](100) NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorName] DEFAULT (''), [OperatorPassword] [varchar](50) NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorPassword] DEFAULT ('nopw'), [OperatorEmail] [varchar](250) NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorEmail] DEFAULT (''), [IsOnline] [bit] NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorStatus] DEFAULT ((0)), Department varchar(500) NOT NULL CONSTRAINT [DF_LiveChat_Operators_Department] DEFAULT ('support'), CONSTRAINT [PK_ASPLiveSupport_Operators] PRIMARY KEY CLUSTERED ( [OperatorID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] "); LiveChat_Operator admin = new LiveChat_Operator(); admin.Department = ""; admin.IsOnline = false; admin.OperatorEmail = "*****@*****.**"; admin.OperatorName = "admin"; admin.OperatorPassword = password; db.LiveChat_Operators.InsertOnSubmit(admin); db.SubmitChanges(); return(true); } }
public override ChatRequest InviteVisitor(int operatorId, string visitorIp, string prompt) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { LiveChat_ChatRequest invite = new LiveChat_ChatRequest(); invite.AcceptDate = null; invite.ChatID = Guid.NewGuid(); invite.ClosedDate = null; //HACK: this will serve as an indicator when visitor display chat button invite.Department = "op-invite"; invite.OperatorID = operatorId; invite.RequestDate = DateTime.Now; invite.VisitorEmail = ""; invite.VisitorIP = visitorIp; invite.VisitorName = "Me"; invite.VisitorUserAgent = ""; db.LiveChat_ChatRequests.InsertOnSubmit(invite); try { db.SubmitChanges(); ChatRequest req = new ChatRequest(); req.Accepted = null; req.ChatId = invite.ChatID; req.Closed = null; req.Department = invite.Department; req.OperatorId = invite.OperatorID; req.Requested = invite.RequestDate; req.VisitorEmail = invite.VisitorEmail; req.VisitorIp = invite.VisitorIP; req.VisitorName = invite.VisitorName; req.VisitorUserAgent = invite.VisitorUserAgent; req.WasAccepted = false; return req; } catch { throw; } } }
public override bool RejectInvite(ChatRequest req) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var entity = db.LiveChat_ChatRequests.SingleOrDefault(x => x.ChatID == req.ChatId); if (entity != null) { entity.ClosedDate = DateTime.Now; entity.Department = "visitor-rejected"; db.SubmitChanges(); return true; } return false; } }
public override Guid RequestChat(ChatRequest request) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { if (request.Department == null) request.Department = ""; var existing = db.LiveChat_ChatRequests.SingleOrDefault(x => x.VisitorIP == request.VisitorIp && x.OperatorID == -1); if (existing != null) return existing.ChatID; // Get the less busy operator int operatorId = -1; var results = from o in db.LiveChat_Operators join c in db.LiveChat_ChatRequests on o.OperatorID equals c.OperatorID into req from r in req.DefaultIfEmpty() where o.IsOnline && o.Department.Contains(request.Department) group o by o.OperatorID into g select new { Id = g.Key, Count = g.Count() }; if (results != null && results.Count() > 0) operatorId = results.OrderBy(x => x.Count).First().Id; else { // WTH operatorId = db.LiveChat_Operators.First(x => x.IsOnline).OperatorID; } LiveChat_ChatRequest entity = new LiveChat_ChatRequest(); entity.ChatID = request.ChatId; entity.Department = request.Department; entity.OperatorID = operatorId; entity.RequestDate = DateTime.Now; entity.VisitorEmail = request.VisitorEmail; entity.VisitorIP = request.VisitorIp; entity.VisitorName = request.VisitorName; entity.VisitorUserAgent = request.VisitorUserAgent.Length > 100 ? request.VisitorUserAgent.Substring(0, 100) : request.VisitorUserAgent; db.LiveChat_ChatRequests.InsertOnSubmit(entity); db.SubmitChanges(); return entity.ChatID; } }
public override void AddChatMessage(ChatMessage msg) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { LiveChat_ChatMessage entity = new LiveChat_ChatMessage(); entity.ChatID = msg.ChatId; entity.FromName = msg.Name; entity.Message = msg.Message; //TODO: Change SentDate to DateTime //entity.SentDate = DateTime.Now; db.LiveChat_ChatMessages.InsertOnSubmit(entity); db.SubmitChanges(); } }
public override bool CreateDatabase(string password) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { //TODO: Refactor this db.ExecuteCommand(@" CREATE TABLE [dbo].[LiveChat_ChatMessages]( [MessageID] [bigint] IDENTITY(1,1) NOT NULL, [ChatID] [uniqueidentifier] NOT NULL, [FromName] [varchar](100) NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatMessages_FromName] DEFAULT (''), [Message] [varchar](3000) NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatMessages_Message] DEFAULT (''), [SentDate] [bigint] NOT NULL, CONSTRAINT [PK_ASPLiveSupport_ChatMessages] PRIMARY KEY CLUSTERED ( [MessageID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[LiveChat_ChatRequests]( [ChatID] [uniqueidentifier] NOT NULL, [VisitorIP] [varchar](50) NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatRequests_VisitorIP] DEFAULT (''), [VisitorName] [varchar](100) NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_VisitorName] DEFAULT (''), [VisitorEmail] [varchar](225) NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_VisitorEmail] DEFAULT (''), [VisitorUserAgent] [varchar](125) NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_VisitorUserAgent] DEFAULT (''), [OperatorID] [int] NOT NULL CONSTRAINT [DF_LiveChat_ChatRequests_OperatorID] DEFAULT ((-1)), [Department] varchar(100) NULL, [RequestDate] [smalldatetime] NOT NULL CONSTRAINT [DF_ASPLiveSupport_ChatRequests_RequestDate] DEFAULT (getdate()), [AcceptDate] [smalldatetime] NULL, [ClosedDate] [smalldatetime] NULL, CONSTRAINT [PK_ASPLiveSupport_ChatRequests] PRIMARY KEY CLUSTERED ( [ChatID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[LiveChat_LogAccess]( [LogAccessID] [int] IDENTITY(1,1) NOT NULL, [PageRequested] [varchar](500) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_PageRequested] DEFAULT (''), [DomainRequested] [varchar](250) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_DomainRequested] DEFAULT (''), [RequestedTime] [smalldatetime] NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_RequestedTime] DEFAULT (getdate()), [Referrer] [varchar](500) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_Referrer] DEFAULT (''), [VisitorUserAgent] [varchar](100) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_VisitorUserAgent] DEFAULT (''), [VisitorIP] [varchar](50) NOT NULL CONSTRAINT [DF_ASPLiveSupport_LogAccess_VisitorIP] DEFAULT (''), CONSTRAINT [PK_ASPLiveSupport_LogAccess] PRIMARY KEY CLUSTERED ( [LogAccessID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[LiveChat_Operators]( [OperatorID] [int] IDENTITY(1,1) NOT NULL, [OperatorName] [varchar](100) NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorName] DEFAULT (''), [OperatorPassword] [varchar](50) NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorPassword] DEFAULT ('nopw'), [OperatorEmail] [varchar](250) NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorEmail] DEFAULT (''), [IsOnline] [bit] NOT NULL CONSTRAINT [DF_ASPLiveSupport_Operators_OperatorStatus] DEFAULT ((0)), Department varchar(500) NOT NULL CONSTRAINT [DF_LiveChat_Operators_Department] DEFAULT ('support'), CONSTRAINT [PK_ASPLiveSupport_Operators] PRIMARY KEY CLUSTERED ( [OperatorID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] "); LiveChat_Operator admin = new LiveChat_Operator(); admin.Department = ""; admin.IsOnline = false; admin.OperatorEmail = "*****@*****.**"; admin.OperatorName = "admin"; admin.OperatorPassword = password; db.LiveChat_Operators.InsertOnSubmit(admin); db.SubmitChanges(); return true; } }
public override bool Save(Operator op) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var entity = db.LiveChat_Operators.SingleOrDefault(x => x.OperatorID == op.OperatorId); if (entity == null) { entity = new LiveChat_Operator(); db.LiveChat_Operators.InsertOnSubmit(entity); } entity.Department = op.Department; entity.OperatorEmail = op.Email; entity.OperatorName = op.OperatorName; entity.OperatorPassword = op.Password.Length == 0 ? entity.OperatorPassword : op.Password; db.SubmitChanges(); return true; } }
public override void RemoveChatRequest(ChatRequest req) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { db.LiveChat_ChatRequests.DeleteAllOnSubmit(db.LiveChat_ChatRequests.Where(x => x.ChatID == req.ChatId)); db.SubmitChanges(); } }
public override bool Delete(Operator op) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { db.LiveChat_Operators.DeleteAllOnSubmit(db.LiveChat_Operators.Where(x => x.OperatorID == op.OperatorId)); db.SubmitChanges(); return true; } }
public override bool AcceptRequest(Guid id, int operatorId) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var req = db.LiveChat_ChatRequests.SingleOrDefault(x => x.ChatID == id); if (req != null) { req.AcceptDate = DateTime.Now; db.SubmitChanges(); return true; } return false; } }
public override ChatRequest CheckForInvites(string visitorIp) { using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString)) { var invites = db.LiveChat_ChatRequests.OrderByDescending(x => x.RequestDate).Where(x => x.VisitorIP == visitorIp && x.Department == "op-invite" && x.AcceptDate == null && x.ClosedDate == null).ToList(); if(invites != null && invites.Count() > 0) { // do they have more than 1 invite var invite = invites.First(); if (invites.Count() > 1) { invites.Remove(invite); foreach (var inv in invites) { inv.ClosedDate = DateTime.Now; inv.Department = "Visitor had more than 1 invite pending..."; } db.SubmitChanges(); } ChatRequest req = new ChatRequest(); req.Accepted = null; req.ChatId = invite.ChatID; req.Closed = null; req.Department = invite.Department; req.OperatorId = invite.OperatorID; req.Requested = invite.RequestDate; req.VisitorEmail = invite.VisitorEmail; req.VisitorIp = invite.VisitorIP; req.VisitorName = invite.VisitorName; req.VisitorUserAgent = invite.VisitorUserAgent; req.WasAccepted = false; return req; } return null; } }