コード例 #1
0
ファイル: DoctorModel.cs プロジェクト: gvhung/hospital-finder
        public static bool UpdateDoctor(DoctorModel model)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                using (LinqDBDataContext data = new LinqDBDataContext())
                {
                    string workingDay = "";
                    foreach (int wd in model.WorkingDay)
                    {
                        workingDay = workingDay + wd + ',';
                    }
                    if (workingDay.Length > 0)
                    {
                        workingDay = workingDay.Substring(0, workingDay.Length - 1);
                    }
                    Doctor doctor = (from d in data.Doctors
                                     where d.Doctor_ID == model.DoctorID
                                     select d).SingleOrDefault();
                    if (doctor != null)
                    {
                        doctor.First_Name  = model.FirstName;
                        doctor.Last_Name   = model.LastName;
                        doctor.Gender      = model.Gender == 1 ? true : false;
                        doctor.Degree      = model.Degree;
                        doctor.Experience  = model.Experience;
                        doctor.Working_Day = string.IsNullOrEmpty(workingDay) ? null : workingDay;
                        doctor.Is_Active   = true;
                        data.SubmitChanges();


                        var dsList = (from ds in data.Doctor_Specialities
                                      where ds.Doctor_ID == doctor.Doctor_ID
                                      select ds);
                        data.Doctor_Specialities.DeleteAllOnSubmit(dsList);
                        data.SubmitChanges();

                        foreach (int specilityId in model.SpecialityList)
                        {
                            Doctor_Speciality ds = new Doctor_Speciality()
                            {
                                Doctor_ID     = doctor.Doctor_ID,
                                Speciality_ID = specilityId,
                                Is_Active     = true
                            };
                            data.Doctor_Specialities.InsertOnSubmit(ds);
                            data.SubmitChanges();
                        }

                        if (!string.IsNullOrEmpty(model.PhotoFilePath))
                        {
                            Photo photo = (from p in data.Photos
                                           where p.Doctor_ID == doctor.Doctor_ID
                                           select p).SingleOrDefault();
                            if (photo != null)
                            {
                                photo.File_Path       = model.PhotoFilePath;
                                photo.Uploaded_Person = model.UploadedPerson;
                                data.SubmitChanges();
                            }
                            else
                            {
                                Photo newPhoto = new Photo()
                                {
                                    File_Path       = model.PhotoFilePath,
                                    Caption         = model.LastName + " " + model.FirstName,
                                    Add_Date        = DateTime.Now,
                                    Doctor_ID       = doctor.Doctor_ID,
                                    Uploaded_Person = model.UploadedPerson,
                                    Is_Active       = true
                                };

                                data.Photos.InsertOnSubmit(newPhoto);
                                data.SubmitChanges();
                            }
                        }
                    }

                    ts.Complete();
                }
            }
            return(true);
        }
コード例 #2
0
ファイル: DoctorModel.cs プロジェクト: gvhung/hospital-finder
        public static bool InsertDoctor(DoctorModel model)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                using (LinqDBDataContext data = new LinqDBDataContext())
                {
                    string workingDay = "";
                    foreach (int wd in model.WorkingDay)
                    {
                        workingDay = workingDay + wd + ',';
                    }
                    if (workingDay.Length > 0)
                    {
                        workingDay = workingDay.Substring(0, workingDay.Length - 1);
                    }
                    Doctor doctor = new Doctor()
                    {
                        First_Name  = model.FirstName,
                        Last_Name   = model.LastName,
                        Gender      = model.Gender == 1 ? true : false,
                        Degree      = model.Degree,
                        Experience  = model.Experience,
                        Working_Day = string.IsNullOrEmpty(workingDay) ? null : workingDay,
                        Is_Active   = true
                    };
                    data.Doctors.InsertOnSubmit(doctor);
                    data.SubmitChanges();

                    if (!string.IsNullOrEmpty(model.PhotoFilePath))
                    {
                        Photo photo = new Photo()
                        {
                            File_Path       = model.PhotoFilePath,
                            Caption         = model.LastName + " " + model.FirstName,
                            Add_Date        = DateTime.Now,
                            Doctor_ID       = doctor.Doctor_ID,
                            Uploaded_Person = model.UploadedPerson,
                            Is_Active       = true
                        };

                        data.Photos.InsertOnSubmit(photo);
                        data.SubmitChanges();
                    }

                    foreach (int specilityId in model.SpecialityList)
                    {
                        Doctor_Speciality ds = new Doctor_Speciality()
                        {
                            Doctor_ID     = doctor.Doctor_ID,
                            Speciality_ID = specilityId,
                            Is_Active     = true
                        };
                        data.Doctor_Specialities.InsertOnSubmit(ds);
                        data.SubmitChanges();
                    }
                    Doctor_Hospital dh = new Doctor_Hospital()
                    {
                        Doctor_ID   = doctor.Doctor_ID,
                        Hospital_ID = model.HospitalID,
                        Is_Active   = true
                    };
                    data.Doctor_Hospitals.InsertOnSubmit(dh);
                    data.SubmitChanges();
                    ts.Complete();
                }
            }
            return(true);
        }