Exemplo n.º 1
0
        public DomainObjectRepository()
        {
            dbContext = new PatientsMgtEntities();

            dbContext.Configuration.ProxyCreationEnabled = false;
            dbContext.Configuration.LazyLoadingEnabled   = false;
        }
        public PaymentModel UpdatePayment(PaymentModel payment)
        {
            var paymentToUpdate = _domainObjectRepository.Get <Payment>(p => p.PaymentID == payment.Id);

            if (paymentToUpdate != null)
            {
                Payment updatedPayment = new Payment()
                {
                    PatientCID    = payment.PatientCID,
                    AgencyID      = _domainObjectRepository.Get <Agency>(a => a.AgencyName == payment.Agency).AgencyID,
                    CAmount       = payment.CompanionAmount,
                    BeneficiaryID = _domainObjectRepository.Get <Beneficiary>(b => b.PatientCID == payment.PatientCID).BeneficiaryID,
                    CompanionCID  = payment.CompanionCID,
                    CreatedBy     = payment.CreatedBy,
                    CreatedDate   = payment.CreatedDate,
                    Notes         = payment.Notes,
                    EndDate       = payment.PaymentEndDate,
                    HospitalID    = _domainObjectRepository.Get <Hospital>(h => h.HospitalName == payment.Hospital).HospitalID,
                    ModifiedBy    = payment.ModifiedBy,

                    PAmount   = payment.PatientAmount,
                    PayRateID = _domainObjectRepository.Get <PayRate>(pr => pr.CompanionRate == payment.CompanionPayRate &&
                                                                      pr.PatientRate == payment.PatientPayRate).PayRateID,
                    PaymentDate  = payment.PaymentDate,
                    Period       = payment.PaymentLengthPeriod,
                    StartDate    = payment.PaymentStartDate,
                    TotalDue     = payment.TotalDue,
                    Id           = payment.Id,
                    PaymentID    = payment.Id,
                    ModifiedDate = DateTime.Now
                };
                paymentToUpdate = updatedPayment;
                //Todo This is a temp fix for updating the Payment
                PatientsMgtEntities dbContext = new PatientsMgtEntities();
                var entry = dbContext.Entry(paymentToUpdate);
                dbContext.Set <Payment>().Attach(paymentToUpdate);
                entry.State = EntityState.Modified;
                dbContext.SaveChanges();
                //
                //_domainObjectRepository.Update<Payment>(paymentToUpdate);
            }
            return(payment);
        }
Exemplo n.º 3
0
        public IList <T> CreateBulk <T>(IList <T> t) where T : class, IDomainObject
        {
            using (TransactionScope scope = new TransactionScope())
            {
                PatientsMgtEntities context  = null;
                IList <T>           newBatch = new List <T>();
                try
                {
                    context = new PatientsMgtEntities();
                    context.Configuration.AutoDetectChangesEnabled = false;

                    int count = 0;
                    foreach (var entityToInsert in t)
                    {
                        ++count;

                        if (entityToInsert is IAuditObject)
                        {
                            (entityToInsert as IAuditObject).CreatedDate = DateTime.Now;
                        }

                        T newEntry = context.Set <T>().Add(entityToInsert);
                        newBatch.Add(newEntry);
                    }

                    context.SaveChanges();
                }
                finally
                {
                    if (context != null)
                    {
                        context.Dispose();
                    }
                }

                scope.Complete();

                return(newBatch);
            }
        }