Ejemplo n.º 1
0
        public async Task <List <PatientVisitProducts> > getActiveVisits(string patientId)
        {
            if (!string.IsNullOrEmpty(patientId))
            {
                List <PatientVisitProducts> workOrders = new List <PatientVisitProducts>();
                QueryExpression             query      = new QueryExpression(xrm.Incident.EntityLogicalName);
                query.Criteria.AddCondition("customerid", ConditionOperator.Equal, new Guid(patientId));
                query.ColumnSet = new ColumnSet("mzk_contract");

                LinkEntity caseWorkOrder = new LinkEntity(xrm.Incident.EntityLogicalName, xrm.msdyn_workorder.EntityLogicalName, "incidentid", "msdyn_servicerequest", JoinOperator.Inner)
                {
                    Columns      = new ColumnSet("mzk_scheduledstartdatetime", "mzk_visitnumber", "msdyn_workorderid"),
                    LinkCriteria =
                    {
                        Conditions     =
                        {
                            new ConditionExpression("mzk_visitstatus", ConditionOperator.Equal, 275380001), //Confirmed (Previously it was Scheduled 13)
                            new ConditionExpression("mzk_visittype",   ConditionOperator.Equal, 275380001)  //Delivery Visit
                        },
                        FilterOperator = LogicalOperator.And
                    },
                    EntityAlias = "workOrder"
                };
                query.LinkEntities.Add(caseWorkOrder);

                SoapEntityRepository repo             = SoapEntityRepository.GetService();
                EntityCollection     entityCollection = repo.GetEntityCollection(query);
                var groupedWorkOrders = entityCollection.Entities.GroupBy(item => (item.GetAttributeValue <Guid>("incidentid")));
                foreach (var groupedVisits in groupedWorkOrders)
                {
                    foreach (Entity entity in groupedVisits)
                    {
                        PatientVisitProducts workOrder = new PatientVisitProducts();
                        if (entity.Attributes.Contains("workOrder.msdyn_workorderid"))
                        {
                            workOrder.workOrderId = entity.GetAttributeValue <AliasedValue>("workOrder.msdyn_workorderid").Value.ToString();
                        }
                        if (entity.Attributes.Contains("workOrder.mzk_scheduledstartdatetime"))
                        {
                            workOrder.visitDate = (DateTime)(entity.GetAttributeValue <AliasedValue>("workOrder.mzk_scheduledstartdatetime").Value);
                        }
                        if (entity.Attributes.Contains("workOrder.mzk_visitnumber"))
                        {
                            workOrder.visitNumber = Int32.Parse(entity.GetAttributeValue <AliasedValue>("workOrder.mzk_visitnumber").Value.ToString());
                        }
                        if (entity.Attributes.Contains("mzk_contract"))
                        {
                            workOrder.contract = (entity["mzk_contract"] as EntityReference).Name;
                        }

                        workOrders.Add(workOrder);
                    }
                }
                return(workOrders);
            }
            else
            {
                throw new ValidationException("Patient Id missing");
            }
        }
 public async Task <bool> updateWorkOrderProduct(PatientVisitProducts products)
 {
     if (!string.IsNullOrEmpty(products.workOrderProductId))
     {
         SoapEntityRepository repo = SoapEntityRepository.GetService();
         Entity workOrderProduct   = new Entity(xrm.msdyn_workorderproduct.EntityLogicalName, new Guid(products.workOrderProductId));
         if (products.stockLevel != -1)
         {
             workOrderProduct["mzk_currentstocklevel"] = products.stockLevel;
         }
         try
         {
             repo.UpdateEntity(workOrderProduct);
             return(true);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     else
     {
         throw new ValidationException("Work Order Product Id not found");
     }
 }