Esempio n. 1
0
        public CYCAAdmissionBodilySearchPartiallViewModel GetIllegalItemByIllegalItemId(int Item_Found_Id)
        {
            CYCAAdmissionBodilySearchPartiallViewModel vm = new CYCAAdmissionBodilySearchPartiallViewModel();

            using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities())
            {
                try
                {
                    CYCA_Admissions_IllegalItemsFound act = db.CYCA_Admissions_IllegalItemsFound.Find(Item_Found_Id);
                    if (act != null)
                    {
                        vm.Item_Found_Id    = Item_Found_Id;
                        vm.Admission_Id     = Convert.ToInt16(act.Admission_Id);
                        vm.Quantity         = act.Quantity;
                        vm.Handed_By        = act.Handed_By;
                        vm.Document_Type_Id = act.Document_Type_Id;
                        vm.Description      = act.Description;
                    }

                    //CYCA_BodilySearch_Document bsd = db.CYCA_BodilySearch_Document.Find(BodySearchId);

                    //var docL = db.CYCA_BodilySearch_Document.ToList();

                    //if (bsd != null)
                    //{
                    //    foreach (var item in docL)
                    //    {
                    //        vm.BodySearchId = BodySearchId;
                    //        vm.DocumentId = bsd.Document_Id;
                    //        vm.DocumentName = bsd.Document_Name;
                    //    }

                    //}
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
            }
            return(vm);
        }
Esempio n. 2
0
        public CYCAAdmissionBodilySearchPartiallViewModel GetBodySearchByBodySearchId(int BodySearchId)
        {
            CYCAAdmissionBodilySearchPartiallViewModel vm = new CYCAAdmissionBodilySearchPartiallViewModel();

            using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities())
            {
                try
                {
                    CYCA_BodilySearch act = db.CYCA_BodilySearch.Find(BodySearchId);
                    if (act != null)
                    {
                        vm.BodySearchId     = BodySearchId;
                        vm.Admission_Id     = Convert.ToInt16(act.Admission_Id);
                        vm.BodySearchDate   = act.Bodily_Search_Date.ToString();
                        vm.Search_Reason_Id = act.Search_Reason_Id;
                        vm.ReasonForSearch  = db.apl_Cyca_Bodily_Search_Reasons.Find(act.Search_Reason_Id).Description;
                        vm.Conducted_By     = act.Conducted_By;
                        vm.ConductedBy      = db.Users.Find(act.Conducted_By).First_Name + " " + db.Users.Find(act.Conducted_By).Last_Name;
                        vm.Witnessed_By     = act.Witnessed_By;
                        vm.WitnessedBy      = db.Users.Find(act.Witnessed_By).First_Name + " " + db.Users.Find(act.Witnessed_By).Last_Name;
                        vm.Document_Type_Id = act.Document_Type_Id;
                        vm.Description      = act.Description;
                        vm.saveBodySearchId = BodySearchId;
                    }

                    CYCA_BodilySearch_Document bsd = db.CYCA_BodilySearch_Document.Find(BodySearchId);
                    var bs = db.CYCA_BodilySearch_Document.Find(BodySearchId);

                    var docL = db.CYCA_BodilySearch_Document.ToList();

                    //if (bsd != null)
                    //{
                    foreach (var item in docL)
                    {
                        if (item.Bodily_Search_Id == BodySearchId)
                        {
                            vm.saveBodySearchId = BodySearchId;
                            vm.BodySearchId     = BodySearchId;
                            vm.DocumentId       = item.Document_Id;
                            vm.DocumentName     = item.Document_Name;
                        }
                    }

                    //}
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
            }
            return(vm);
        }