Ejemplo n.º 1
0
        public async Task <IActionResult> EditAccountInfoAsync(string id, ProfessionalViewModel model)
        {
            ProfessionalViewModel newModel = new ProfessionalViewModel();
            ProfessionalModel     newProf  = new ProfessionalModel();

            newProf.Title    = model.Professional.Title;
            newProf.Location = model.Professional.Location;
            newProf.AppointmentLengthInHours = model.Professional.AppointmentLengthInHours;
            newProf.HourlyRate = model.Professional.HourlyRate;
            newProf.Language   = model.Professional.Language;
            newProf.Bio        = model.Professional.Bio;
            newProf.Username   = id;

            newModel.Professional        = newProf;
            newModel.Professional.Rating = model.Professional.Rating;
            newModel.Username            = id;

            HttpClientHandler clientHandler = new HttpClientHandler();
            var           json    = JsonConvert.SerializeObject(newProf);
            StringContent content = new StringContent(json.ToString());

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };
            HttpClient client   = new HttpClient(clientHandler);
            var        response = await client.PutAsync(apiUrl + apiProfessionalController + "/UpdateProfessional", content);

            return(View("ProfessionalAccountView", newModel));
        }
Ejemplo n.º 2
0
        public void Test_ProfessionalModelExists()
        {
            var sut = new ProfessionalModel();
            ProfessionalModel sut1 = new ProfessionalModel();

            var actual = sut;

            Assert.IsType <ProfessionalModel>(actual);
            Assert.NotNull(actual);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get all Masterclasss in a list
        /// </summary>
        /// <returns>List with Players</returns>
        public ProfessionalModel GetProfessional(int professionalId)
        {
            ProfessionalModel professional = null;

            try
            {
                this.Connection.Open();

                string          query  = $@"SELECT * FROM professional LEFT JOIN person ON professional.id = person.id WHERE professional.id = { professionalId }";
                MySqlCommand    cmd    = new MySqlCommand(query, this.Connection);
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    professional = new ProfessionalModel
                    {
                        Id          = reader.GetInt32("id"),
                        BirthDate   = reader.GetDateTime("birth_date"),
                        FirstName   = reader.GetString("first_name"),
                        MiddleName  = reader["middle_name"] == DBNull.Value ? string.Empty : reader.GetString("middle_name"),
                        LastName    = reader.GetString("last_name"),
                        Gender      = reader.GetChar("gender"),
                        Nationality = reader.GetString("nationality")
                    };
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Fetching professionals failed. " + e.Message);
                MessageBox.Show("Professionals ophalen is mislukt.");
            }
            finally
            {
                this.Connection.Close();
            }

            if (professional != null)
            {
                professional.Emails       = this.GetEmails(professional.Id);
                professional.PhoneNumbers = this.GetPhoneNumbers(professional.Id);
            }

            return(professional);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> GetListPatient(ProfessionalModel professionalModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var professionalPatiens = context.Professional.Where(u => u.Id == professionalModel.IdProfessional).Select(p => p.Patients).ToList().FirstOrDefault();
                    var patients            = professionalPatiens.Select(p => p);


                    return(Ok(patients.ToArray()));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(Ok(false));
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> SetPatient(ProfessionalModel professionalModel)
        {
            using (var context = new MegaHackContext())
            {
                try
                {
                    var patient      = context.Patient.Where(u => u.Id == professionalModel.IdPatient).First();
                    var professional = context.Professional.Where(u => u.Id == professionalModel.IdProfessional).First();

                    professional.Patients.Add(patient);

                    await context.SaveChangesAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(Ok(false));
                }
            }
        }
Ejemplo n.º 6
0
        public void InsertProfessional(ProfessionalModel professional)
        {
            MySqlTransaction trans = null;

            try
            {
                this.Connection.Open();
                trans = this.Connection.BeginTransaction();

                const string InsertString =
                    @"insert into professional(id, nationality) value (LAST_INSERT_ID(), @nationality)";
                MySqlCommand command =
                    new MySqlCommand(InsertString, this.Connection)
                {
                    Parameters =
                    {
                        new MySqlParameter("@nationality", MySqlDbType.VarChar)
                        {
                            Value = professional.Nationality
                        }
                    }
                };

                command.Prepare();
                command.ExecuteNonQuery();
                trans.Commit();
            }
            catch (Exception e)
            {
                trans?.Rollback();
                Console.WriteLine("Adding professional failed. " + e.Message);
                MessageBox.Show("Professional toevoegen is mislukt.");
            }
            finally
            {
                this.Connection.Close();
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> CreateAccountProfessional(ProfessionalModel model)
        {
            //Serializing the model and converting it into a string
            model.MemberSince = DateTime.Now;
            model.Rating      = 5;
            var           json    = JsonConvert.SerializeObject(model);
            StringContent content = new StringContent(json.ToString());

            //Creating a HTTP handler to bypass SSL cert checks
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            //creating httpclient that uses the handler
            HttpClient client = new HttpClient(clientHandler);

            //Passing the serialized object to the API
            var response = await client.PostAsync(apiUrl + loginController + "/CreateAccountProfessional", content);

            /*
             * Getting an object back from the api,
             * The api is going to search its database for a user with the credentials that we sent
             * and send us back a user based on its search
             */
            //UserModel user = JsonConvert.DeserializeObject<UserModel>(await response.Content.ReadAsStringAsync());

            LoginViewModel modelForm = new LoginViewModel();

            if (response.IsSuccessStatusCode)
            {
                return(View("FormLogin", modelForm));
            }

            modelForm.Error = "Could Not Create Account!";
            return(View("FormLogin", modelForm));
        }
Ejemplo n.º 8
0
        public bool CreateProfessional(ProfessionalModel professional)
        {
            MySqlTransaction trans = null;
            bool             success;

            try
            {
                this.Connection.Open();
                trans = this.Connection.BeginTransaction();

                string middleName = professional.MiddleName == "" ? null : professional.MiddleName;

                const string InsertString =
                    @"insert into person (first_name, middle_name, last_name, gender, birth_date) values (@first_name, @middle_name, @last_name, @gender, @birth_date);";
                MySqlCommand command =
                    new MySqlCommand(InsertString, this.Connection)
                {
                    Parameters =
                    {
                        new MySqlParameter("@first_name", MySqlDbType.VarChar)
                        {
                            Value = professional.FirstName
                        },
                        new MySqlParameter("@birth_date", MySqlDbType.DateTime)
                        {
                            Value = professional.BirthDate
                        },
                        new MySqlParameter("@last_name", MySqlDbType.VarChar)
                        {
                            Value = professional.LastName
                        },
                        new MySqlParameter("@middle_name", MySqlDbType.VarChar)
                        {
                            Value = middleName
                        },
                        new MySqlParameter("@gender", MySqlDbType.VarChar)
                        {
                            Value = professional.Gender
                        }
                    }
                };

                command.Prepare();
                command.ExecuteNonQuery();
                trans.Commit();
                success = true;
            }
            catch (Exception e)
            {
                success = false;
                trans?.Rollback();
                Console.WriteLine("Adding person failed. " + e.Message);
                MessageBox.Show("Persoon toevoegen is mislukt.");
            }
            finally
            {
                this.Connection.Close();
            }

            this.InsertProfessional(professional);

            return(success);
        }
Ejemplo n.º 9
0
        public IActionResult AccountCreationProfessional()
        {
            ProfessionalModel accountModel = new ProfessionalModel();

            return(View("AccountCreationProfessional", accountModel));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> SetAppointment(AppointmentViewModel model)
        {
            //Find the professional
            HttpClientHandler professionalclientHandler = new HttpClientHandler();

            professionalclientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };
            HttpClient professionalclient   = new HttpClient(professionalclientHandler);
            var        professionalresponse = await professionalclient.GetAsync(apiUrl + apiProfessionalController + "/GetOneByUsername/" + model.ProfessionalUsername);

            ProfessionalModel professional = JsonConvert.DeserializeObject <ProfessionalModel>(await professionalresponse.Content.ReadAsStringAsync());
            //Parse Datetimepicker
            AppointmentModel appointment = new AppointmentModel();

            string      format   = "MM/dd/yyyy h:mm tt";
            CultureInfo provider = CultureInfo.InvariantCulture;

            try
            {
                if (model.StartTime == null)
                {
                    ViewBag.Error = ("Appointment Time Must not be Empty");
                    return(View("CreateAppointment", model));
                }
                DateTime startTime = DateTime.ParseExact(model.StartTime.Trim(), format, provider);
                if (startTime < DateTime.Now)
                {
                    ViewBag.Error = ("Appointment Time Cannot be in the past");
                    return(View("CreateAppointment", model));
                }
                appointment.Time       = new TimeModel();
                appointment.Time.Start = startTime;
                appointment.Time.End   = startTime.AddHours(professional.AppointmentLengthInHours);
            }
            catch (FormatException)
            {
            }

            appointment.IsFufilled   = false;
            appointment.Professional = professional;
            appointment.EntityID     = DateTime.Now.Ticks;


            //Serializing the model and converting it into a string
            var           json    = JsonConvert.SerializeObject(appointment.Time);
            StringContent content = new StringContent(json.ToString());
            //Creating a HTTP handler to bypass SSL cert checks
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            //creating httpclient that uses the handler
            HttpClient client = new HttpClient(clientHandler);

            //Passing the serialized object to the API
            var response = await client.PostAsync(apiUrl + "Appointment" + "/Post/" + model.CustomerUsername + "/" + model.ProfessionalUsername, content); //this is where it's breaking

            CustomerViewModel customerView = new CustomerViewModel();

            customerView.Username = model.CustomerUsername;

            AppointmentViewModel appointmentModel = new AppointmentViewModel();

            appointmentModel.ProfessionalUsername = model.ProfessionalUsername;
            appointmentModel.CustomerUsername     = model.CustomerUsername;

            //Return to success page
            return(View("AppointmentCompletion", appointmentModel));
        }