// To generate sequences for Event Id public int getseqDBCalEventId() { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); int intnextseqDBEventId = mDBContext.Database.SqlQuery <int>("select next value for seqDBEventId").FirstOrDefault(); return(intnextseqDBEventId); }
//method to fetch incidentDetails from database public DBIncident gettingIncidentDetails(int pstrComponentId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBIncident incidentObj = new DBIncident(); try{ incidentObj = contextObj.Database.SqlQuery <DBIncident>("select * from DBIncidents where DBCSId=" + pstrComponentId + ";").FirstOrDefault(); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); } return(incidentObj); }
//function to load existing events from db public List <Events> gettingExistingEvents(int pstrCompanyId) { List <Events> eventList = new List <Events>(); WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); List <DBCalendar> calenderList = new List <DBCalendar>(); calenderList = (from calenderEvent in contextObj.DBCalendars where calenderEvent.DBCompanyId == pstrCompanyId select calenderEvent).ToList(); foreach (DBCalendar calenderObj in calenderList) { Events eventObj = new Events(); eventObj.id = calenderObj.DBEventId; eventObj.title = calenderObj.DBEventTitle; eventObj.start = calenderObj.DBEventStartTime.ToString("s"); eventObj.end = calenderObj.DBEventEndTime.ToString("s"); eventObj.allDay = false; if (calenderObj.DBEventMaintenance == "Maintenance") { eventObj.backgroundColor = "#CCCCFF"; } else { eventObj.backgroundColor = "#9CEDFE"; } eventList.Add(eventObj); } return(eventList); }
//Display Component Page Elements public IEnumerable <DummyClassForComponentPageDisplay> LoadExistingComponentsFromDataBase(int pCompanyId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); IEnumerable <DummyClassForComponentPageDisplay> result; result = contextObj.Database.SqlQuery <DummyClassForComponentPageDisplay>("select cws.DBCSId as mstrComponentId, cws.DBComponentName as mstrComponentName, cws.DBType as mstrComponentType, cws.DBStatus as mstrComponentStatus, comp.DBCompanyName as mstrCompanyName, i.DBIncidentName as mstrIncidentName, cws.DBCenterName as mstrCenterName from DBComponent_With_Status cws inner join DBCompany comp on cws.DBCompanyId = comp.DBCompanyId left join DBIncidents i on i.DBCSId = cws.DBCSId where comp.DBCompanyId= " + pCompanyId + "").ToList(); return(result); }
//method to get all compoennts related to a company public List <DBComponent_With_Status> gettingComponents(int pstrCompanyId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); List <DBComponent_With_Status> listOfComponents = new List <DBComponent_With_Status>(); listOfComponents = contextObj.Database.SqlQuery <DBComponent_With_Status>("select * from DBComponent_With_Status where DBCompanyId = " + pstrCompanyId + ";").ToList(); return(listOfComponents); }
//method to populate data center list on component page public DBCompany populatingDataCenterListOnComponentPage(int pstrCompanyId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBCompany companyObj = new DBCompany(); companyObj = contextObj.Database.SqlQuery <DBCompany>("select * from DBCompany where DBCompanyId=" + pstrCompanyId + ";").FirstOrDefault(); return(companyObj); }
//method to return data center list public List <DBDataCenter> fillingDataCenterListOnPage(string pstrDataCenterType) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); List <DBDataCenter> dataCenterList = new List <DBDataCenter>(); dataCenterList = contextObj.Database.SqlQuery <DBDataCenter>("select * from DBDataCenter where DBTypeName='" + pstrDataCenterType + "';").ToList(); return(dataCenterList); }
//USER FUNCTIONS //get user CompanyId from CompanyName in url public int mGetUserCompanyId(string pstringCompanyName) { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); int mCompanyId = mDBContext.Database.SqlQuery <int>("select DBCompanyId from DBCompany where DBCompanyName='" + pstringCompanyName + "'").FirstOrDefault(); return(mCompanyId); }
//fetching master component list from database public IEnumerable <DBMaster_DBComponent_With_Status> MasterComponentDataFromDB() { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); IEnumerable <DBMaster_DBComponent_With_Status> masterComponentList; masterComponentList = contextObj.Database.SqlQuery <DBMaster_DBComponent_With_Status>("select * from dbo.DBMaster_DBComponent_With_Status").AsEnumerable(); return(masterComponentList); }
//method to add subscriptions in the database public string mAddSubscription(string pstrName, string pstrEmail, int pstrId) { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); DBSubscription SubscriptionObj = new DBSubscription(); SubscriptionObj.DBSubscriptionsId = getseqDBSubscriptionsId(); SubscriptionObj.DBName = pstrName; SubscriptionObj.DBEmail = pstrEmail; SubscriptionObj.DBCompanyId = pstrId; int limitSubscriptionsPerCompany = mDBContext.Database.SqlQuery <Int32>("select count(*) from DBSubscriptions where DBCompanyId='" + pstrId + "';").FirstOrDefault(); try { if (limitSubscriptionsPerCompany < 5) { mDBContext.DBSubscriptions.Add(SubscriptionObj); mDBContext.SaveChanges(); return("Sucess, Subscriptions left for company:'" + (4 - limitSubscriptionsPerCompany) + "'"); } else { return("Unsucessful: Subscriptions limit: 5 for company reached"); } } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
public DBLogHistory gettingDetailsOfIncident(int pstrLogId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBLogHistory historyObj = new DBLogHistory(); historyObj = (from history in contextObj.DBLogHistories where history.DBLogId == pstrLogId select history).First(); return(historyObj); }
//method to change data center of components list selected public void ChangingDataCenter(List <int> mListOfCheckBoxes, int pstrCompanyId, string pstrDataCenterSelected) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBCompany companyObj = new DBCompany(); companyObj = (from company in contextObj.DBCompanies where company.DBCompanyId == pstrCompanyId select company).FirstOrDefault(); foreach (int componentId in mListOfCheckBoxes) { DBComponent_With_Status componentObj = new DBComponent_With_Status(); componentObj = (from component in contextObj.DBComponent_With_Status where component.DBCSId == componentId select component).FirstOrDefault(); componentObj.DBCenterName = pstrDataCenterSelected; contextObj.SaveChanges(); List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in contextObj.DBSubscriptions where subObj.DBCompanyId == pstrCompanyId select subObj).ToList(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in contextObj.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringToBeReplaced; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of eventsUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForEvents\">"); stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); endIndex = stringHtml.IndexOf("<!--end of componentStatusChangeDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForComponentStatusUpdate\">"); stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("ComponentNameForDataCenterUpdateVariable", componentObj.DBComponentName); stringHtml = stringHtml.Replace("DataCenterVariable", componentObj.DBCenterName); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "Data Center Updated", stringHtml); } } }
//method to add New Data Center public void AddingNewDataCenterToDB(string pstrDataCenterName, string pstrDataCenterType) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBDataCenter dataCenterObj = new DBDataCenter(); dataCenterObj.DBDataCenterId = getseqDBDataCenterId(); dataCenterObj.DBDataCenterName = pstrDataCenterName; dataCenterObj.DBTypeName = pstrDataCenterType; contextObj.DBDataCenters.Add(dataCenterObj); contextObj.SaveChanges(); }
//fetching companyName from companyId method public string GetCompanyNameById(int pstrCompanyId) { WinMonitorEntityModelContext contextObj; DBCompany result; contextObj = new WinMonitorEntityModelContext(); result = (from company in contextObj.DBCompanies where company.DBCompanyId == pstrCompanyId select company).SingleOrDefault(); return(result.DBCompanyName); }
//function to update events in Database public void UpdatingCalenderInDB(int pstrEventId, DateTime pstrNewEventStart, DateTime pstrNewEventEnd) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBCalendar calenderObj = new DBCalendar(); calenderObj = (from calenderEvent in contextObj.DBCalendars where calenderEvent.DBEventId == pstrEventId select calenderEvent).FirstOrDefault(); if (calenderObj.DBEventStatus == "Active") { calenderObj.DBEventStartTime = pstrNewEventStart; calenderObj.DBEventEndTime = pstrNewEventEnd; contextObj.SaveChanges(); DBCompany companyObj = new DBCompany(); companyObj = (from company in contextObj.DBCompanies where company.DBCompanyId == calenderObj.DBCompanyId select company).FirstOrDefault(); List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in contextObj.DBSubscriptions where subObj.DBCompanyId == calenderObj.DBCompanyId select subObj).ToList(); DBCalendar calEvent = new DBCalendar(); calEvent = (from calObj in contextObj.DBCalendars where calObj.DBEventId == pstrEventId select calObj).FirstOrDefault(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in contextObj.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of componentUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">"); string stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("EventNameVariable", calEvent.DBEventTitle); stringHtml = stringHtml.Replace("EventDetailsVariable", calEvent.DBEventDetails); stringHtml = stringHtml.Replace("EventStartTimeVariable", calEvent.DBEventStartTime.ToString()); stringHtml = stringHtml.Replace("EventEndTimeVariable", calEvent.DBEventEndTime.ToString()); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "Event Schedule Updated", stringHtml); } } }
public string mSaveAddCompanyDetails(string pstringCompanyName, string pstringURL, string pstringPrimarySelect, string pstringSecondarySelect) { try { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); DBCompany mDBCompanyObj = new DBCompany(); mDBCompanyObj.DBCompanyId = getseqDBCompanyId(); mDBCompanyObj.DBCompanyName = pstringCompanyName; mDBCompanyObj.DBURL = pstringURL; mDBCompanyObj.DBPrimaryCenter = pstringPrimarySelect; mDBCompanyObj.DBSecondaryCenter = pstringSecondarySelect; //adds new to the company mDBContext.DBCompanies.Add(mDBCompanyObj); //save the company details to the database mDBContext.SaveChanges(); return("Company Successfully added !!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException, Duplicate Company"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
//function to inactivate events public void InactivatingEvents() { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); List <DBCalendar> calenderEventList = contextObj.DBCalendars.ToList(); foreach (DBCalendar calEvent in calenderEventList) { TimeSpan mstrRecordState = calEvent.DBEventEndTime.Subtract(DateTime.UtcNow); if (mstrRecordState.TotalMinutes < 0) { calEvent.DBEventStatus = "Inactive"; } contextObj.SaveChanges(); } }
//method for changing the password for the Administrator public string mChangeSettings(string sendUsername, string sendOldPassword, string sendNewPassword) { try { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); int checkIfExistingPasswordTrue = mDBContext.Database.SqlQuery <int>("select count(*) from DBLogin where DBUsername='******' and DBPassword='******';").FirstOrDefault(); if (checkIfExistingPasswordTrue == 1) { mDBContext.Database.ExecuteSqlCommand("update DBLogin set DBPassword = '******' where DBUsername = '******'; "); return("Password Sucessfully Changed"); } else { return("Old Password Entered is incorrect"); } } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
//Performing Screen Login public string mCredentialCheck(string sendUsername, string sendPassword) { try { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); int checkObj = mDBContext.Database.SqlQuery <int>("select count(*) from DBLogin where DBUsername='******' and DBPassword='******' and DBAccountType ='Edit';").FirstOrDefault(); if (checkObj == 1) { return("true"); } else { return("false"); } } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
//Delete Event in Event Click public string mDeleteEvent(int pstrgetId) { try { WinMonitorEntityModelContext mDBContextObj = new WinMonitorEntityModelContext(); DBCalendar CalObj = new DBCalendar(); CalObj = (from calObj in mDBContextObj.DBCalendars where calObj.DBEventId == pstrgetId select calObj).FirstOrDefault(); mDBContextObj.DBCalendars.Remove(CalObj); mDBContextObj.SaveChanges(); return("Event Sucessfully Deleted!!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
//method to check if incident exists corresponding to particular component public string checkingIfIncidentExists(int pstrComponentId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); string ExistsOrNot; int numberOfIncidents = (from incidentObj in contextObj.DBIncidents where incidentObj.DBCSId == pstrComponentId select incidentObj).Count(); if (numberOfIncidents == 0) { ExistsOrNot = "false"; } else { ExistsOrNot = "true"; } return(ExistsOrNot); }
//function to count subscriptions public string getSubscriptionCount() { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); try { int countSubscriptions = mDBContext.Database.SqlQuery <Int32>("select count(*) from DBSubscriptions;").FirstOrDefault(); return(countSubscriptions.ToString()); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
//function to get expected end date public DummyClassToGetExpectedEndTime gettingExpectedEndTime(int componentId) { DummyClassToGetExpectedEndTime dummyObj = new DummyClassToGetExpectedEndTime(); WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBIncident incidentObj = new DBIncident(); DBLogHistory historyObj = new DBLogHistory(); incidentObj = contextObj.Database.SqlQuery <DBIncident>("select * from DBIncidents where DBCSId='" + componentId + "';").First(); historyObj = contextObj.Database.SqlQuery <DBLogHistory>("select * from DBLogHistory where DBIncidentId='" + incidentObj.DBIncidentId + "';").Last(); if (incidentObj.DBExpectedDuration != null) { dummyObj.expectedEndpresentOrNot = true; dummyObj.expectedEndDate = contextObj.Database.SqlQuery <DateTime>("select DATEADD(hour, " + incidentObj.DBExpectedDuration + ", '" + historyObj.DBDateTimeStart + "')").First(); } else { dummyObj.expectedEndpresentOrNot = false; dummyObj.expectedEndDate = null; } return(dummyObj); }
//method to delete existing incident of particular element public void deletingExistingIncidentOfComponent(int pstrComponentId, int pstrCompanyId) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBIncident incidentObj = new DBIncident(); DBComponent_With_Status componentObj = new DBComponent_With_Status(); DBLogHistory historyObj = new DBLogHistory(); componentObj = (from component in contextObj.DBComponent_With_Status where component.DBCSId == pstrComponentId select component).FirstOrDefault(); incidentObj = (from incident in contextObj.DBIncidents where incident.DBCSId == pstrComponentId select incident).FirstOrDefault(); historyObj = (from log in contextObj.DBLogHistories where ((log.DBCompanyId == pstrCompanyId) && (log.DBCSId == pstrComponentId) && (log.DBDateTimeEnd == null)) select log).Last(); historyObj.DBDateTimeStart = DateTime.UtcNow;; contextObj.SaveChanges(); contextObj.DBIncidents.Remove(incidentObj); contextObj.SaveChanges(); }
public List <DummyPerformance> gettingEventTimeStored(int pstrComponentId, int eventStartOffset, int eventEndOffset, string pstrRecentOrNot) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBLogHistory lastHistoryObj = new DBLogHistory(); DateTime nowTime = DateTime.UtcNow; DateTime eventStart, eventEnd; if (pstrRecentOrNot == "true") { if (((nowTime.Day + eventStartOffset) <= 0) || ((nowTime.Day + eventEndOffset) <= 0)) { eventStart = nowTime.AddDays(eventStartOffset); eventEnd = nowTime.AddDays(eventEndOffset); } else { eventStart = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventStartOffset, nowTime.Hour, nowTime.Minute, nowTime.Second); eventEnd = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventEndOffset, nowTime.Hour, nowTime.Minute, nowTime.Second); } } else { if (((nowTime.Day + eventStartOffset) <= 0) || ((nowTime.Day + eventEndOffset) <= 0)) { eventStart = nowTime.AddDays(eventStartOffset); eventEnd = nowTime.AddDays(eventEndOffset); eventStart = new DateTime(eventStart.Year, eventStart.Month, eventStart.Day, 0, 0, 0); eventEnd = new DateTime(eventEnd.Year, eventEnd.Month, eventEnd.Day, 0, 0, 0); } else { eventStart = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventStartOffset, 0, 0, 0); eventEnd = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day + eventEndOffset, 0, 0, 0); } } List <DummyPerformance> listPerformance = new List <DummyPerformance>(); DummyPerformance performanceObj; int a = 0; List <DBLogHistory> listHistory = new List <DBLogHistory>(); listHistory = (from historyObj in contextObj.DBLogHistories where ((historyObj.DBCSId == pstrComponentId) && (eventStart <= historyObj.DBDateTimeStart) && (historyObj.DBDateTimeStart <= eventEnd) && (historyObj.DBStatus != "Operational")) select historyObj).ToList(); if (listHistory.Count > 0) { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(eventStart, listHistory[0].DBDateTimeStart).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); int i; DateTime?lastInList = DateTime.UtcNow; for (i = 0; i < listHistory.Count; i++) { if (listHistory[i].DBDateTimeEnd != null) { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(listHistory[i].DBDateTimeStart, listHistory[i].DBDateTimeEnd).First()).Value; performanceObj.mLogId = listHistory[i].DBLogId; performanceObj.mDiff = a; performanceObj.mStatus = listHistory[i].DBStatus; listPerformance.Add(performanceObj); if (i != listHistory.Count - 1) { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(listHistory[i].DBDateTimeEnd, listHistory[i + 1].DBDateTimeStart).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); } else { lastInList = listHistory[i].DBDateTimeEnd; performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(lastInList, eventEnd).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); } } else { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(listHistory[i].DBDateTimeStart, eventEnd).First()).Value; performanceObj.mLogId = listHistory[i].DBLogId; performanceObj.mDiff = a; performanceObj.mStatus = listHistory[i].DBStatus; listPerformance.Add(performanceObj); } } } else { performanceObj = new DummyPerformance(); a = (contextObj.GetDateDiffInSec(eventStart, eventEnd).First()).Value; performanceObj.mLogId = -1; performanceObj.mDiff = a; performanceObj.mStatus = "Operational"; listPerformance.Add(performanceObj); } return(listPerformance); }
// For Displaying List of Registered Administrators public List <DBLogin> mRetrieveLoginDetails() { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); return(mDBContext.DBLogins.ToList()); }
//ADMIN FUNCTIONS //show company details public List <DBCompany> mRetrieveCompanyDetails() { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); return(mDBContext.DBCompanies.ToList()); }
//function to send email for calender event subscription public void sendEmailForCalenderEvent(DBCalendar calObj, string pstrRecipientsEmailId, string pstrCCRecipientsEmailId, string pstrSubject, string pstrMessageBody, string pstrMessage, DateTime startTime, DateTime endTime, string actionToBeTaken) { ExchangeService objExchangeService = new ExchangeService(ExchangeVersion.Exchange2013); objExchangeService.Credentials = new WebCredentials("wse\\centraluser", "$abcd1234"); objExchangeService.UseDefaultCredentials = false; objExchangeService.Url = new Uri("https://mail.winshuttle.in/EWS/Exchange.asmx"); EmailMessage objMessage = new EmailMessage(objExchangeService); objMessage.ToRecipients.Add(pstrRecipientsEmailId); if (pstrCCRecipientsEmailId != null) { objMessage.CcRecipients.Add(pstrCCRecipientsEmailId); } objMessage.Subject = pstrSubject; objMessage.ReplyTo.Add(new EmailAddress("*****@*****.**")); objMessage.Body = new MessageBody(pstrMessageBody); objMessage.Body.BodyType = BodyType.HTML; Appointment appObj; if (actionToBeTaken == "Update") { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DateTime endDateLimit = contextObj.Database.SqlQuery <DateTime>("select DBEventEndTime from DBCalendar").Last(); CalendarFolder folder = CalendarFolder.Bind(objExchangeService, WellKnownFolderName.Calendar); CalendarView view = new CalendarView(DateTime.UtcNow, endDateLimit); FindItemsResults <Appointment> results = folder.FindAppointments(view); foreach (Appointment appointment in results) { if ((appointment.Subject == calObj.DBEventTitle) || (appointment.Start == calObj.DBEventStartTime) || (appointment.End == calObj.DBEventEndTime)) { appObj = Appointment.Bind(objExchangeService, appointment.Id, new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Body, AppointmentSchema.Start, AppointmentSchema.End)); appObj.Subject = pstrSubject; appObj.Body = pstrMessage; appObj.Start = startTime; appObj.End = endTime; appObj.RequiredAttendees.Add(pstrRecipientsEmailId); appObj.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy); } } } else if (actionToBeTaken == "CreateNew") { appObj = new Appointment(objExchangeService); appObj.Subject = calObj.DBEventTitle; appObj.Body = calObj.DBEventDetails; appObj.Start = calObj.DBEventStartTime; appObj.End = calObj.DBEventEndTime; appObj.RequiredAttendees.Add(pstrRecipientsEmailId); appObj.Save(SendInvitationsMode.SendToAllAndSaveCopy); } else { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DateTime endDateLimit = DateTime.Parse(contextObj.Database.SqlQuery <string>("select DBEventEndTime from DBCalendar").Last()); CalendarFolder folder = CalendarFolder.Bind(objExchangeService, WellKnownFolderName.Calendar); CalendarView view = new CalendarView(DateTime.UtcNow, endDateLimit); FindItemsResults <Appointment> results = folder.FindAppointments(view); foreach (Appointment appointment in results) { if ((appointment.Subject == calObj.DBEventTitle) || (appointment.Start == calObj.DBEventStartTime) || (appointment.End == calObj.DBEventEndTime)) { appObj = Appointment.Bind(objExchangeService, appointment.Id, new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Body, AppointmentSchema.Start, AppointmentSchema.End)); appObj.Delete(DeleteMode.HardDelete); } } } objMessage.Send(); }
//Show Event Details on Event Click public List <DummyCalendar> mGetEventCalendarDetails(int pstrgetId) { WinMonitorEntityModelContext mDBContextObj = new WinMonitorEntityModelContext(); return(mDBContextObj.Database.SqlQuery <DummyCalendar>("select DBEventTitle as Title, DBEventDetails as Details, DBEventStartTime as Start, DBEventEndTime as EndTime, DBEventMaintenance as Maintenance, DBEventStatus as Status from DBCalendar where DBEventId=" + pstrgetId + "").ToList()); }
//Admin Maintenance Calendar //AddEVent In Calendar public string mSaveCalendarEvent(string pstrTitle, string pstrDetails, string pstrStartTime, string pstrEndTime, string pstrEventFor, string pstrMaintenance, int pstrCompanyId) { try { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); if (pstrEventFor == "all") { List <DBCompany> companyList = new List <DBCompany>(); companyList = (from company in mDBContext.DBCompanies select company).ToList(); foreach (DBCompany companyObj in companyList) { DBCalendar CalObj = new DBCalendar(); CalObj.DBEventId = getseqDBCalEventId(); CalObj.DBEventTitle = pstrTitle; CalObj.DBEventDetails = pstrDetails; DateTime mdateStartTime = DateTime.Parse(pstrStartTime); CalObj.DBEventStartTime = mdateStartTime; DateTime mdateEndTime = DateTime.Parse(pstrEndTime); CalObj.DBEventEndTime = mdateEndTime; CalObj.DBEventDifferenceTime = mdateEndTime.Subtract(mdateStartTime).ToString(); CalObj.DBEventMaintenance = pstrMaintenance; CalObj.DBCompanyId = companyObj.DBCompanyId; TimeSpan mstrRecordState = mdateEndTime.Subtract(DateTime.UtcNow); if (mstrRecordState.TotalMinutes > 0) { CalObj.DBEventStatus = "Active"; } else { CalObj.DBEventStatus = "Inactive"; } mDBContext.DBCalendars.Add(CalObj); mDBContext.SaveChanges(); List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in mDBContext.DBSubscriptions where subObj.DBCompanyId == companyObj.DBCompanyId select subObj).ToList(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in mDBContext.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of componentUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">"); string stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("EventNameVariable", CalObj.DBEventTitle); stringHtml = stringHtml.Replace("EventDetailsVariable", CalObj.DBEventDetails); stringHtml = stringHtml.Replace("EventStartTimeVariable", CalObj.DBEventStartTime.ToString()); stringHtml = stringHtml.Replace("EventEndTimeVariable", CalObj.DBEventEndTime.ToString()); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml); } } } else { DBCalendar CalObj = new DBCalendar(); CalObj.DBEventId = getseqDBCalEventId(); CalObj.DBEventTitle = pstrTitle; CalObj.DBEventDetails = pstrDetails; DateTime mdateStartTime = DateTime.Parse(pstrStartTime); CalObj.DBEventStartTime = mdateStartTime; DateTime mdateEndTime = DateTime.Parse(pstrEndTime); CalObj.DBEventEndTime = mdateEndTime; CalObj.DBEventDifferenceTime = mdateEndTime.Subtract(mdateStartTime).ToString(); //CalObj.DBEventRepetition = pstrEventFor; CalObj.DBEventMaintenance = pstrMaintenance; CalObj.DBCompanyId = pstrCompanyId; TimeSpan mstrRecordState = mdateEndTime.Subtract(DateTime.UtcNow); if (mstrRecordState.TotalMinutes > 0) { CalObj.DBEventStatus = "Active"; } else { CalObj.DBEventStatus = "Inactive"; } mDBContext.DBCalendars.Add(CalObj); mDBContext.SaveChanges(); DBCompany companyObj = new DBCompany(); companyObj = (from company in mDBContext.DBCompanies where company.DBCompanyId == pstrCompanyId select company).FirstOrDefault(); List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in mDBContext.DBSubscriptions where subObj.DBCompanyId == pstrCompanyId select subObj).ToList(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in mDBContext.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of componentUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">"); string stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("EventNameVariable", CalObj.DBEventTitle); stringHtml = stringHtml.Replace("EventDetailsVariable", CalObj.DBEventDetails); stringHtml = stringHtml.Replace("EventStartTimeVariable", CalObj.DBEventStartTime.ToString()); stringHtml = stringHtml.Replace("EventEndTimeVariable", CalObj.DBEventEndTime.ToString()); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml); } } return("Event Saved Sucessfully!!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }