예제 #1
0
        public string GeneratePatientNo(string userID)
        {
            string             result             = "";
            HospitalProfileDto hospitalProfileDto = GetHospital(userID);
            var    hospitalID = hospitalProfileDto.UniqueID;
            string prefix = "";
            int    maxLength = 0, currentValue = 0;
            ConsultationPatientNo consultationPatientNo = _DBContext.Set <ConsultationPatientNo>().FirstOrDefault(c => c.HospitalID == hospitalID);
            ConsultationContext   consultationContext = (ConsultationContext)_DBContext;

            if (consultationPatientNo != null)
            {
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required,
                                                                  new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.Serializable
                }))
                {
                    consultationPatientNo = consultationContext.Set <ConsultationPatientNo>().FirstOrDefault(c => c.HospitalID == hospitalID);
                    consultationPatientNo.CurrentValue++;
                    consultationContext.SaveChanges();

                    ts.Complete();
                }
                prefix       = consultationPatientNo.Prefix;
                maxLength    = consultationPatientNo.MaxLength;
                currentValue = consultationPatientNo.CurrentValue;
            }
            else
            {
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required,
                                                                  new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.Serializable
                }))
                {
                    consultationPatientNo = consultationContext.Set <ConsultationPatientNo>().FirstOrDefault(c => c.HospitalID == null || c.HospitalID == "");
                    consultationPatientNo.CurrentValue++;
                    consultationContext.SaveChanges();

                    ts.Complete();
                }
                prefix       = consultationPatientNo.Prefix;
                maxLength    = consultationPatientNo.MaxLength;
                currentValue = consultationPatientNo.CurrentValue;
            }

            if (maxLength > 0 && currentValue > 0)
            {
                result = !string.IsNullOrEmpty(prefix)
                    ? prefix + currentValue.ToString().PadLeft(maxLength, '0')
                    : currentValue.ToString().PadLeft(maxLength, '0');
            }

            return(result);
        }
예제 #2
0
        public bool SaveHospital(HospitalProfileDto hospitalDto)
        {
            hospitalDto.LastEditTime = DateTime.Now;
            hospitalDto.LastEditUser = _LoginUserService.CurrentUserID;
            var rep      = new HospitalProfileRepository(_DBContext);
            var existing = rep.Get(h => h.UniqueID == hospitalDto.UniqueID).FirstOrDefault();

            if (existing == null)
            {
                rep.Add(Mapper.Map <HospitalProfileDto, HospitalProfile>(hospitalDto));
            }
            else
            {
                Mapper.Map(hospitalDto, existing);
                rep.Update(existing);
            }
            rep.SaveChanges();
            return(true);
        }
예제 #3
0
 public IHttpActionResult SaveHospital(HospitalProfileDto hospital)
 {
     return(Ok(_UserManagementService.SaveHospital(hospital)));
 }