//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.sendEmailForCalenderEvent(calenderObj, subscriptionObj.DBEmail, null, "Event Schedule Updated", stringHtml, calEvent.DBEventDetails, pstrNewEventStart, pstrNewEventEnd, "Update"); } } }
//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.sendEmailForCalenderEvent(CalObj, subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml, CalObj.DBEventDetails, DateTime.Parse(pstrStartTime), DateTime.Parse(pstrEndTime), "CreateNew"); } } } 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.sendEmailForCalenderEvent(CalObj, subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml, CalObj.DBEventDetails, DateTime.Parse(pstrStartTime), DateTime.Parse(pstrEndTime), "CreateNew"); } } 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"); } }