public override async Task <GNSample> Insert(object entity)
        {
            LogUtil.LogMethod(logger, MethodBase.GetCurrentMethod());

            GNSample sample = (GNSample)entity;

            try
            {
                sample.CreateDateTime = DateTime.Now;

                sample = await base.Insert(sample);

                Guid analysisRequestId = Guid.Empty;
                Guid.TryParse(sample.CurrentAnalysisRequestId, out analysisRequestId);
                AssociateSampleToAnalysisRequest(sample.Id, analysisRequestId);
            }
            catch (Exception e1)
            {
                string errorMsg = "Unable to create sample.";
                errorMsg += GetSqlExceptionErrorMessage(e1);

                Exception e2 = new Exception(errorMsg, e1);
                LogUtil.Error(logger, e2.Message, e2);
                throw e2;
            }

            bool auditResult = new GNCloudNoSQLService().LogEvent(sample.CreatedByContact, sample.Id, this.ENTITY, "N/A", "EVENT_INSERT");

            return(sample);
        }
        public override async Task <GNContact> Insert(object entity)
        {
            GNContact contact = (GNContact)entity;

            bool isExistingOrgContact = (this.db.GNContacts
                                         .Count(c => c.GNOrganizationId == contact.GNOrganizationId &&
                                                c.Email == contact.Email) == 0) ? false : true;

            if (!isExistingOrgContact)
            {
                List <GNContactRole> contactRoles = null;
                if (contact.GNContactRoles != null && contact.GNContactRoles.Count != 0)
                {
                    contactRoles           = new List <GNContactRole>(contact.GNContactRoles);
                    contact.GNContactRoles = null;
                }

                contact = await base.Insert(entity);

                contact = this.db.GNContacts.Find(contact.Id);

                contact.GNContactRoles = contactRoles;
                this.db.SaveChanges();
            }
            else
            {
                throw new Exception("User with this email is already a contact for this organization.");
            }

            bool auditResult = new GNCloudNoSQLService().LogEvent(contact.CreatedByContact, contact.Id, this.ENTITY, "N/A", "EVENT_INSERT");

            return(contact);
        }
        public override async Task <GNContact> Update(GNContact userContact, object entity)
        {
            GNContact contact = (GNContact)entity;

            if (contact.IsSubscribedForNewsletters == null)
            {
                contact.IsSubscribedForNewsletters = false;
            }

            List <GNContactRole> contactRoles = null;

            if (contact.GNContactRoles != null && contact.GNContactRoles.Count != 0)
            {
                contactRoles = new List <GNContactRole>(contact.GNContactRoles.ToList());
            }

            contact = await base.Update(userContact, entity);

            var tx = db.Database.BeginTransaction();

            db.Database.ExecuteSqlCommand(
                "DELETE FROM [gn].[GNContactRoles] " +
                "WHERE [GNContactId] = @contactId ",
                new SqlParameter("@contactId", contact.Id));

            if (contactRoles != null)
            {
                foreach (var contactRole in contactRoles)
                {
                    db.Database.ExecuteSqlCommand(
                        "INSERT INTO [gn].[GNContactRoles] ([GNContactId],[AspNetRoleId],[CreatedBy],[CreateDateTime]) " +
                        "VALUES(@contactId,@aspNetRoleId,@createdBy,@createDateTime) ",
                        new SqlParameter("@contactId", contact.Id),
                        new SqlParameter("@aspNetRoleId", contactRole.AspNetRoleId),
                        new SqlParameter("@createdBy", userContact.Id),
                        new SqlParameter("@createDateTime", DateTime.Now));
                }
            }

            //tfrege 10/14/14
            List <GNNotificationTopicSubscriber> TopicSubscriptions = contact.GNNotificationTopicSubscribers.ToList();

            foreach (var subscription in TopicSubscriptions)
            {
                if (db.GNNotificationTopicSubscribers.Where(a => a.GNNotificationTopicId == subscription.GNNotificationTopicId && subscription.GNContactId.Equals(contact.Id)).Count() == 0)
                {
                    db.GNNotificationTopicSubscribers.Add(subscription);
                    db.SaveChanges();
                }
            }

            tx.Commit();

            contact = this.db.GNContacts.Find(contact.Id);

            bool auditResult = new GNCloudNoSQLService().LogEvent(userContact, contact.Id, this.ENTITY, "N/A", "EVENT_UPDATE");

            return(contact);
        }
Exemple #4
0
        public override async Task <GNProject> Insert(object entity)
        {
            LogUtil.LogMethod(logger, MethodBase.GetCurrentMethod());

            GNProject project = (GNProject)entity;

            try
            {
                project.Id             = Guid.NewGuid();
                project.CreateDateTime = DateTime.Now;

                var tx = db.Database.BeginTransaction();

                db.Database.ExecuteSqlCommand(
                    "INSERT INTO [gn].[GNProjects] " +
                    "([Id],[Name],[Description],[StartDate],[EndDate],[CreatedBy],[CreateDateTime],[ProjectLead_Id]) " +
                    "VALUES " +
                    "(@projectId, " +
                    "@projectName, " +
                    "@projectDescription, " +
                    "@projectStartDate, " +
                    "@projectEndDate, " +
                    "@projectCreatedBy, " +
                    "@projectCreateDateTime, " +
                    "@projectProjectLeadId)",
                    new SqlParameter("@projectId", project.Id),
                    new SqlParameter("@projectName", project.Name),
                    new SqlParameter("@projectDescription", project.Description),
                    new SqlParameter("@projectStartDate", project.StartDate),
                    new SqlParameter("@projectEndDate", project.EndDate),
                    new SqlParameter("@projectCreatedBy", project.CreatedBy.Value),
                    new SqlParameter("@projectCreateDateTime", project.CreateDateTime),
                    new SqlParameter("@projectProjectLeadId", Guid.Parse(project.ProjectLeadId)));

                db.Database.ExecuteSqlCommand(
                    "INSERT INTO [gn].[GNTeamGNProject]([Teams_Id],[Projects_Id]) " +
                    "VALUES(@teamId,@projectId)",
                    new SqlParameter("@teamId", Guid.Parse(project.TeamId)),
                    new SqlParameter("@projectId", project.Id));

                tx.Commit();

                bool auditResult = new GNCloudNoSQLService().LogEvent(project.CreatedByContact, project.Id, this.ENTITY, "N/A", "EVENT_INSERT");
            }
            catch (Exception e1)
            {
                string errorMsg = "Unable to create project.";
                errorMsg += GetSqlExceptionErrorMessage(e1);

                Exception e2 = new Exception(errorMsg, e1);
                LogUtil.Error(logger, e2.Message, e2);
                throw e2;
            }

            return(project);
        }
Exemple #5
0
        public override async Task <GNOrganization> Update(object entity)
        {
            GNOrganization org = null;

            org = SetUTCOffset(entity);

            bool auditResult = new GNCloudNoSQLService().LogEvent(org.CreatedByContact, org.Id, this.ENTITY, "N/A", "EVENT_UPDATE");

            return(await base.Update(org));
        }
        public async Task <int> AddRelationship(string leftSampleId, string rigthSampleId, string sampleRelationshipTypeId, GNContact userContact)
        {
            LogUtil.LogMethod(logger, MethodBase.GetCurrentMethod());

            return(await Task.Factory.StartNew <int>(() =>
            {
                int result = 0;

                if (leftSampleId != null && rigthSampleId != null && sampleRelationshipTypeId != null)
                {
                    var tx = db.Database.BeginTransaction();

                    result = db.Database.ExecuteSqlCommand(
                        "INSERT INTO [gn].[GNSampleRelationships]([GNLeftSampleId],[GNRightSampleId],[GNSampleRelationshipTypeId],[CreatedBy],[CreateDateTime]) " +
                        "VALUES(@leftSampleId, @rigthSampleId, @sampleRelationshipTypeId, @CreatedBy, @CreateDateTime)",
                        new SqlParameter("@leftSampleId", Guid.Parse(leftSampleId)),
                        new SqlParameter("@rigthSampleId", Guid.Parse(rigthSampleId)),
                        new SqlParameter("@sampleRelationshipTypeId", sampleRelationshipTypeId),
                        new SqlParameter("@CreatedBy", userContact.AspNetUserId),
                        new SqlParameter("@CreateDateTime", DateTime.Now));



                    //insert also the other-way relationship using the following mapping:
                    Guid guidLeftSampleId = Guid.Parse(leftSampleId);
                    int relationshipTypeId = Int32.Parse(sampleRelationshipTypeId);
                    string leftSampleGender = db.GNSamples.Where(a => a.Id.Equals(guidLeftSampleId)).FirstOrDefault().Gender;
                    string nameLeftSampleRel = db.GNSampleRelationshipTypes.Where(a => a.Id == relationshipTypeId).FirstOrDefault().Name;
                    string nameRightSampleRel = db.GNSampleRelationshipTypeMappings.Where(a => a.NameLeftRelationship.Equals(nameLeftSampleRel) && a.GenderRightRelationship == leftSampleGender).FirstOrDefault().NameRightRelationship;
                    int rightSampleRelationshipTypeId = db.GNSampleRelationshipTypes.Where(a => a.Name.Equals(nameRightSampleRel)).FirstOrDefault().Id;

                    result = db.Database.ExecuteSqlCommand(
                        "INSERT INTO [gn].[GNSampleRelationships]([GNLeftSampleId],[GNRightSampleId],[GNSampleRelationshipTypeId],[CreatedBy],[CreateDateTime]) " +
                        "VALUES(@leftSampleId, @rigthSampleId, @sampleRelationshipTypeId, @CreatedBy, @CreateDateTime)",
                        new SqlParameter("@leftSampleId", Guid.Parse(rigthSampleId)),
                        new SqlParameter("@rigthSampleId", Guid.Parse(leftSampleId)),
                        new SqlParameter("@sampleRelationshipTypeId", rightSampleRelationshipTypeId),
                        new SqlParameter("@CreatedBy", userContact.AspNetUserId),
                        new SqlParameter("@CreateDateTime", DateTime.Now));

                    tx.Commit();
                }

                bool auditResult = new GNCloudNoSQLService().LogEvent(userContact, Guid.Parse(leftSampleId), this.ENTITY, "N/A", "INSERT_RELATIONSHIP");
                auditResult = new GNCloudNoSQLService().LogEvent(userContact, Guid.Parse(rigthSampleId), this.ENTITY, "N/A", "INSERT_RELATIONSHIP");

                return result;
            }));
        }
        public override async Task <List <GNAudit> > FindAll(int start = 0, int end = 10, Dictionary <string, object> filters = null)
        {
            await Task.Delay(1);

            LogUtil.LogMethod(logger, MethodBase.GetCurrentMethod());

            List <GNAudit> results = new List <GNAudit>();

            try
            {
                GNCloudNoSQLService noSQL = new GNCloudNoSQLService();

                List <Dictionary <string, Amazon.DynamoDBv2.Model.AttributeValue> > logs = noSQL.ScanGNEvents(filters);

                foreach (var item in logs)
                {
                    try
                    {
                        GNAudit audit = new GNAudit();
                        foreach (KeyValuePair <string, Amazon.DynamoDBv2.Model.AttributeValue> entry in item)
                        {
                            string entryKey = entry.Key;
                            switch (entry.Key)
                            {
                            case "Id":
                                audit.Id = entry.Value.S.ToString();
                                break;

                            case "OrganizationId":
                                audit.OrganizationId    = Guid.Parse(entry.Value.S.ToString().Trim());
                                audit.ActorOrganization = db.GNOrganizations.Where(a => a.Id.Equals(audit.OrganizationId)).FirstOrDefault();
                                if (audit.ActorOrganization != null)
                                {
                                    audit.OrganizationName = audit.ActorOrganization.Name;
                                }
                                break;

                            case "Actor":
                                if (entry.Value.SS.Count() > 0)
                                {
                                    audit.ActorId    = Guid.Parse(entry.Value.SS.First().ToString());
                                    audit.ActorEmail = entry.Value.SS.Last().ToString();
                                    audit.Actor      = db.GNContacts.Where(a => a.Id.Equals(audit.ActorId)).FirstOrDefault();
                                    if (audit.Actor != null)
                                    {
                                        audit.ActorName = audit.Actor.FullName;
                                    }
                                }
                                break;

                            case "ActorEmail":
                                if (entry.Value.S.ToString().Trim() != "")
                                {
                                    audit.ActorEmail = entry.Value.S.ToString().Trim();
                                }
                                break;

                            case "ActorId":
                                if (entry.Value.S.ToString().Trim() != "")
                                {
                                    audit.ActorId = Guid.Parse(entry.Value.S.ToString().Trim());
                                    audit.Actor   = db.GNContacts.Where(a => a.Id.Equals(audit.ActorId)).FirstOrDefault();
                                    if (audit.Actor != null)
                                    {
                                        audit.ActorName = audit.Actor.FullName;
                                    }
                                }
                                break;

                            case "Action":
                            case "ActionExecuted":
                                audit.Action = entry.Value.S.ToString();
                                break;

                            case "EntityId":
                                audit.EntityId = Guid.Parse(entry.Value.S.ToString());
                                break;

                            case "EntityType":
                                audit.EntityType = entry.Value.S.ToString();
                                break;

                            case "IP":
                                audit.IP = entry.Value.S.ToString();
                                break;

                            case "Timestamp":
                                audit.Timestamp = DateTime.Parse(entry.Value.S.ToString());
                                break;

                            case "TimestampNumeric":
                                audit.TimestampNumeric = Int64.Parse(entry.Value.S.ToString());
                                break;
                            }
                        }
                        string auditEntityType = audit.EntityType;
                        switch (audit.EntityType)
                        {
                        case "CONTACT":
                            audit.Contact = db.GNContacts.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "ORGANIZATION":
                            audit.Organization = db.GNOrganizations.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "TEAM":
                            audit.Team = db.GNTeams.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "PROJECT":
                            audit.Project = db.GNProjects.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "SAMPLE":
                            audit.Sample = db.GNSamples.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "SAMPLE_RELATIONSHIP":
                            audit.Sample = db.GNSamples.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "ANALYSIS_REQUEST":
                            audit.Analysis = db.GNAnalysisRequests.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "SETTINGS_TEMPLATE":
                            audit.SettingsTemplate = db.GNSettingsTemplates.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "SETTINGS_TEMPLATE_CONFIG":
                            audit.SettingsTemplateConfig = db.GNSettingsTemplateConfigs.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "ACCOUNT":
                            audit.Account = db.GNAccounts.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "PRODUCT":
                            audit.Product = db.GNProducts.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "CLOUD_FILE":
                            audit.CloudFile = db.GNCloudFiles.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "INVOICE":
                            audit.Invoice = db.GNInvoices.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "INVOICE_DETAIL":
                            audit.InvoiceDetail = db.GNInvoiceDetails.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "PAYMENT":
                            audit.Payment = db.GNPayments.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "PURCHASE_ORDER":
                            audit.PurchaseOrder = db.GNPurchaseOrders.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;

                        case "USER":
                            //audit.User = db.GNAnalysisRequests.Where(a => a.Id.Equals(audit.EntityId)).FirstOrDefault();
                            break;
                        }

                        results.Add(audit);
                    }

                    catch (Exception e1)
                    {
                        logger.Error("Error while loading records from Audit table GNEvents " + e1.Message);
                    }
                }
            }
            catch (Exception e2)
            {
                logger.Error("Error while loading records from Audit table GNEvents " + e2.Message);
            }

            logger.Error("Returning  " + results.Count() + " results");
            return(results);
        }