Exemplo n.º 1
0
        private static void CreateOutGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, string propertyID, string renowalkID, string Contract_Code, Events gridEvent, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");

                List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                gridEventDataPayload.EventTime = DateTime.Now.ToString();
                gridEventDataPayload.EventType = "allEvents";
                gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.Subject = $"Turn Process : {gridEvent.ToString()}";
                }
                else
                {
                    gridEventDataPayload.Subject = $"Initial Renovation : {gridEvent.ToString()}";
                }
                gridEventDataPayload.data       = new DataPayLoad();
                gridEventDataPayload.data.Date1 = DateTime.Now.ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.data.Event = gridEvent;
                }
                else
                {
                    gridEventDataPayload.data.Event = gridEvent;
                }
                gridEventDataPayload.data.IsForce       = false;
                gridEventDataPayload.data.PropertyID    = propertyID;
                gridEventDataPayload.data.RenowalkID    = renowalkID;
                gridEventDataPayload.data.Contract_Code = Contract_Code;

                gridEventDataPayloadList.Add(gridEventDataPayload);

                Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = true;
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = gridEvent.ToString();
                }
                else
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = gridEvent.ToString();
                }
                _service.Create(azIntCallEntity);
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Exemplo n.º 2
0
        private static void CreateOutGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, Entity projectEntity, Entity changeOrderEntity, EntityCollection changeOrderItemsEntityCollection, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings, string propertyID)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");

                EntityCollection          projectTeamMemberEntityCollection = RetrieveProjectTeamMembers(tracer, _service, projectEntity.ToEntityReference());
                EntityCollection          projectTaskEntityCollection       = RetrieveAllProjectTaskByProjectWithContractID(tracer, _service, projectEntity.ToEntityReference());
                Dictionary <Guid, string> vendorContractCode   = new Dictionary <Guid, string>();
                Dictionary <Guid, string> vendorCodeDictionary = new Dictionary <Guid, string>();
                List <Contract>           contractList         = new List <Contract>();
                foreach (Entity changeOrderItemEntity in changeOrderItemsEntityCollection.Entities)
                {
                    if (changeOrderItemEntity.Attributes.Contains(Constants.ChangeOrderItems.Vendor))
                    {
                        string contractCode = string.Empty;
                        //Check whether It is existing Vendor or not.
                        if (vendorContractCode.ContainsKey(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id))
                        {
                            contractCode = vendorContractCode[changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id];
                        }
                        else
                        {
                            if (projectTeamMemberEntityCollection is EntityCollection)
                            {
                                Entity prjTeamMemberEntity = projectTeamMemberEntityCollection.Entities.Where(e => e.Attributes.Contains("B.accountid") && ((EntityReference)e.GetAttributeValue <AliasedValue>("B.accountid").Value).Id.Equals(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id)).FirstOrDefault();
                                if (prjTeamMemberEntity is Entity)
                                {
                                    Entity prjTaskEntity = projectTaskEntityCollection.Entities.Where(e => e.Attributes.Contains(Constants.ProjectTasks.AssignedTeamMembers) && e.GetAttributeValue <EntityReference>(Constants.ProjectTasks.AssignedTeamMembers).Id.Equals(prjTeamMemberEntity.Id)).FirstOrDefault();
                                    if (prjTaskEntity is Entity)
                                    {
                                        vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, prjTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID));
                                        contractCode = prjTaskEntity.GetAttributeValue <string>(Constants.ProjectTasks.ContractID);
                                    }
                                    else
                                    {
                                        vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, string.Empty);
                                    }
                                }
                                else
                                {
                                    vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, string.Empty);
                                }
                            }
                            else
                            {
                                vendorContractCode.Add(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, string.Empty);
                            }
                        }
                        Contract c = new Contract();
                        c.Amount          = changeOrderItemEntity.GetAttributeValue <Money>(Constants.ChangeOrderItems.Amount).Value.ToString();
                        c.Category_Code   = changeOrderItemEntity.GetAttributeValue <AliasedValue>("JC.fkh_jobcategorycode").Value.ToString();
                        c.Contract_Code   = contractCode;
                        c.ItemDescription = changeOrderItemEntity.GetAttributeValue <string>(Constants.ChangeOrderItems.Description);
                        c.Start_Date      = DateTime.Now.ToString();
                        if (vendorCodeDictionary.ContainsKey(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id))
                        {
                            c.Vendor_Code = vendorCodeDictionary[changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id];
                        }
                        else
                        {
                            Entity vendorEntity = _service.Retrieve(changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).LogicalName, changeOrderItemEntity.GetAttributeValue <EntityReference>(Constants.ChangeOrderItems.Vendor).Id, new ColumnSet(true));
                            if (vendorEntity is Entity && vendorEntity.Attributes.Contains(Constants.Vendors.AccountCode))
                            {
                                c.Vendor_Code = vendorEntity.GetAttributeValue <string>(Constants.Vendors.AccountCode);
                                vendorCodeDictionary.Add(vendorEntity.Id, vendorEntity.GetAttributeValue <string>(Constants.Vendors.AccountCode));
                            }
                        }
                        //c.Vendor_Code =
                        contractList.Add(c);
                    }
                }


                List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                gridEventDataPayload.EventTime = DateTime.Now.ToString();
                gridEventDataPayload.EventType = "allEvents";
                gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.Subject = $"Turn Process : {Events.CHANGE_ORDER.ToString()}";
                }
                else
                {
                    gridEventDataPayload.Subject = $"Initial Renovation : {Events.IR_CHANGE_ORDER.ToString()}";
                }
                gridEventDataPayload.data       = new DataPayLoad();
                gridEventDataPayload.data.Date1 = DateTime.Now.ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.data.Event = Events.CHANGE_ORDER;
                }
                else
                {
                    gridEventDataPayload.data.Event = Events.IR_CHANGE_ORDER;
                }
                gridEventDataPayload.data.IsForce     = false;
                gridEventDataPayload.data.PropertyID  = propertyID;
                gridEventDataPayload.data.EmailID     = string.Empty;
                gridEventDataPayload.data.FotoNotesID = string.Empty;
                gridEventDataPayload.data.JobID       = string.Empty;
                gridEventDataPayload.data.RenowalkID  = projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID);
                gridEventDataPayload.data.Contracts   = contractList;

                gridEventDataPayloadList.Add(gridEventDataPayload);

                Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = true;
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.CHANGE_ORDER.ToString();
                }
                else
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.IR_CHANGE_ORDER.ToString();
                }
                _service.Create(azIntCallEntity);
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Exemplo n.º 3
0
        private void CreateInComingGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, string propertyID, DateTime appointmentCreatedOn, DateTime appointmentSchStart, DateTime appointmentSchEnd, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");

                List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                gridEventDataPayload.EventTime = DateTime.Now.ToString();
                gridEventDataPayload.EventType = "allEvents";
                gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.Subject = $"Turn Process : {Events.MARKET_SCHEDULES_PRE_MOVE_OUT.ToString()}";
                }
                else
                {
                    gridEventDataPayload.Subject = $"Initial Renovation : {Events.SCHEDULE_DUE_DILLIGENCE_INSPECTION.ToString()}";
                }

                gridEventDataPayload.data       = new DataPayLoad();
                gridEventDataPayload.data.Date1 = appointmentCreatedOn.ToString();
                tracer.Trace($"App Scheduled Start : {appointmentSchStart.ToString()}");
                tracer.Trace($"App Scheduled End : {appointmentSchEnd.ToString()}");
                gridEventDataPayload.data.Date2 = appointmentSchStart.ToString();
                gridEventDataPayload.data.Date3 = appointmentSchEnd.ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.data.Event = Events.MARKET_SCHEDULES_PRE_MOVE_OUT;
                }
                else
                {
                    gridEventDataPayload.data.Event = Events.SCHEDULE_DUE_DILLIGENCE_INSPECTION;
                }
                gridEventDataPayload.data.IsForce    = false;
                gridEventDataPayload.data.PropertyID = propertyID;

                gridEventDataPayloadList.Add(gridEventDataPayload);

                Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = false;
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.MARKET_SCHEDULES_PRE_MOVE_OUT.ToString();
                }
                else
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.SCHEDULE_DUE_DILLIGENCE_INSPECTION.ToString();
                }

                _service.Create(azIntCallEntity);
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Exemplo n.º 4
0
        private void CreateOutGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, Entity projectEntity, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings, string propertyID)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");
                Entity systemuserEntity = _service.Retrieve(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectManager).LogicalName, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectManager).Id, new ColumnSet(true));
                if (systemuserEntity is Entity && systemuserEntity.Attributes.Contains(Constants.SystemUsers.UserName))
                {
                    List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                    GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                    gridEventDataPayload.EventTime = DateTime.Now.ToString();
                    gridEventDataPayload.EventType = "allEvents";
                    gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                    {
                        gridEventDataPayload.Subject = $"Turn Process : {Events.ASSIGN_PROJECT_MANAGER.ToString()}";
                    }
                    else
                    {
                        gridEventDataPayload.Subject = $"Initial Renovation : {Events.IR_ASSIGN_PROJECT_MANAGER.ToString()}";
                    }
                    gridEventDataPayload.data       = new DataPayLoad();
                    gridEventDataPayload.data.Date1 = DateTime.Now.ToString();
                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                    {
                        gridEventDataPayload.data.Event = Events.ASSIGN_PROJECT_MANAGER;
                    }
                    else
                    {
                        gridEventDataPayload.data.Event = Events.IR_ASSIGN_PROJECT_MANAGER;
                    }
                    gridEventDataPayload.data.IsForce     = false;
                    gridEventDataPayload.data.PropertyID  = propertyID;
                    gridEventDataPayload.data.EmailID     = systemuserEntity.GetAttributeValue <string>(Constants.SystemUsers.UserName);
                    gridEventDataPayload.data.FotoNotesID = "";
                    gridEventDataPayload.data.JobID       = "";
                    gridEventDataPayload.data.RenowalkID  = projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID);

                    gridEventDataPayloadList.Add(gridEventDataPayload);

                    Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                    azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = true;
                    if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                    {
                        azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.ASSIGN_PROJECT_MANAGER.ToString();
                    }
                    else
                    {
                        azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.IR_ASSIGN_PROJECT_MANAGER.ToString();
                    }
                    _service.Create(azIntCallEntity);
                }
                else
                {
                    tracer.Trace($"System User (Project Manager) Not Found or Primary Email (internalemailaddress) Not found for System User (Project Manager).");
                }
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }
Exemplo n.º 5
0
        public static Entity CreateProjectFromProjectTemplate(ITracingService tracer, IOrganizationService service, Entity unitEntity, Entity projectTemplateEntity, DateTime startDate, int timeZoneCode, GridEvent <DataPayLoad> gridEvent)
        {
            DateTime moveOutDate;

            startDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, startDate);
            tracer.Trace($"Local Date 1 : {startDate}");

            tracer.Trace($"Creating {projectTemplateEntity.GetAttributeValue<string>(Constants.Projects.Subject)} for {unitEntity.GetAttributeValue<string>(Constants.Units.Name)}.");
            string projectName   = (projectTemplateEntity.GetAttributeValue <string>(Constants.Projects.Subject).Equals("Turn Process", StringComparison.OrdinalIgnoreCase) ? "Turn " : "Reno ") + unitEntity.GetAttributeValue <string>(Constants.Units.Name);
            Entity projectEntity = new Entity(Constants.Projects.LogicalName);

            projectEntity[Constants.Projects.Unit]                   = unitEntity.ToEntityReference();
            projectEntity[Constants.Projects.ProjectTemplate]        = projectTemplateEntity.ToEntityReference();
            projectEntity[Constants.Projects.Subject]                = projectName;
            projectEntity[Constants.Projects.StartDate]              = startDate;
            projectEntity[Constants.Projects.ActualStartDate]        = startDate;
            projectEntity[Constants.Projects.InitialJSONDataPayLoad] = CommonMethods.Serialize <DataPayLoad>(gridEvent.data);
            if (!string.IsNullOrEmpty(gridEvent.data.RenowalkID))
            {
                projectEntity[Constants.Projects.RenowalkID] = gridEvent.data.RenowalkID;
            }
            if (!DateTime.TryParse(gridEvent.data.Date2, out moveOutDate))
            {
                if (unitEntity.Attributes.Contains(Constants.Units.MoveOutDate))
                {
                    moveOutDate = unitEntity.GetAttributeValue <DateTime>(Constants.Units.MoveOutDate);
                }
            }
            moveOutDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, unitEntity.GetAttributeValue <DateTime>(Constants.Units.MoveOutDate));
            tracer.Trace($"Move Out Date : {moveOutDate}.");

            if (projectTemplateEntity.GetAttributeValue <string>(Constants.Projects.Subject).Equals("Turn Process", StringComparison.OrdinalIgnoreCase))
            {
                projectEntity[Constants.Projects.CurrentResidentMoveOutDate] = moveOutDate;
                tracer.Trace($"Est. Job Start Date : {moveOutDate.ChangeTime(6, 0, 0, 0).AddDays(1)}.");
                projectEntity[Constants.Projects.ScheduledJobStartDate] = moveOutDate.ChangeTime(6, 0, 0, 0).AddDays(1);
                tracer.Trace($"Est. Job Complete Date : {moveOutDate.ChangeTime(6, 0, 0, 0).AddDays(6)}.");
                projectEntity[Constants.Projects.ScheduledJobCompletionDate] = moveOutDate.ChangeTime(6, 0, 0, 0).AddDays(6);
            }
            else
            {
                if (unitEntity.Attributes.Contains(Constants.Units.ScheduledAcquisitionDate))
                {
                    DateTime schStartDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, unitEntity.GetAttributeValue <DateTime>(Constants.Units.ScheduledAcquisitionDate));
                    projectEntity[Constants.Projects.ScheduledJobStartDate]      = schStartDate.AddDays(1);
                    projectEntity[Constants.Projects.ScheduledJobCompletionDate] = schStartDate.AddDays(11);
                }
            }
            if (moveOutDate > startDate)
            {
                projectEntity[Constants.Projects.DueDate] = moveOutDate.AddHours(24);
            }

            projectEntity.Id = service.Create(projectEntity);

            tracer.Trace($"{projectTemplateEntity.GetAttributeValue<string>(Constants.Projects.Subject)} for {unitEntity.GetAttributeValue<string>(Constants.Units.Name)} successfully created.");
            SetUnitSyncJobFlag(tracer, service, unitEntity.ToEntityReference(), true);

            return(projectEntity);
        }