Exemplo n.º 1
0
        public ActionResult AddPatient(string empID, string Name, string SurName, string CPRno, string Password, string RPassword, string DDLLevel, string DeviceSelection)
        {
            if (Password == RPassword)
            {
                //try
                //{


                if (DDLLevel == "Klinikker")
                {
                    string   Hash = HomeController.HashPassword(Password);
                    Employee E    = new Employee {
                        FirstName = Name, SurName = SurName, CPRno = int.Parse(CPRno), Password = Hash.ToString()
                    };
                    DB.Employee.Add(E);
                    DB.SaveChanges();
                    Response.Write("<script>alert('Klinikeren er tilføjet');</script>");
                    return(View());
                }
                else if (DDLLevel == "Patient")
                {
                    string  Hash = HomeController.HashPassword(Password);
                    Patient P    = new Patient {
                        ForName = Name, SurName = SurName, CPRno = int.Parse(CPRno), Password = Hash.ToString()
                    };

                    //Device getdevice = DB.Device.First(p => p.ID == DeviceSelection);
                    //getdevice.PatientID = 123;
                    //DB.Entry(getdevice).State = System.Data.Entity.EntityState.Modified;

                    DB.Patient.Add(P);
                    DB.SaveChanges();

                    int newPersonID = P.ID;

                    using (var context = new Gnusys.Models.GnysusEFModel())
                    {
                        context.Database.ExecuteSqlCommand("INSERT INTO EmployeePatients(EmployeeID, PatientID) VALUES(" + empID + ", " + newPersonID + ")");
                    }

                    using (var context = new Gnusys.Models.GnysusEFModel())
                    {
                        context.Database.ExecuteSqlCommand("UPDATE Device SET PatientID = " + newPersonID + " WHERE ID = '" + DeviceSelection + "'");
                    }



                    Response.Write("<script>alert('Patient er tilføjet');</script>");
                    return(View());
                }
                else
                {
                    return(View());
                }
                //}
                //catch
                //{
                //    Response.Write("<script>alert('Fejl, tjek om alle felter er udfyldt korrekt');</script>");
                //}
            }
            else
            {
                return(View());
            }
            //return View();
        }