public override List <MIDAS.GBX.BusinessObjects.BusinessValidation> Validate <T>(T entity)
        {
            BO.DoctorLocationSchedule schedule = (BO.DoctorLocationSchedule)(object) entity;
            var result = schedule.Validate(schedule);

            return(result);
        }
 public override object Get(int id)
 {
     BO.DoctorLocationSchedule acc_ = Convert <BO.DoctorLocationSchedule, DoctorLocationSchedule>(_context.DoctorLocationSchedules.Include("Doctor").Include("Location").Include("Schedule").Where(p => p.id == id && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault <DoctorLocationSchedule>());
     if (acc_ == null)
     {
         return(new BO.ErrorObject {
             ErrorMessage = "No record found for this DoctorLocationSchedule.", errorObject = "", ErrorLevel = ErrorLevel.Error
         });
     }
     return((object)acc_);
 }
        public override object Delete <T>(T entity)
        {
            BO.DoctorLocationSchedule doctorlocationscheduleBO = entity as BO.DoctorLocationSchedule;

            DoctorLocationSchedule doctorlocationscheduleDB = new DoctorLocationSchedule();

            doctorlocationscheduleDB.id = doctorlocationscheduleBO.ID;
            _dbSet.Remove(_context.DoctorLocationSchedules.Single <DoctorLocationSchedule>(p => p.id == doctorlocationscheduleBO.ID));
            _context.SaveChanges();

            var res = (BO.GbObject)(object) entity;

            return(doctorlocationscheduleBO);
        }
 public override List <MIDAS.GBX.BusinessObjects.BusinessValidation> Validate <T>(T entity)
 {
     if (entity is List <BO.DoctorLocationSchedule> )
     {
         List <BO.DoctorLocationSchedule> lstdoctorlocationschedule = (List <BO.DoctorLocationSchedule>)(object) entity;
         //var result = lstdoctorlocationschedule.Validate(doctorlocationschedule);
         List <MIDAS.GBX.BusinessObjects.BusinessValidation> result = new List <BO.BusinessValidation>();
         return(result);
     }
     else
     {
         BO.DoctorLocationSchedule doctorlocationschedule = (BO.DoctorLocationSchedule)(object) entity;
         var result = doctorlocationschedule.Validate(doctorlocationschedule);
         return(result);
     }
 }
        public override object Save <T>(T entity)
        {
            BO.DoctorLocationSchedule scheduleBO = (BO.DoctorLocationSchedule)(object) entity;

            DoctorLocationSchedule scheduleDB = new DoctorLocationSchedule();

            #region DoctorLocationSchedule
            scheduleDB.id        = scheduleBO.ID;
            scheduleDB.Name      = scheduleBO.Name;
            scheduleDB.IsDeleted = scheduleBO.IsDeleted.HasValue ? scheduleBO.IsDeleted : false;
            #endregion

            if (scheduleDB.id > 0)
            {
                //For Update Record

                //Find DoctorLocationSchedule By ID
                DoctorLocationSchedule schedule = _context.Schedules.Where(p => p.id == scheduleDB.id).FirstOrDefault <DoctorLocationSchedule>();

                if (schedule != null)
                {
                    #region Location
                    schedule.id             = scheduleBO.ID;
                    schedule.Name           = scheduleBO.Name == null ? schedule.Name : scheduleBO.Name;
                    schedule.IsDeleted      = scheduleBO.IsDeleted == null ? scheduleBO.IsDeleted : schedule.IsDeleted;
                    schedule.UpdateDate     = scheduleBO.UpdateDate;
                    schedule.UpdateByUserID = scheduleBO.UpdateByUserID;
                    #endregion
                    _context.Entry(schedule).State = System.Data.Entity.EntityState.Modified;
                }
            }
            else
            {
                scheduleDB.CreateDate     = scheduleBO.CreateDate;
                scheduleDB.CreateByUserID = scheduleBO.CreateByUserID;
                _dbSet.Add(scheduleDB);
            }
            _context.SaveChanges();

            var res = Convert <BO.DoctorLocationSchedule, DoctorLocationSchedule>(scheduleDB);
            return((object)res);
        }
        public override object Get <T>(T entity)
        {
            List <BO.DoctorLocationSchedule> lstSchedules = new List <BO.DoctorLocationSchedule>();

            BO.DoctorLocationSchedule scheduleBO = (BO.DoctorLocationSchedule)(object) entity;

            var acc_ = _context.Schedules.Where(p => (p.IsDeleted == false || p.IsDeleted == null)).ToList <DoctorLocationSchedule>();

            if (acc_ == null || acc_.Count < 1)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "No records found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }
            foreach (DoctorLocationSchedule item in acc_)
            {
                lstSchedules.Add(Convert <BO.DoctorLocationSchedule, DoctorLocationSchedule>(item));
            }

            return(lstSchedules);
        }
        public override T Convert <T, U>(U entity)
        {
            DoctorLocationSchedule schedule = entity as DoctorLocationSchedule;

            if (schedule == null)
            {
                return(default(T));
            }

            BO.DoctorLocationSchedule scheduleBO = new BO.DoctorLocationSchedule();
            scheduleBO.Name = schedule.Name;
            scheduleBO.ID   = schedule.id;

            if (schedule.IsDeleted.HasValue)
            {
                scheduleBO.IsDeleted = schedule.IsDeleted.Value;
            }
            if (schedule.UpdateByUserID.HasValue)
            {
                scheduleBO.UpdateByUserID = schedule.UpdateByUserID.Value;
            }

            return((T)(object)scheduleBO);
        }
        public override T Convert <T, U>(U entity)
        {
            DoctorLocationSchedule doctorlocationschedule = entity as DoctorLocationSchedule;

            if (doctorlocationschedule == null)
            {
                return(default(T));
            }

            BO.DoctorLocationSchedule doctorlocationscheduleBO = new BO.DoctorLocationSchedule();

            doctorlocationscheduleBO.ID = doctorlocationschedule.id;
            if (doctorlocationschedule.IsDeleted.HasValue)
            {
                doctorlocationscheduleBO.IsDeleted = doctorlocationschedule.IsDeleted.Value;
            }
            if (doctorlocationschedule.UpdateByUserID.HasValue)
            {
                doctorlocationscheduleBO.UpdateByUserID = doctorlocationschedule.UpdateByUserID.Value;
            }

            if (doctorlocationschedule.Doctor != null && (doctorlocationschedule.Doctor.IsDeleted.HasValue == false || (doctorlocationschedule.Doctor.IsDeleted.HasValue == true && doctorlocationschedule.Doctor.IsDeleted.Value == false)))
            {
                BO.Doctor boDoctor = new BO.Doctor();
                using (DoctorRepository cmp = new DoctorRepository(_context))
                {
                    boDoctor = cmp.ObjectConvert <BO.Doctor, Doctor>(doctorlocationschedule.Doctor);

                    if (boDoctor != null && doctorlocationschedule.Doctor != null && doctorlocationschedule.Doctor.User != null)
                    {
                        using (UserRepository userRep = new UserRepository(_context))
                        {
                            boDoctor.user = userRep.Convert <BO.User, User>(doctorlocationschedule.Doctor.User);
                        }
                    }

                    doctorlocationscheduleBO.doctor = boDoctor;
                }
            }

            if (doctorlocationschedule.Location != null && (doctorlocationschedule.Location.IsDeleted.HasValue == false || (doctorlocationschedule.Location.IsDeleted.HasValue == true && doctorlocationschedule.Location.IsDeleted.Value == false)))
            {
                BO.Location boLocation = new BO.Location();
                using (LocationRepository cmp = new LocationRepository(_context))
                {
                    boLocation = cmp.Convert <BO.Location, Location>(doctorlocationschedule.Location);
                    doctorlocationscheduleBO.location = boLocation;
                }
            }

            if (doctorlocationschedule.Schedule != null && (doctorlocationschedule.Schedule.IsDeleted.HasValue == false || (doctorlocationschedule.Schedule.IsDeleted.HasValue == true && doctorlocationschedule.Schedule.IsDeleted.Value == false)))
            {
                BO.Schedule boSchedule = new BO.Schedule();
                using (ScheduleRepository cmp = new ScheduleRepository(_context))
                {
                    boSchedule = cmp.Convert <BO.Schedule, Schedule>(doctorlocationschedule.Schedule);
                    doctorlocationscheduleBO.schedule = boSchedule;
                }
            }

            return((T)(object)doctorlocationscheduleBO);
        }
        public override object Save <T>(T entity)
        {
            BO.DoctorLocationSchedule doctorLocationScheduleBO = (BO.DoctorLocationSchedule)(object) entity;

            DoctorLocationSchedule doctorLocationScheduleDB = new DoctorLocationSchedule();

            int?LocationId = null, DoctorId = null;

            if (doctorLocationScheduleBO.ID > 0)
            {
                doctorLocationScheduleDB = _context.DoctorLocationSchedules.Where(p => p.id == doctorLocationScheduleBO.ID).FirstOrDefault();

                if (doctorLocationScheduleDB == null)
                {
                    return(new BO.ErrorObject {
                        ErrorMessage = "Doctor,Location,Schedule record not found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }
            }

            if (doctorLocationScheduleBO.location == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Location object can't be null", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }
            else
            {
                LocationId = doctorLocationScheduleBO.location.ID;
            }

            if (doctorLocationScheduleBO.doctor == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Doctor object can't be null", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }
            else
            {
                DoctorId = doctorLocationScheduleBO.doctor.ID;
            }

            if (doctorLocationScheduleBO.schedule == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Schedule object can't be null", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }

            bool ExistsLinkage = CheckLinkage(null, LocationId, DoctorId);

            if (ExistsLinkage == false)
            {
                return(new BO.ErrorObject {
                    errorObject = "", ErrorMessage = "The Doctor does not belongs to this location.", ErrorLevel = ErrorLevel.Error
                });
            }

            #region schedule
            if (doctorLocationScheduleBO.schedule != null)
            {
                if (doctorLocationScheduleBO.schedule.ID > 0)
                {
                    Schedule schedule = _context.Schedules.Where(p => p.id == doctorLocationScheduleBO.schedule.ID).FirstOrDefault <Schedule>();
                    if (schedule != null)
                    {
                        doctorLocationScheduleDB.Schedule = schedule;
                    }
                    else
                    {
                        return new BO.ErrorObject {
                                   errorObject = "", ErrorMessage = "Please pass the valid schedule.", ErrorLevel = ErrorLevel.Error
                        }
                    };
                }
            }
            #endregion

            #region Location
            if (doctorLocationScheduleBO.location != null)
            {
                if (doctorLocationScheduleBO.location.ID > 0)
                {
                    Location location = _context.Locations.Where(p => p.id == doctorLocationScheduleBO.location.ID).FirstOrDefault <Location>();
                    if (location != null)
                    {
                        doctorLocationScheduleDB.Location = location;
                    }
                    else
                    {
                        return new BO.ErrorObject {
                                   errorObject = "", ErrorMessage = "Please pass valid location.", ErrorLevel = ErrorLevel.Error
                        }
                    };
                }
            }
            #endregion

            #region doctor
            if (doctorLocationScheduleBO.doctor != null)
            {
                if (doctorLocationScheduleBO.doctor.ID > 0)
                {
                    Doctor doctor = _context.Doctors.Where(p => p.Id == doctorLocationScheduleBO.doctor.ID).FirstOrDefault <Doctor>();
                    if (doctor != null)
                    {
                        doctorLocationScheduleDB.Doctor = doctor;
                    }
                    else
                    {
                        return new BO.ErrorObject {
                                   errorObject = "", ErrorMessage = "Please pass valid doctor.", ErrorLevel = ErrorLevel.Error
                        }
                    };
                }
            }

            #endregion

            if (doctorLocationScheduleBO.ID <= 0)
            {
                _context.DoctorLocationSchedules.Add(doctorLocationScheduleDB);
            }
            _context.SaveChanges();

            doctorLocationScheduleDB = _context.DoctorLocationSchedules.Include("Doctor").Include("Location").Include("Schedule").Where(p => p.id == doctorLocationScheduleDB.id).FirstOrDefault <DoctorLocationSchedule>();

            _context.SaveChanges();

            var res = Convert <BO.DoctorLocationSchedule, DoctorLocationSchedule>(doctorLocationScheduleDB);
            return((object)res);
        }
        public override T Convert <T, U>(U entity)
        {
            Doctor doctor = entity as Doctor;

            if (doctor == null)
            {
                return(default(T));
            }

            BO.Doctor doctorBO = new BO.Doctor();

            doctorBO.ID               = doctor.Id;
            doctorBO.LicenseNumber    = doctor.LicenseNumber;
            doctorBO.WCBAuthorization = doctor.WCBAuthorization;
            doctorBO.WcbRatingCode    = doctor.WcbRatingCode;
            doctorBO.NPI              = doctor.NPI;
            doctorBO.Title            = doctor.Title;
            doctorBO.TaxType          = (BO.GBEnums.TaxType)doctor.TaxTypeId;

            if (doctor.IsDeleted.HasValue)
            {
                doctorBO.IsDeleted = doctor.IsDeleted.Value;
            }
            if (doctor.UpdateByUserID.HasValue)
            {
                doctorBO.UpdateByUserID = doctor.UpdateByUserID.Value;
            }

            doctorBO.IsCalendarPublic = doctor.IsCalendarPublic;

            if (doctor.User != null)
            {
                if (doctor.User.IsDeleted.HasValue == false || (doctor.User.IsDeleted.HasValue == true && doctor.User.IsDeleted.Value == false))
                {
                    BO.User boUser = new BO.User();
                    using (UserRepository sr = new UserRepository(_context))
                    {
                        boUser        = sr.Convert <BO.User, User>(doctor.User);
                        doctorBO.user = boUser;
                    }

                    if (doctor.DoctorSpecialities != null)
                    {
                        List <BO.DoctorSpeciality> lstDoctorSpecility = new List <BO.DoctorSpeciality>();
                        foreach (var item in doctor.DoctorSpecialities)
                        {
                            if (item.IsDeleted == false)
                            {
                                using (DoctorSpecialityRepository sr = new DoctorSpecialityRepository(_context))
                                {
                                    lstDoctorSpecility.Add(sr.ObjectConvert <BO.DoctorSpeciality, DoctorSpeciality>(item));
                                }
                            }
                        }
                        doctorBO.DoctorSpecialities = lstDoctorSpecility;
                    }

                    if (doctor.DoctorRoomTestMappings != null)
                    {
                        List <BO.DoctorRoomTestMapping> lstDoctorRoomTestMapping = new List <BO.DoctorRoomTestMapping>();
                        foreach (var item in doctor.DoctorRoomTestMappings)
                        {
                            if (item.IsDeleted == false)
                            {
                                BO.DoctorRoomTestMapping doctorRoomTestMappingBO = new BO.DoctorRoomTestMapping();
                                doctorRoomTestMappingBO.ID        = item.Id;
                                doctorRoomTestMappingBO.IsDeleted = item.IsDeleted;
                                if (doctorRoomTestMappingBO.UpdateByUserID.HasValue)
                                {
                                    doctorRoomTestMappingBO.UpdateByUserID = item.UpdateByUserID.Value;
                                }

                                if (item.RoomTest != null && (item.RoomTest.IsDeleted.HasValue == false || (item.RoomTest.IsDeleted.HasValue == true && item.RoomTest.IsDeleted.Value == false)))
                                {
                                    BO.RoomTest boRoomTest = new BO.RoomTest();
                                    using (RoomTestRepository sr = new RoomTestRepository(_context))
                                    {
                                        boRoomTest = sr.Convert <BO.RoomTest, RoomTest>(item.RoomTest);
                                        doctorRoomTestMappingBO.RoomTest = boRoomTest;
                                    }
                                }
                                lstDoctorRoomTestMapping.Add(doctorRoomTestMappingBO);
                            }
                        }
                        doctorBO.DoctorRoomTestMappings = lstDoctorRoomTestMapping;
                    }

                    //if (doctor.User.UserCompanies != null && doctorBO.user.UserCompanies != null && doctorBO.user.UserCompanies.Count <= 0)
                    if (doctor.User.UserCompanies != null)
                    {
                        List <BO.UserCompany> lstUserCompany = new List <BO.UserCompany>();
                        foreach (var item in doctor.User.UserCompanies)
                        {
                            if (item.IsDeleted.HasValue == false || (item.IsDeleted.HasValue == true && item.IsDeleted.Value == false))
                            {
                                using (UserCompanyRepository sr = new UserCompanyRepository(_context))
                                {
                                    BO.UserCompany BOUserCompany = new BO.UserCompany();
                                    BOUserCompany      = sr.Convert <BO.UserCompany, UserCompany>(item);
                                    BOUserCompany.User = null;
                                    lstUserCompany.Add(BOUserCompany);
                                }
                            }
                        }
                        doctorBO.user.UserCompanies = lstUserCompany;
                    }

                    if (doctor.DoctorLocationSchedules != null)
                    {
                        List <BO.DoctorLocationSchedule> lstDoctorLocationSchedule = new List <BO.DoctorLocationSchedule>();
                        foreach (var item in doctor.DoctorLocationSchedules)
                        {
                            if (item.IsDeleted.HasValue == false || (item.IsDeleted.HasValue == true && item.IsDeleted.Value == false))
                            {
                                using (DoctorLocationScheduleRepository sr = new DoctorLocationScheduleRepository(_context))
                                {
                                    BO.DoctorLocationSchedule BODoctorLocationSchedule = new BO.DoctorLocationSchedule();
                                    BODoctorLocationSchedule          = sr.Convert <BO.DoctorLocationSchedule, DoctorLocationSchedule>(item);
                                    BODoctorLocationSchedule.doctor   = null;
                                    BODoctorLocationSchedule.schedule = null;
                                    lstDoctorLocationSchedule.Add(BODoctorLocationSchedule);
                                }
                            }
                        }
                        doctorBO.DoctorLocationSchedules = lstDoctorLocationSchedule;
                    }
                }
            }

            return((T)(object)doctorBO);
        }