private DoctorViewModel RefreshDoctor()
 {
     DoctorViewModel model = new DoctorViewModel();
     model.FieldId = "doctorName";
     model.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE);
     var entities = _bdmSvc.GetViewOfAllEntities(AppConstants.SITE_CODE);
     model.Doctors = entities.Where(m => m.EntityTypeCode == EntityTypes.DOC.ToString()).ToList();
     model.Managers = entities.Where(m => m.EntityTypeCode == EntityTypes.MGR.ToString()).ToList();
     //foreach (var mgr in model.Managers)
     //    mgr.ParentEntityID = mgr.ID;
     return model;
 }
 public DoctorViewModel GetDoctorById(decimal doctorId)
 {
     DoctorViewModel mod = new DoctorViewModel();
     try
     {
         //mod.Doctor = _bdmSvc.GetEntityById(AppConstants.SITE_CODE, doctorId);
         //if (mod.Doctor.Addresses.Count > 0)
         //    mod.Address = mod.Doctor.Addresses[0];
         //if (mod.Doctor.Contacts.Count > 0)
         //    mod.Contact = mod.Doctor.Contacts[0];
     }
     catch (Exception ex)
     {
         mod.TranslateException(ex);
     }
     return mod;
 }
        public DoctorViewModel ModifyDoctor(DoctorViewModel model)
        {
            try
            {
                DBOperations op = model.IsActive ? DBOperations.Update : DBOperations.Delete;
                model.Doctor.SiteCode = AppConstants.SITE_CODE;
                if (model.IsActive)
                {
                    model.IsValid = model.Validate();
                    if (model.IsValid)
                    {
                        //model.Address = base.TranslateNames(model.Address);
                        //var mgr = _bdmSvc.GetEntityById(AppConstants.SITE_CODE, decimal.Zero); // model.Doctor.ParentEntityID);
                        //if (mgr != null && mgr.Addresses.Count > 0)
                        //{
                        //    var src = mgr.Addresses[0];
                        //    AddressDE dest = model.Address;
                        //    Translate(src, ref dest);
                        //}

                        //if (model.Doctor.Addresses.Count > 0)
                        //    model.Doctor.Addresses[0] = model.Address.Translate(model.Doctor.Addresses[0]);

                        //if (model.Doctor.Contacts.Count > 0)
                        //    model.Doctor.Contacts[0] = model.Contact.Translate(model.Doctor.Contacts[0]);

                        _bdmSvc.ModifyEntity(model.Doctor);
                    }
                }
                else
                {
                    model.Doctor.IsActive = false;
                    _bdmSvc.ModifyEntity(model.Doctor);
                }

                model = RefreshDoctor();
                model.Message = op == DBOperations.Update ? string.Format(AppConstants.CRUD_UPDATE, "Doctor") : string.Format(AppConstants.CRUD_DELETE, "Doctor");
            }
            catch (Exception ex)
            {
                model.TranslateException(ex);
                if (ex.Message.Contains("Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions."))
                    model.Message = "Unable to modify Region Code";
            }

            return model;
        }
        public DoctorViewModel AddDoctor(DoctorViewModel model)
        {
            try
            {
                model.IsValid = model.Validate();
                if (model.IsValid)
                {
                    model.Doctor.SiteCode = AppConstants.SITE_CODE;
                    //var mgr = _bdmSvc.GetEntityById(AppConstants.SITE_CODE, decimal.Zero); // model.Doctor.ParentEntityID);
                    //if (mgr != null && mgr.Addresses.Count > 0)
                    //{
                    //    var src = mgr.Addresses[0];
                    //    AddressDE dest = model.Address;
                    //    Translate(src, ref dest);
                    //}

                    //model.Doctor.Addresses.Add(model.Address);
                    //model.Doctor.Contacts.Add(model.Contact);
                    //_bdmSvc.AddEntity(model.Doctor);

                    //model = RefreshDoctor();
                    //model.Message = string.Format(AppConstants.CRUD_CREATE, "Doctor");
                }
            }
            catch (Exception ex)
            {
                model.TranslateException(ex);
            }

            return model;
        }