public async Task <IActionResult> Edit(int id, [Bind("AppointmentId,CustomerAddress,AppointmentNotes,AppointmentTime,AppointmentDate,IsComplete")] ServiceAppointment serviceAppointment) { if (id != serviceAppointment.AppointmentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(serviceAppointment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ServiceAppointmentExists(serviceAppointment.AppointmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(serviceAppointment)); }
protected void ScheduleService_Click(object sender, EventArgs e) { var availableResourceId = (Guid)AvailableTimes.SelectedDataKey.Values["AvailableResource"]; var availableResource = XrmContext.ResourceSet.First(r => r.ResourceId == availableResourceId); var selectedStart = (DateTime)AvailableTimes.SelectedDataKey.Values["ScheduledStartUniversalTime"]; var selectedEnd = (DateTime)AvailableTimes.SelectedDataKey.Values["ScheduledEndUniversalTime"]; var appointment = new ServiceAppointment { ServiceId = Service.ToEntityReference(), Subject = "Web Service Scheduler: " + ServiceType.SelectedItem, ScheduledStart = selectedStart, ScheduledEnd = selectedEnd, Resources = new[] { new ActivityParty { PartyId = new EntityReference(availableResource.ObjectTypeCode, availableResource.Id) } }, Customers = new[] { new ActivityParty { PartyId = Contact.ToEntityReference() } } }; XrmContext.AddObject(appointment); XrmContext.SaveChanges(); XrmContext.SetState((int)Enums.ServiceAppointmentState.Scheduled, 4, appointment); var page = ServiceContext.GetPageBySiteMarkerName(Website, "Service Details"); Response.Redirect(string.Format("{0}?serviceid={1}", ServiceContext.GetUrl(page), appointment.Id)); }
public static bool getBooleanField(ServiceAppointment i_Service, string i_FieldName) { bool fieldValue = false; if (i_Service.m_JSONAdditionalData.TryGetValue(i_FieldName, out var value)) { fieldValue = value.ToObject <bool>(); } return(fieldValue); }
public async Task <IActionResult> Create([Bind("AppointmentId,CustomerAddress,AppointmentNotes,AppointmentTime,AppointmentDate,IsComplete")] ServiceAppointment serviceAppointment) { if (ModelState.IsValid) { _context.Add(serviceAppointment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(serviceAppointment)); }
public List <ServiceAppointment> getAppointmentServiceList(int cid) { List <ServiceAppointment> salist = new List <ServiceAppointment>(); SqlConnection scon = new SqlConnection(conn); string qry = "select distinct app_Id,App_date,cust_Id,Timeslot,UserName,UserEmail,canceled from ServiceAppointment inner join Service_booked on ServiceAppointment.App_Id=Service_booked.Appointment_Id" + " inner join Timeslot on timeslot.TimeSlotId = ServiceAppointment.TimeslotId" + " inner join Users on users.userId = ServiceAppointment.cust_Id " + " where ServiceAppointment.cust_ID = " + cid + ""; using (SqlCommand scmd = new SqlCommand()) { scmd.Connection = scon; scmd.CommandType = CommandType.Text; scmd.CommandText = qry; scon.Open(); SqlDataReader sdr = scmd.ExecuteReader(); while (sdr.Read()) { ServiceAppointment sa = new ServiceAppointment(); sa.App_Id = Convert.ToInt32(sdr["app_Id"]); sa.App_date = sdr["App_date"].ToString(); sa.timeslot = sdr["TimeSlot"].ToString(); sa.custId = cid; string str = sdr["canceled"].ToString(); str = str.Trim(); sa.appintmentstatus = str; sa.cust_Name = sdr["UserName"].ToString(); sa.cust_Email = sdr["UserEmail"].ToString(); List <ServiceCart> subservicelist = bs.getServiceCartList1(sa.App_Id); sa.subservicecart = subservicelist; salist.Add(sa); } if (sdr != null) { sdr.Dispose(); sdr.Close(); } scon.Close(); } return(salist); }
private List <Work_Rule__c> initiateRulesWithRelvanceGroupList( Dictionary <string, List <Work_Rule__c> > i_RulesByDevName, ServiceAppointment i_Service) { List <Work_Rule__c> rulesFilteredByRelevanceGroup = new List <Work_Rule__c>(); foreach (List <Work_Rule__c> rules in i_RulesByDevName.Values) { foreach (Work_Rule__c rule in rules.Where(rule => rule.Object_Group_Field__c == null || ServiceAppointmentUtils.getBooleanField(i_Service, rule.Object_Group_Field__c))) { rulesFilteredByRelevanceGroup.Add(rule); } } return(rulesFilteredByRelevanceGroup); }
public override string getQuery(AppointmentBookingRequest i_Request = null, AdditionalObjectsUtils.eAdditionalObjectQuery i_AdditionalObjQuery = default) { ServiceAppointment service = m_ABData.ServiceToSchedule; DateTime minDate = service.EarliestStartTime.Value.AddDays(-7); DateTime maxDate = service.DueDate.Value.AddDays(7); string resourcesIds = formatIdList(m_ABData.STMResourcesIDs.ToList()); string query = "select Id, name, IsActive, IsCapacityBased, Efficiency__c, Travel_Speed__c, " + "RelatedRecordId, ResourceType, ServiceCrewId, (select ServiceResourceId," + "StartDate,EndDate,ServiceCrewId from ServiceCrewMembers " + $"where ((StartDate <= {formatDate(maxDate)}) AND (EndDate = null OR EndDate >= {formatDate(minDate)}))) {addRequiredFields(minDate, maxDate)}" + $" from ServiceResource Where IsActive = true And Id in ({resourcesIds})"; return(formatQueryString(query)); }
internal override void updateReferencesAfterDeserialize(SFRefereceResolver i_ReferenceResolver, bool i_ShouldAddToRelatedLists = true) { Type myType = GetType(); string propertyName = "Root_Service_Appointment__r"; propertyName = DeserializationUtils.GetPropertyName(myType.GetProperty(propertyName), propertyName); JToken objectJson = removeObjectJTokenFromAdditionalDictionary(propertyName); Root_Service_Appointment__r = DeserializationUtils.GetSingleObjectReference <ServiceAppointment>(Root_Service_Appointment__c, objectJson, i_ReferenceResolver); propertyName = "Service_Appointment_1__r"; propertyName = DeserializationUtils.GetPropertyName(myType.GetProperty(propertyName), propertyName); objectJson = removeObjectJTokenFromAdditionalDictionary(propertyName); Service_Appointment_1__r = DeserializationUtils.GetSingleObjectReference <ServiceAppointment>(Service_Appointment_1__c, objectJson, i_ReferenceResolver); if (Service_Appointment_1__r != null) { if (Service_Appointment_1__r.Time_Dependencies__r == null) { Service_Appointment_1__r.Time_Dependencies__r = new List <Time_Dependency__c>(); } Service_Appointment_1__r.Time_Dependencies__r.Add(this); } propertyName = "Service_Appointment_2__r"; propertyName = DeserializationUtils.GetPropertyName(myType.GetProperty(propertyName), propertyName); objectJson = removeObjectJTokenFromAdditionalDictionary(propertyName); Service_Appointment_2__r = DeserializationUtils.GetSingleObjectReference <ServiceAppointment>(Service_Appointment_2__c, objectJson, i_ReferenceResolver); // if (Service_Appointment_2__r != null) // { // if (Service_Appointment_2__r.Time_Dependencies__r == null) // { // Service_Appointment_2__r.Time_Dependencies__r = new List<Time_Dependency__c>(); // } // // Service_Appointment_2__r.Time_Dependencies__r.Add(this); // } base.updateReferencesAfterDeserialize(i_ReferenceResolver); }
private string addRequiredFields(DateTime i_MinDate, DateTime i_MaxDate) { ServiceAppointment service = m_ABData.ServiceToSchedule; HashSet <string> requiredSkillsIds = new HashSet <string>(); ServiceParent serviceParent = m_ABData.ServiceParent[service.ParentRecordId]; foreach (SkillRequirement skillReq in serviceParent.SkillRequirements) { requiredSkillsIds.Add(skillReq.SkillId); } HashSet <string> relevantSecondariesToRetrieve = new HashSet <string>(); if (service.ServiceTerritory.Id != null) { relevantSecondariesToRetrieve.Add(service.ServiceTerritory.Id); } return(getFields(requiredSkillsIds, relevantSecondariesToRetrieve, i_MinDate, i_MaxDate)); }
public override string getQuery(AppointmentBookingRequest i_Request = null, eAdditionalObjectQuery i_AdditionalObjQuery = default) { ServiceAppointment service = m_ABData.ServiceToSchedule; m_Start = service.EarliestStartTime.Value; m_Finish = service.DueDate.Value; calculateHorizonByMaxDaysSearchSlot(service, DateTime.Now, i_Request.SearchSlotsMaxDays, out m_Start, out m_Finish); string query; switch (i_AdditionalObjQuery) { case eAdditionalObjectQuery.ServicesInResourcesTimeDomain: query = getServicesInResourcesTimeDomainQuery(); break; case eAdditionalObjectQuery.ResourcesAdditionalObjects: query = getResourcesQueryForAdditionalObjects(i_Request); break; case eAdditionalObjectQuery.ResourceTerritories: query = getResourceTerritoriesQuery(i_Request); break; case eAdditionalObjectQuery.Capacities: query = getCapacitiesQuery(i_Request); break; case eAdditionalObjectQuery.Calendars: query = getCalendarsQuery(i_Request); break; default: query = String.Empty; break; } return(formatQueryString(query)); }
protected void calculateHorizonByMaxDaysSearchSlot(ServiceAppointment i_Service, DateTime i_DateTimeNow, double i_SearchSlotsMaxDays, out DateTime start, out DateTime finish) { DateTime?resourcesHorizonStart = i_Service.EarliestStartTime; DateTime?resourcesHorizonFinish = i_Service.DueDate; if (resourcesHorizonStart < i_DateTimeNow) { resourcesHorizonStart = i_DateTimeNow; } TimeSpan currDaysInterval = (resourcesHorizonFinish.Value.Subtract(resourcesHorizonStart.Value)); double maxDays = i_SearchSlotsMaxDays; if (currDaysInterval.Days > maxDays) { resourcesHorizonFinish = resourcesHorizonStart.Value.AddDays(maxDays); } start = resourcesHorizonStart.Value.AddDays(-1); finish = resourcesHorizonFinish.Value.AddDays(1); }
public AppointmentController() { appointmentService = new ServiceAppointment(); }
public override string getQuery(AppointmentBookingRequest i_Request = null, AdditionalObjectsUtils.eAdditionalObjectQuery i_AdditionalObjQuery = default) { m_Request = i_Request; if (doAdditionalMembersQuery) { return(getAdditionalMembersQuery()); } string queryStr = "SELECT ServiceResource.Id, ServiceResource.ResourceType, ServiceResource.ServiceCrewId, ServiceResource.Travel_Speed__c" + ",ServiceResource.IsCapacityBased,ServiceResource.IsActive,ServiceResource.Name," + "ServiceTerritory.Address,ServiceTerritory.Internal_SLR_Geolocation__c,ServiceTerritory.Longitude" + ",ServiceTerritory.Latitude,Id,ServiceResourceId,ServiceTerritory.OperatingHours.TimeZone" + ",ServiceTerritory.Internal_SLR_Geolocation__Latitude__s,ServiceTerritory.Internal_SLR_Geolocation__Longitude__s" + ",OperatingHoursId,OperatingHours.TimeZone,EffectiveEndDate,EffectiveStartDate,Latitude,Longitude," + "Internal_SLR_HomeAddress_Geolocation__Latitude__s,Internal_SLR_HomeAddress_Geolocation__Longitude__s" + ",Internal_SLR_HomeAddress_Geolocation__c,TerritoryType,ServiceTerritoryId,Address"; m_AdditionalMembersQuery = "Select ServiceResource.Id, ServiceResource.IsActive,ServiceResource.Name,ServiceTerritory.Internal_SLR_Geolocation__c," + "ServiceTerritory.Longitude,ServiceTerritory.Latitude,Id,ServiceResourceId," + "ServiceTerritory.OperatingHours.TimeZone,ServiceTerritory.Internal_SLR_Geolocation__Latitude__s," + "ServiceTerritory.Internal_SLR_Geolocation__Longitude__s,OperatingHoursId,OperatingHours.TimeZone," + "EffectiveEndDate,EffectiveStartDate,Latitude,Longitude,Internal_SLR_HomeAddress_Geolocation__Latitude__s," + "Internal_SLR_HomeAddress_Geolocation__Longitude__s,Internal_SLR_HomeAddress_Geolocation__c," + "TerritoryType,ServiceTerritoryId "; HashSet <String> relevanceFields = new HashSet <String>(); ServiceAppointment service = m_ABData.ServiceToSchedule; string notPartOfRelevenceGroupStr = "("; bool atLeastOneLocationRuleIsActive = false; bool travelRuleIsActive = false; double?travelDistance = null; double?latestUpdatedTravelDistance; bool addedOneOfTheRulesToTheQuery = false; bool serviceHasGeo = service.Latitude != null && service.Longitude != null; List <Work_Rule__c> enhancedRules = new List <Work_Rule__c>(); List <Work_Rule__c> rulesListFileteredBySARelevance = new List <Work_Rule__c>(); string territoryId = m_ABData.ServiceToSchedule.ServiceTerritory.Id; rulesListFileteredBySARelevance = initiateRulesWithRelvanceGroupList(m_ABData.RulesByDevName, service); foreach (Work_Rule__c rule in rulesListFileteredBySARelevance) { string resGroupFieldValue = rule.Resource_Group_Field__c; if (rule.DeveloperName.Equals("Match_Location_Service") || rule.DeveloperName.Equals("Field_Working_Locations")) { atLeastOneLocationRuleIsActive = true; } if (serviceHasGeo && rule.DeveloperName.Equals("Max_Travel_From_Home_To_Service") && rule.Maximum_Travel_From_Home_Type__c.Equals("Distance") && rule.Maximum_Travel_From_Home__c != null) { travelRuleIsActive = true; latestUpdatedTravelDistance = (i_Request.TravelUnit == eTravelUnit.Miles.ToString()) ? (rule.Maximum_Travel_From_Home__c * MILE_TO_KM_RATIO) : rule.Maximum_Travel_From_Home__c; if (travelDistance == null || travelDistance < latestUpdatedTravelDistance) { travelDistance = latestUpdatedTravelDistance; travelDistance++; } } if (!string.IsNullOrEmpty(resGroupFieldValue)) { relevanceFields.Add(resGroupFieldValue.ToLower()); if (rule.DeveloperName.Equals("Match_Location_Service") || rule.DeveloperName.Equals("Field_Working_Locations") || (rule.DeveloperName.Equals("Max_Travel_From_Home_To_Service") && rule.Maximum_Travel_From_Home_Type__c.Equals("Distance"))) { if (notPartOfRelevenceGroupStr != "(") { notPartOfRelevenceGroupStr += " AND "; } notPartOfRelevenceGroupStr += resGroupFieldValue.ToLower() + " = false"; } } if (rule.DeveloperName.Equals("Enhanced_Match_Service")) { enhancedRules.Add(rule); } } if (notPartOfRelevenceGroupStr != "(") { notPartOfRelevenceGroupStr += $" AND TerritoryType != \'S\' AND ServiceTerritoryId = {territoryId} )"; } else { notPartOfRelevenceGroupStr += ")"; } foreach (KeyValuePair <string, List <Service_Goal__c> > objByDevName in m_ABData.ObjectivesByDevName) { foreach (Service_Goal__c obj in objByDevName.Value) { String objGroupFieldValue = obj.Resource_Group_Field__c; if (!string.IsNullOrEmpty(objGroupFieldValue)) { relevanceFields.Add(objGroupFieldValue.ToLower()); } } } if (relevanceFields.Any()) { foreach (String field in relevanceFields) { queryStr += "," + field; m_AdditionalMembersQuery += "," + field; } } calculateHorizonByMaxDaysSearchSlot(service, m_DateTimeNow, i_Request.SearchSlotsMaxDays, out m_Start, out m_Finish); notPartOfRelevenceGroupStr = notPartOfRelevenceGroupStr != "()" ? " OR " + notPartOfRelevenceGroupStr : string.Empty; queryStr += " FROM ServiceTerritoryMember WHERE "; if (atLeastOneLocationRuleIsActive && territoryId != null) { addedOneOfTheRulesToTheQuery = true; if (travelRuleIsActive) { queryStr += $"(( ServiceTerritoryId = '{territoryId}' And "; } else { queryStr += $"( ServiceTerritoryId = '{territoryId}' "; } } if (travelRuleIsActive) { if (!addedOneOfTheRulesToTheQuery) { queryStr += "("; } queryStr += $" (TerritoryType = \'S\' Or ( Latitude <> null And Latitude <> 0 And Longitude <> null And Longitude <> 0 And (DISTANCE(Address, GEOLOCATION(' + {service.Latitude} + ',' + {service.Longitude} + '),\'km\') < ' + travelDistance + ') ) OR "; queryStr += $" ( ServiceTerritory.Latitude <> null And ServiceTerritory.Latitude <> 0 And ServiceTerritory.Longitude <> null And ServiceTerritory.Longitude <> 0 And (DISTANCE(ServiceTerritory.Address, GEOLOCATION(' + {service.Latitude} + ',' + {service.Longitude} + '),\'km\') < ' + travelDistance + ') ))"; if (addedOneOfTheRulesToTheQuery) { queryStr += ')'; } addedOneOfTheRulesToTheQuery = true; } if (addedOneOfTheRulesToTheQuery) { queryStr += notPartOfRelevenceGroupStr + ") AND "; } queryStr += $"( NOT ((EffectiveStartDate <> NULL AND EffectiveStartDate > {formatDate(m_Finish)}) OR " + $"(EffectiveEndDate <> NULL AND EffectiveEndDate < {formatDate(m_Start)})) ) And ServiceResource.IsActive = true"; //TODO: implement for Enhanced Match Rule /* * if(enhancedRules != null && enhancedRules.Count > 0) * { * List<string> queriesToFilterResources = getQueriesToFilterResourcesAcoordingToEnhancedRules(service, enhancedRules); * foreach(string queryToFilterResource in queriesToFilterResources){ * queryStr += queryToFilterResource; * } * } */ doAdditionalMembersQuery = true; queryStr = formatQueryString(queryStr); return(queryStr); }