Пример #1
0
        /// <summary>
        /// Cập nhật thông tin bác sĩ
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public override async Task <bool> UpdateAsync(Doctors item)
        {
            bool result = false;
            var  exists = await Queryable
                          .AsNoTracking()
                          .Where(e => e.Id == item.Id && !e.Deleted)
                          .FirstOrDefaultAsync();

            if (exists != null)
            {
                exists = mapper.Map <Doctors>(item);
                unitOfWork.Repository <Doctors>().Update(exists);

                // Cập nhật thông tin chuyên khoa của bác sĩ
                if (item.DoctorDetails != null && item.DoctorDetails.Any())
                {
                    foreach (var doctorDetail in item.DoctorDetails)
                    {
                        var existDoctorDetail = await unitOfWork.Repository <DoctorDetails>().GetQueryable()
                                                .AsNoTracking()
                                                .Where(e => e.Id == doctorDetail.Id && !e.Deleted)
                                                .FirstOrDefaultAsync();

                        if (existDoctorDetail != null)
                        {
                            existDoctorDetail          = mapper.Map <DoctorDetails>(doctorDetail);
                            existDoctorDetail.DoctorId = exists.Id;
                            existDoctorDetail.Updated  = DateTime.Now;
                            unitOfWork.Repository <DoctorDetails>().Update(existDoctorDetail);
                        }
                        else
                        {
                            doctorDetail.DoctorId = exists.Id;
                            doctorDetail.Created  = DateTime.Now;
                            await unitOfWork.Repository <DoctorDetails>().CreateAsync(doctorDetail);
                        }
                    }
                }
                await unitOfWork.SaveAsync();

                result = true;
            }
            return(result);
        }
Пример #2
0
        public override async Task <bool> UpdateAsync(MedicalRecords item)
        {
            bool result = false;
            var  exists = await Queryable
                          .AsNoTracking()
                          .Where(e => e.Id == item.Id && !e.Deleted)
                          .FirstOrDefaultAsync();

            if (exists != null)
            {
                exists = mapper.Map <MedicalRecords>(item);
                unitOfWork.Repository <MedicalRecords>().Update(exists);

                // Cập nhật thông tin người thân của hồ sơ
                if (item.MedicalRecordAdditions != null && item.MedicalRecordAdditions.Any())
                {
                    foreach (var medicalRecordAddition in item.MedicalRecordAdditions)
                    {
                        var existMedicalRecordAddition = await unitOfWork.Repository <MedicalRecordAdditions>().GetQueryable()
                                                         .AsNoTracking()
                                                         .Where(e => e.Id == medicalRecordAddition.Id && !e.Deleted)
                                                         .FirstOrDefaultAsync();

                        if (existMedicalRecordAddition != null)
                        {
                            existMedicalRecordAddition = mapper.Map <MedicalRecordAdditions>(medicalRecordAddition);
                            existMedicalRecordAddition.MedicalRecordId = exists.Id;
                            existMedicalRecordAddition.Updated         = DateTime.Now;
                            unitOfWork.Repository <MedicalRecordAdditions>().Update(existMedicalRecordAddition);
                        }
                        else
                        {
                            medicalRecordAddition.MedicalRecordId = exists.Id;
                            medicalRecordAddition.Created         = DateTime.Now;
                            await unitOfWork.Repository <MedicalRecordAdditions>().CreateAsync(medicalRecordAddition);
                        }
                    }
                }
                await unitOfWork.SaveAsync();

                result = true;
            }
            return(result);
        }
Пример #3
0
        public override async Task <bool> UpdateAsync(ExaminationSchedules item)
        {
            bool result = false;
            var  exists = await Queryable
                          .AsNoTracking()
                          .Where(e => e.Id == item.Id && !e.Deleted)
                          .FirstOrDefaultAsync();

            if (exists != null)
            {
                exists = mapper.Map <ExaminationSchedules>(item);
                unitOfWork.Repository <ExaminationSchedules>().Update(exists);

                // Cập nhật thông tin chi tiết ca
                if (item.ExaminationScheduleDetails != null && item.ExaminationScheduleDetails.Any())
                {
                    foreach (var examinationScheduleDetail in item.ExaminationScheduleDetails)
                    {
                        var existExaminationScheduleDetail = await unitOfWork.Repository <ExaminationScheduleDetails>().GetQueryable()
                                                             .AsNoTracking()
                                                             .Where(e => e.Id == examinationScheduleDetail.Id && !e.Deleted)
                                                             .FirstOrDefaultAsync();

                        if (existExaminationScheduleDetail != null)
                        {
                            existExaminationScheduleDetail            = mapper.Map <ExaminationScheduleDetails>(examinationScheduleDetail);
                            existExaminationScheduleDetail.ScheduleId = exists.Id;
                            existExaminationScheduleDetail.Updated    = DateTime.Now;
                            unitOfWork.Repository <ExaminationScheduleDetails>().Update(examinationScheduleDetail);
                        }
                        else
                        {
                            examinationScheduleDetail.ScheduleId = exists.Id;
                            examinationScheduleDetail.Created    = DateTime.Now;
                            await unitOfWork.Repository <ExaminationScheduleDetails>().CreateAsync(examinationScheduleDetail);
                        }
                    }
                }
                await unitOfWork.SaveAsync();

                result = true;
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Cập nhật thông tin bệnh viện
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public override async Task <bool> UpdateAsync(Hospitals item)
        {
            bool result = false;
            var  exists = await Queryable
                          .AsNoTracking()
                          .Where(e => e.Id == item.Id && !e.Deleted)
                          .FirstOrDefaultAsync();

            if (exists != null)
            {
                exists = mapper.Map <Hospitals>(item);
                unitOfWork.Repository <Hospitals>().Update(exists);

                // Cập nhật thông tin dịch vụ
                if (item.ServiceTypeMappingHospitals != null && item.ServiceTypeMappingHospitals.Any())
                {
                    foreach (var serviceTypeMappingHospital in item.ServiceTypeMappingHospitals)
                    {
                        var existServiceTypeMapping = await unitOfWork.Repository <ServiceTypeMappingHospital>().GetQueryable()
                                                      .AsNoTracking()
                                                      .Where(e => e.Id == serviceTypeMappingHospital.Id && !e.Deleted)
                                                      .FirstOrDefaultAsync();

                        if (existServiceTypeMapping != null)
                        {
                            serviceTypeMappingHospital.Updated   = DateTime.Now;
                            serviceTypeMappingHospital.UpdatedBy = item.UpdatedBy;
                            existServiceTypeMapping = mapper.Map <ServiceTypeMappingHospital>(serviceTypeMappingHospital);
                            unitOfWork.Repository <ServiceTypeMappingHospital>().Update(existServiceTypeMapping);
                        }
                        else
                        {
                            serviceTypeMappingHospital.HospitalId = item.Id;
                            serviceTypeMappingHospital.Created    = DateTime.Now;
                            serviceTypeMappingHospital.CreatedBy  = item.UpdatedBy;
                            await unitOfWork.Repository <ServiceTypeMappingHospital>().CreateAsync(serviceTypeMappingHospital);
                        }
                    }
                }

                // Cập nhật thông tin kênh thanh toán
                if (item.ChannelMappingHospitals != null && item.ChannelMappingHospitals.Any())
                {
                    foreach (var channelMappingHospital in item.ChannelMappingHospitals)
                    {
                        var existChannelMappingHospital = await unitOfWork.Repository <ChannelMappingHospital>().GetQueryable()
                                                          .AsNoTracking()
                                                          .Where(e => e.Id == channelMappingHospital.Id && !e.Deleted)
                                                          .FirstOrDefaultAsync();

                        if (existChannelMappingHospital != null)
                        {
                            channelMappingHospital.Updated   = DateTime.Now;
                            channelMappingHospital.UpdatedBy = item.UpdatedBy;
                            existChannelMappingHospital      = mapper.Map <ChannelMappingHospital>(channelMappingHospital);
                            unitOfWork.Repository <ChannelMappingHospital>().Update(existChannelMappingHospital);
                        }
                        else
                        {
                            channelMappingHospital.HospitalId = item.Id;
                            channelMappingHospital.Created    = DateTime.Now;
                            channelMappingHospital.CreatedBy  = item.UpdatedBy;
                            await unitOfWork.Repository <ChannelMappingHospital>().CreateAsync(channelMappingHospital);
                        }
                    }
                }
                // Cập nhật thông tin file của bệnh viện
                if (item.HospitalFiles != null && item.HospitalFiles.Any())
                {
                    foreach (var hospitalFile in item.HospitalFiles)
                    {
                        var existHospitalFile = await unitOfWork.Repository <HospitalFiles>().GetQueryable()
                                                .AsNoTracking()
                                                .Where(e => e.Id == hospitalFile.Id && !e.Deleted)
                                                .FirstOrDefaultAsync();

                        if (existHospitalFile != null)
                        {
                            hospitalFile.Updated   = DateTime.Now;
                            hospitalFile.UpdatedBy = item.UpdatedBy;
                            existHospitalFile      = mapper.Map <HospitalFiles>(hospitalFile);
                            unitOfWork.Repository <HospitalFiles>().Update(existHospitalFile);
                        }
                        else
                        {
                            hospitalFile.HospitalId = item.Id;
                            hospitalFile.Created    = DateTime.Now;
                            hospitalFile.CreatedBy  = item.UpdatedBy;
                            await unitOfWork.Repository <HospitalFiles>().CreateAsync(hospitalFile);
                        }
                    }
                }

                // Cập nhật thông tin ngân hàng liên kết
                if (item.BankInfos != null && item.BankInfos.Any())
                {
                    foreach (var bankInfo in item.BankInfos)
                    {
                        var existBankInfo = await unitOfWork.Repository <BankInfos>().GetQueryable()
                                            .AsNoTracking()
                                            .Where(e => e.Id == bankInfo.Id && !e.Deleted)
                                            .FirstOrDefaultAsync();

                        if (existBankInfo != null)
                        {
                            bankInfo.Updated   = DateTime.Now;
                            bankInfo.UpdatedBy = item.UpdatedBy;
                            existBankInfo      = mapper.Map <BankInfos>(bankInfo);
                            unitOfWork.Repository <BankInfos>().Update(existBankInfo);
                        }
                        else
                        {
                            bankInfo.HospitalId = item.Id;
                            bankInfo.Created    = DateTime.Now;
                            bankInfo.CreatedBy  = item.UpdatedBy;
                            await unitOfWork.Repository <BankInfos>().CreateAsync(bankInfo);
                        }
                    }
                }
                await unitOfWork.SaveAsync();

                result = true;
            }
            return(result);
        }
 public virtual async Task <IEnumerable <TEntity> > GetItemsAsync()
 {
     return(await Queryable.AsNoTracking().ToArrayAsync());
 }