/// <summary>
 /// Updates the database with any missing model term associations.
 /// </summary>
 /// <param name="modelID"></param>
 /// <param name="terms"></param>
 public void UpdateModelTerms(Guid modelID, IEnumerable <IModelTerm> terms)
 {
     using (var db = new Lpp.Dns.Data.DataContext())
     {
         foreach (var trm in terms)
         {
             db.Database.ExecuteSqlCommand("IF(NOT EXISTS(SELECT NULL FROM DataModelSupportedTerms WHERE DataModelID = @p0 AND TermID = @p1)) INSERT INTO DataModelSupportedTerms (DataModelID, TermID) VALUES (@p0, @p1)", modelID, trm.ID);
         }
     }
 }
 /// <summary>
 /// Updates the database from the provided terms with any that are missing.
 /// </summary>
 /// <param name="terms"></param>
 public void UpdateTerms(IEnumerable <IModelTerm> terms)
 {
     using (var db = new Lpp.Dns.Data.DataContext())
     {
         foreach (var trm in terms)
         {
             db.Database.ExecuteSqlCommand("IF(NOT EXISTS (SELECT NULL FROM Terms WHERE Terms.ID = @p0)) INSERT INTO Terms (ID, Name, Description, OID, ReferenceUrl) VALUES (@p0, @p1, @p2, @p3, @p4)", trm.ID, trm.Name, trm.Description, trm.OID, trm.ReferenceUrl);
         }
     }
 }
        public void Start()
        {
            lock (_lockObject)
            {
                if (_started)
                {
                    return;
                }
                _started = true;

                HostingEnvironment.RegisterObject(this);

                using (var db = new Lpp.Dns.Data.DataContext())
                {
                    GlobalConfiguration.Configuration.UseSqlServerStorage(db.Database.Connection.ConnectionString);
                }

                _backgroundJobServer = new BackgroundJobServer();
            }
        }
        /// <summary>
        /// Gets all the registerd package identifers from the database, interrogates the packages, and updates the Terms in the database as needed.
        /// </summary>
        public void Run()
        {
            IEnumerable <string> identifiers;

            using (var db = new Lpp.Dns.Data.DataContext())
            {
                identifiers = db.RequestTypes.Where(rt => !string.IsNullOrEmpty(rt.PackageIdentifier)).Select(rt => rt.PackageIdentifier).Distinct().ToArray();
            }

            var providers = Interrogate(identifiers);

            //Using Distinct if we initialize DataModelProcessorsDTO didn't seem to work. Anonymous type allowed it.
            var dmProcessors = (from p in providers
                                select new
            {
                ModelID = p.ModelID,
                ProcessorID = p.ProcessorID,
                Processor = p.Processor
            }).Distinct().ToList();

            DataModelProcessors = dmProcessors.Select(p => new Dns.DTO.DataModelProcessorDTO()
            {
                ModelID = p.ModelID, Processor = p.Processor, ProcessorID = p.ProcessorID
            });

            var comparer = new IModelTermComparer();
            IEnumerable <IModelTerm> terms = providers.SelectMany(p => p.Terms).Distinct(comparer);

            //update the main list of terms to make sure the term exists in the system.
            UpdateTerms(terms);

            foreach (var termProvider in providers.GroupBy(g => g.ModelID))
            {
                //update the association between the model and the term
                terms = termProvider.SelectMany(p => p.Terms).Distinct(comparer);
                UpdateModelTerms(termProvider.Key, terms);
            }
        }
        public async Task <ActionResult> Details()
        {
            using (var db = new Lpp.Dns.Data.DataContext())
            {
                Guid projectID          = Guid.Empty;
                Guid workflowActivityID = Guid.Empty;
                Guid requestTypeID      = Guid.Empty;
                Guid workflowID         = Guid.Empty;
                Guid organizationID     = Guid.Empty;

                Guid requestID;
                if (Guid.TryParse(Request.QueryString.Get("ID"), out requestID))
                {
                    var details = db.Requests.Where(r => r.ID == requestID).Select(r => new { r.ProjectID, r.WorkFlowActivityID, r.RequestTypeID, r.WorkflowID, r.OrganizationID }).Single();
                    projectID          = details.ProjectID;
                    workflowActivityID = details.WorkFlowActivityID ?? Guid.Empty;
                    requestTypeID      = details.RequestTypeID;
                    workflowID         = details.WorkflowID ?? Guid.Empty;
                    organizationID     = details.OrganizationID;
                }
                else
                {
                    Guid.TryParse(Request.QueryString.Get("projectID"), out projectID);
                    Guid.TryParse(Request.QueryString.Get("requestTypeID"), out requestTypeID);

                    var details = await(from wa in db.WorkflowActivities
                                        join cm in db.WorkflowActivityCompletionMaps on wa.ID equals cm.SourceWorkflowActivityID
                                        join rt in db.RequestTypes on cm.WorkflowID equals rt.WorkflowID
                                        where wa.Start && rt.ID == requestTypeID
                                        select new { workflowActivityID = wa.ID, workflowID = rt.WorkflowID }).FirstOrDefaultAsync();

                    workflowActivityID = details.workflowActivityID;
                    workflowID         = details.workflowID ?? Guid.Empty;
                    requestID          = Guid.Empty;
                    organizationID     = ApiIdentity.EmployerID.HasValue ? ApiIdentity.EmployerID.Value : Guid.Empty;
                }

                Lpp.Dns.Data.ExtendedQuery query = new Lpp.Dns.Data.ExtendedQuery
                {
                    Projects = p => p.ProjectID == projectID,
                    ProjectRequestTypeWorkflowActivity = p => p.ProjectID == projectID && p.RequestTypeID == requestTypeID && p.WorkflowActivityID == workflowActivityID
                };

                if (organizationID != Guid.Empty)
                {
                    query.Organizations = o => o.OrganizationID == organizationID;
                }

                var permissionsList = new List <PermissionDefinition>(Lpp.Dns.DTO.Security.PermissionIdentifiers.ProjectRequestTypeWorkflowActivities.Permissions().ToArray());
                permissionsList.Add(Lpp.Dns.DTO.Security.PermissionIdentifiers.DataMartInProject.SeeRequests);
                permissionsList.Add(Lpp.Dns.DTO.Security.PermissionIdentifiers.Request.AssignRequestLevelNotifications);

                var grantedPermissions = await db.HasGrantedPermissions(ApiIdentity, query, permissionsList.ToArray());

                ViewBag.ScreenPermissions = grantedPermissions.Select(p => p.ID).ToList();

                ViewBag.TaskOverviewPartial = "~/Areas/QueryComposer/Views/View.cshtml";
                if (workflowActivityID != Guid.Empty)
                {
                    var activity = Lpp.Dns.Portal.Areas.Workflow.WorkflowAreaRegistration.Activities.FirstOrDefault(x => (x.WorkflowActivityID == workflowActivityID) && ((x.WorkflowID.HasValue && x.WorkflowID == workflowID) || (x.WorkflowID.HasValue == false && Areas.Workflow.WorkflowAreaRegistration.Activities.Count(a => a.WorkflowActivityID == x.WorkflowActivityID) == 1)));



                    if (activity != null && !string.IsNullOrEmpty(activity.OverviewPath))
                    {
                        // use new activity.OverviewPath to set the ViewBag.TaskOverviewPartial
                        ViewBag.TaskOverviewPartial = "~/Areas/" + activity.OverviewPath;
                    }
                }

                return(View());
            }
        }
Beispiel #6
0
        /// <summary>
        /// Updates the database from the provided terms with any that are missing or needs to be updated.
        /// </summary>
        /// <param name="terms"></param>
        public void UpdateTerms(IEnumerable <IModelTerm> terms)
        {
            using (var db = new Lpp.Dns.Data.DataContext())
            {
                //The Terms that are passed are from all the adapters so Distinct them.
                var termIDs = terms.Select(x => x.ID).Distinct().ToArray();

                var existingTerms = db.Terms.Where(x => termIDs.Contains(x.ID)).ToArray();

                var changed = false;

                //The Terms that are passed may have already been altered so generate a list of already altered terms based on their ID's.
                List <Guid> checkedIDs = new List <Guid>();

                foreach (var term in terms)
                {
                    if (!checkedIDs.Contains(term.ID))
                    {
                        var existingTerm = existingTerms.Where(x => x.ID == term.ID).FirstOrDefault();

                        if (existingTerm == null)
                        {
                            db.Terms.Add(new Dns.Data.Term
                            {
                                ID           = term.ID,
                                Name         = term.Name,
                                ReferenceUrl = term.ReferenceUrl,
                                OID          = term.OID,
                            });

                            if (!changed)
                            {
                                changed = true;
                            }

                            checkedIDs.Add(term.ID);
                        }
                        else
                        {
                            if (!string.Equals(term.Name, existingTerm.Name))
                            {
                                existingTerm.Name = term.Name;
                                if (!changed)
                                {
                                    changed = true;
                                }
                            }

                            if (!string.Equals(term.Description, existingTerm.Description))
                            {
                                existingTerm.Description = term.Description;
                                if (!changed)
                                {
                                    changed = true;
                                }
                            }

                            if (!string.Equals(term.OID, existingTerm.OID))
                            {
                                existingTerm.OID = term.OID;
                                if (!changed)
                                {
                                    changed = true;
                                }
                            }

                            if (!string.Equals(term.ReferenceUrl, existingTerm.ReferenceUrl))
                            {
                                existingTerm.ReferenceUrl = term.ReferenceUrl;
                                if (!changed)
                                {
                                    changed = true;
                                }
                            }

                            checkedIDs.Add(term.ID);
                        }
                    }
                }

                if (changed)
                {
                    db.SaveChanges();
                }
            }
        }