Beispiel #1
0
        private MEContactCareTeam GetCareTeam(string careTeamId)
        {
            MEContactCareTeam res = null;

            try
            {
                using (var ctx = new ContactCareTeamMongoContext(_dbName))
                {
                    ObjectId cid;
                    if (ObjectId.TryParse(careTeamId, out cid))
                    {
                        var queries = new List <IMongoQuery>
                        {
                            MB.Query <MEContactCareTeam> .EQ(c => c.Id, cid),
                            MB.Query <MEContactCareTeam> .EQ(c => c.DeleteFlag, false)
                        };

                        var query    = MB.Query.And(queries);
                        var careTeam = ctx.CareTeam.Collection.FindOne(query);
                        res = careTeam;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(res);
        }
Beispiel #2
0
        private CareTeamData BuildCareTeamData(MEContactCareTeam meCareTeam)
        {
            CareTeamData team = null;

            if (meCareTeam != null)
            {
                team = new CareTeamData
                {
                    Id          = meCareTeam.Id.ToString(),
                    ContactId   = meCareTeam.ContactId.ToString(),
                    Members     = BuildCareTeamMembers(meCareTeam.MeCareTeamMembers),
                    CreatedOn   = meCareTeam.RecordCreatedOn,
                    CreatedById = meCareTeam.RecordCreatedBy.ToString(),
                    UpdatedById = meCareTeam.UpdatedBy == null ? null : meCareTeam.UpdatedBy.ToString(),
                    UpdatedOn   = meCareTeam.LastUpdatedOn
                };
            }
            return(team);
        }
Beispiel #3
0
        public object Insert(object newEntity)
        {
            var careTeam = new object();
            var data     = newEntity as SaveCareTeamDataRequest;

            if (data != null)
            {
                try
                {
                    using (var ctx = new ContactCareTeamMongoContext(_dbName))
                    {
                        var queries = new List <IMongoQuery>
                        {
                            MB.Query <MEContactCareTeam> .EQ(c => c.ContactId, ObjectId.Parse(data.ContactId)),
                            MB.Query <MEContactCareTeam> .EQ(c => c.DeleteFlag, false)
                        };

                        var query           = MB.Query.And(queries);
                        var contactCareTeam = ctx.CareTeam.Collection.FindOne(query);

                        if (contactCareTeam == null)
                        {
                            //Add
                            var meCareTeam = new MEContactCareTeam(this.UserId, DateTime.UtcNow)
                            {
                                ContactId         = ObjectId.Parse(data.ContactId),
                                MeCareTeamMembers = BuildMECareTeamMembers(data.CareTeamData.Members, this.UserId),
                                DeleteFlag        = false
                            };

                            ctx.CareTeam.Collection.Save(meCareTeam);
                            // response = meCareTeam.Id.ToString();
                            AuditHelper.LogDataAudit(this.UserId,
                                                     MongoCollectionName.CareTeam.ToString(),
                                                     meCareTeam.Id.ToString(),
                                                     DataAuditType.Insert,
                                                     data.ContractNumber);
                        }
                        else
                        {
                            var oldMembers = contactCareTeam.MeCareTeamMembers;
                            //Update
                            contactCareTeam.MeCareTeamMembers = BuildMECareTeamMembers(data.CareTeamData.Members,
                                                                                       this.UserId);
                            contactCareTeam.UpdatedBy     = ObjectId.Parse(this.UserId);
                            contactCareTeam.LastUpdatedOn = DateTime.UtcNow;

                            foreach (var m in oldMembers)
                            {
                                var newmember = contactCareTeam.MeCareTeamMembers.FirstOrDefault(c => c.Id == m.Id);
                                if (newmember != null)
                                {
                                    newmember.RecordCreatedBy = m.RecordCreatedBy;
                                    newmember.RecordCreatedOn = m.RecordCreatedOn;
                                }
                            }

                            var addingMembers = contactCareTeam.MeCareTeamMembers.Except(oldMembers);

                            foreach (var member in addingMembers)
                            {
                                if (member.RecordCreatedBy == ObjectId.Empty)
                                {
                                    member.RecordCreatedBy = ObjectId.Parse(this.UserId);
                                }

                                if (member.RecordCreatedOn == DateTime.MinValue || member.RecordCreatedOn == null)
                                {
                                    member.RecordCreatedOn = DateTime.UtcNow;
                                }
                            }

                            ctx.CareTeam.Collection.Save(contactCareTeam);
                            //response = contactCareTeam.Id.ToString();

                            AuditHelper.LogDataAudit(this.UserId,
                                                     MongoCollectionName.CareTeam.ToString(),
                                                     contactCareTeam.Id.ToString(),
                                                     DataAuditType.Update,
                                                     data.ContractNumber);
                        }

                        careTeam = GetCareTeamByContactId(data.ContactId);

                        if (careTeam == null)
                        {
                            throw new Exception("Care Team is null or empty");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(careTeam);
        }