コード例 #1
0
        public bool UpdateMedicalSpecialist(int id, [FromBody] CreateSpecialistCommand request)
        {
            SpecialistContext       context = HttpContext.RequestServices.GetService(typeof(SpecialistContext)) as SpecialistContext;
            UpdateSpecialistHandler handler = new UpdateSpecialistHandler(context);

            return(handler.Handle(id, request));
        }
        public bool Handle(CreateSpecialistCommand request)
        {
            var    model    = request.Adapt <MedicalSpecialist>();
            string tempHash = Hash.FindHash(model.PasswordHash);

            model.PasswordHash = tempHash;

            using (MySqlConnection conn = _context.GetConnection())
            {
                conn.Open();
                string query = string.Format("insert into Specialists(last_name, first_name, middle_name, email, password_hash, Health_Facilities_faculty_id) values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')",
                                             model.LastName, model.FirstName, model.MiddleName,
                                             model.Email, model.PasswordHash, model.HealthFacilitiesFacultyId);
                MySqlCommand cmd = new MySqlCommand(query, conn);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    return(false);
                }
                finally
                {
                    conn.CloseAsync();
                }
            }

            return(true);
        }
        public bool Handle(CreateSpecialistCommand request)
        {
            var    model    = request.Adapt <Model.Specialist>();
            string tempHash = Hash.FindHash(model.PasswordHash);

            model.PasswordHash = tempHash;

            using (MySqlConnection conn = _context.GetConnection())
            {
                conn.Open();
                string query = string.Format("INSERT INTO specialists(last_name, first_name, middle_name, " +
                                             "email, password_hash, birthday, education, position, " +
                                             "admission_date, dismissal_date, wage_rate, " +
                                             "Subunits_subunit_id, Units_unit_id, Parlours_parlour_id) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}')",
                                             model.LastName,
                                             model.FirstName,
                                             model.MiddleName,
                                             model.Email,
                                             model.PasswordHash,
                                             model.Birthday.ToString("yyyy-MM-dd HH:mm:ss"),
                                             model.Education,
                                             model.Position,
                                             model.AdmissionDate.ToString("yyyy-MM-dd HH:mm:ss"),
                                             model.DismissalDate.ToString("yyyy-MM-dd HH:mm:ss"),
                                             model.WageRate.ToString(),
                                             model.SubunitId.ToString(),
                                             model.UnitId.ToString(),
                                             model.ParlourId.ToString());
                MySqlCommand cmd = new MySqlCommand(query, conn);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    return(false);
                }
                finally
                {
                    conn.CloseAsync();
                }
            }

            return(true);
        }
        public bool Handle(int specialistId, CreateSpecialistCommand request)
        {
            var model = request.Adapt <Model.MedicalSpecialist>();

            using (MySqlConnection conn = _context.GetConnection())
            {
                conn.Open();

                string query = string.Format("update specialists set `last_name`='{1}', `first_name`='{2}', `middle_name`='{3}'," +
                                             "`email`='{4}', `password_hash`='{5}', `Health_Facilities_faculty_id`={6} where `specialist_id`={0}",
                                             specialistId.ToString(),
                                             model.LastName,
                                             model.FirstName,
                                             model.MiddleName,
                                             model.Email,
                                             model.PasswordHash,
                                             model.HealthFacilitiesFacultyId);

                MySqlCommand cmd = new MySqlCommand(query, conn);

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                    return(false);
                }
                finally
                {
                    conn.CloseAsync();
                }
            }

            return(true);
        }
コード例 #5
0
        public void UpdateCourseTest()
        {
            // arrange
            List <MedicalSpecialist> list = new List <MedicalSpecialist>();
            int id = 1;

            MedicalSpecialist expected = new MedicalSpecialist
            {
                LastName     = "lastname",
                FirstName    = "name",
                MiddleName   = "middlename",
                Email        = "*****@*****.**",
                PasswordHash = "password",
                HealthFacilitiesFacultyId = 1,
            };

            CreateSpecialistCommand command = new CreateSpecialistCommand
            {
                LastName     = "newlastname",
                FirstName    = "newname",
                MiddleName   = "newmiddlename",
                Email        = "*****@*****.**",
                PasswordHash = "password",
                HealthFacilitiesFacultyId = 1,
            };

            //act
            SpecialistContext       courseContext       = new SpecialistContext(connString);
            UpdateSpecialistHandler createCourseHandler = new UpdateSpecialistHandler(courseContext);

            createCourseHandler.Handle(id, command);


            using (conn = new MySqlConnection(connString))
            {
                conn.Open();
                string query = string.Format("select * from specialists where email='*****@*****.**' and last_name='newlastname'");

                MySqlCommand cmd = new MySqlCommand(query, conn);

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(new MedicalSpecialist()
                        {
                            Id         = Convert.ToInt32(reader["specialist_id"]),
                            LastName   = reader["last_name"].ToString(),
                            FirstName  = reader["first_name"].ToString(),
                            MiddleName = reader["middle_name"].ToString(),
                            Email      = reader["email"].ToString(),
                            HealthFacilitiesFacultyId = Convert.ToInt32(reader["Health_Facilities_faculty_id"]),
                        });
                    }
                }
            }

            if (list[0].HealthFacilitiesFacultyId == expected.HealthFacilitiesFacultyId &&
                list[0].LastName == expected.LastName && list[0].Email == expected.Email)
            {
                Assert.IsTrue(true);
            }
        }
コード例 #6
0
        public async Task <ActionResult> CreateSpecialist([FromBody] CreateSpecialistCommand command)
        {
            var patient = await Mediator.Send(command);

            return(CreatedAtAction("GetSpecialist", new { id = patient.Id }, patient));
        }