private async void ExecuteDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                using (me = new MedicalModel(ConfigurationManager.Connect()))
                {
                    await me.Database.Connection.OpenAsync();

                    foreach (DocumentControlM.ListElement item in EditEvidenceM.EvidenceList)
                    {
                        if (item.DBId != null)
                        {
                            evidencedatadocuments edd = me.evidencedatadocuments.Where(ed => ed.IdEDD == item.DBId).Single();
                            edd.DataEDD     = edd.DataEDD != item.File.ToArray() ? item.File.ToArray() : edd.DataEDD;
                            edd.FileTypeEDD = edd.FileTypeEDD != item.FileType ? item.FileType : edd.FileTypeEDD;
                        }
                        else if (item.File != null)
                        {
                            evidencedatadocuments ed = new evidencedatadocuments()
                            {
                                DataEDD     = item.File.ToArray(),
                                TypeEDD     = item.ButtonType,
                                FileTypeEDD = item.FileType
                            };

                            me.evidencedatadocuments.Add(ed);
                            await me.SaveChangesAsync();

                            int ide = ed.IdEDD;

                            if (EditEvidenceM.Imported)
                            {
                                me.importedevidencedatadocuments_st.Add(new importedevidencedatadocuments_st()
                                {
                                    IdIED = EditEvidenceM.Id,
                                    IdEDD = ide
                                });
                                await me.SaveChangesAsync();
                            }
                            else
                            {
                                me.evidencedatadocuments_st.Add(new evidencedatadocuments_st()
                                {
                                    IdED  = EditEvidenceM.Id,
                                    IdEDD = ide
                                });
                                await me.SaveChangesAsync();
                            }
                        }
                        await me.SaveChangesAsync();
                    }

                    foreach (int id in DocumentControlVM.Erased())
                    {
                        if (EditEvidenceM.Imported)
                        {
                            me.importedevidencedatadocuments_st.Remove
                                (me.importedevidencedatadocuments_st.Where(ex => ex.IdEDD == id).Single());
                        }

                        else
                        {
                            me.evidencedatadocuments_st.Remove
                                (me.evidencedatadocuments_st.Where(ex => ex.IdEDD == id).Single());
                        }

                        me.evidencedatadocuments.Remove
                            (me.evidencedatadocuments.Where(ex => ex.IdEDD == id).Single());

                        await me.SaveChangesAsync();
                    }

                    foreach (EmptyComboBoxEditM.ErasedItem erased in GetErased())
                    {
                        if (EditEvidenceM.Imported)
                        {
                            if (erased.Imported)
                            {
                                me.importedexaminationeachimportedevidence_st.Remove(
                                    me.importedexaminationeachimportedevidence_st.Where(ieeie => ieeie.IdIEX == erased.Id).FirstOrDefault());
                            }
                            else
                            {
                                me.examinationeachimportedevidence_st.Remove(
                                    me.examinationeachimportedevidence_st.Where(eeie => eeie.IdEX == erased.Id).FirstOrDefault());
                            }
                        }
                        else if (erased.Imported)
                        {
                            me.importedexaminationeachevidence_st.Remove(
                                me.importedexaminationeachevidence_st.Where(ieee => ieee.IdIEX == erased.Id).FirstOrDefault());
                        }
                        else
                        {
                            me.examinationeachevidence_st.Remove(
                                me.examinationeachevidence_st.Where(eee => eee.IdEX == erased.Id).FirstOrDefault());
                        }
                        await me.SaveChangesAsync();
                    }

                    foreach (SelectedPatientM.ExaminationItem exist in GetList())
                    {
                        if (EditEvidenceM.Imported)
                        {
                            if (exist.Imported)
                            {
                                if (!me.importedexaminationeachimportedevidence_st.Any(ieeie => ieeie.IdIEX == exist.Id))
                                {
                                    me.importedexaminationeachimportedevidence_st.Add(new importedexaminationeachimportedevidence_st()
                                    {
                                        IdIEX = exist.Id,
                                        IdIED = EditEvidenceM.Id
                                    });
                                }
                            }
                            else
                            {
                                if (!me.examinationeachimportedevidence_st.Any(eeie => eeie.IdEX == exist.Id))
                                {
                                    me.examinationeachimportedevidence_st.Add(new examinationeachimportedevidence_st()
                                    {
                                        IdEX  = exist.Id,
                                        IdIED = EditEvidenceM.Id
                                    });
                                }
                            }
                        }
                        else
                        {
                            if (exist.Imported)
                            {
                                if (!me.importedexaminationeachevidence_st.Any(ieee => ieee.IdIEX == exist.Id))
                                {
                                    me.importedexaminationeachevidence_st.Add(new importedexaminationeachevidence_st()
                                    {
                                        IdIEX = exist.Id,
                                        IdED  = EditEvidenceM.Id
                                    });
                                }
                            }
                            else
                            {
                                if (!me.examinationeachevidence_st.Any(eee => eee.IdEX == exist.Id))
                                {
                                    me.examinationeachevidence_st.Add(new examinationeachevidence_st()
                                    {
                                        IdEX = exist.Id,
                                        IdED = EditEvidenceM.Id
                                    });
                                }
                            }
                        }
                        await me.SaveChangesAsync();
                    }
                }
                workingConn = true;
            }
            catch (Exception ex)
            {
                Log.WriteException(ex);
                workingConn = false;
            }
        }
Example #2
0
        private async void ExecuteDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                using (me = new MedicalModel(ConfigurationManager.Connect()))
                {
                    await me.Database.Connection.OpenAsync();

                    foreach (DocumentControlM.ListElement item in ExaminationEditM.ExaminationList)
                    {
                        if (item.DBId != null)
                        {
                            examinationdatadocuments edd = me.examinationdatadocuments.Where(ed => ed.IdEXD == item.DBId).Single();
                            edd.DataEXD     = edd.DataEXD != item.File.ToArray() ? item.File.ToArray() : edd.DataEXD;
                            edd.FileTypeEXD = edd.FileTypeEXD != item.FileType ? item.FileType : edd.FileTypeEXD;
                        }
                        else if (item.File != null)
                        {
                            examinationdatadocuments ed = new examinationdatadocuments()
                            {
                                DataEXD     = item.File.ToArray(),
                                TypeEXD     = item.ButtonType,
                                FileTypeEXD = item.FileType
                            };

                            me.examinationdatadocuments.Add(ed);
                            await me.SaveChangesAsync();

                            int ide = ed.IdEXD;

                            if (ExaminationEditM.Imported)
                            {
                                me.importedexaminationdatadocuments_st.Add(new importedexaminationdatadocuments_st()
                                {
                                    IdIEX = ExaminationEditM.Id,
                                    IdEXD = ide
                                });
                                await me.SaveChangesAsync();
                            }
                            else
                            {
                                me.examinationdatadocuments_st.Add(new examinationdatadocuments_st()
                                {
                                    IdEX  = ExaminationEditM.Id,
                                    IdEXD = ide
                                });
                                await me.SaveChangesAsync();
                            }
                        }
                        await me.SaveChangesAsync();
                    }

                    foreach (int id in DocumentControlVM.Erased())
                    {
                        if (ExaminationEditM.Imported)
                        {
                            me.importedexaminationdatadocuments_st.Remove
                                (me.importedexaminationdatadocuments_st.Where(ex => ex.IdEXD == id).Single());
                        }

                        else
                        {
                            me.examinationdatadocuments_st.Remove
                                (me.examinationdatadocuments_st.Where(ex => ex.IdEXD == id).Single());
                        }

                        me.examinationdatadocuments.Remove
                            (me.examinationdatadocuments.Where(ex => ex.IdEXD == id).Single());

                        await me.SaveChangesAsync();
                    }
                }
                workingConn = true;
            }
            catch (Exception ex)
            {
                Log.WriteException(ex);
                workingConn = false;
            }
        }