Ejemplo n.º 1
0
        private void BtnAddStudent_Click(object sender, EventArgs e)
        {
            var selectedcourse      = listBox1.CheckedItems;
            var properties          = selectedcourse.GetType().GetProperties();
            AddEditStudentDto model = new AddEditStudentDto();

            model.Courses = new List <int>();
            foreach (var item in listBox1.CheckedItems)
            {
                model.Courses.Add(Convert.ToInt32(item.GetType().GetProperty("CourseId").GetValue(item, null)));
            }
            model.ImageUrl        = txtImageUrl.Text;
            model.Name            = TxtName.Text;
            model.FName           = TxtFName.Text;
            model.Email           = TxtEmail.Text;
            model.Phone           = TxtStudentPhone.Text;
            model.Password        = TxtPassword.Text;
            model.ConfirmPassword = TxtConfirmPassword.Text;
            model.Dob             = DtpStudetDob.Text.ToString();
            model.UserId          = USER_ID;
            _StudentRepo.AddStudent(model);
            RefreshStudentTable();
            MessageBox.Show("Student Added Successfully");
            RefreshStudentForm();
        }
Ejemplo n.º 2
0
 public bool AddStudentByProcedure(AddEditStudentDto s)
 {
     try
     {
         var id = Convert.ToInt32(context.AddStudent(s.Name, s.FName, s.Phone, s.Email, s.Dob, s.Password, s.ConfirmPassword));
         context.AddCourses(id, s.Courses);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        public bool UpdateStudent(AddEditStudentDto stdPost)
        {
            try
            {
                //update first Student
                Student s = new Student();
                s.Id              = stdPost.Id;
                s.Name            = stdPost.Name;
                s.FName           = stdPost.FName;
                s.Dob             = stdPost.Dob;
                s.Email           = stdPost.Email;
                s.Phone           = stdPost.Phone;
                s.UserId          = stdPost.UserId;
                s.Password        = stdPost.Password;
                s.ImageUrl        = stdPost.ImageUrl;
                s.ThumbUrl        = stdPost.ThumbUrl;
                s.ConfirmPassword = stdPost.ConfirmPassword;
                //now First Find Courses And delete previous courses for Student
                var stdPreCourses = context.StudentCourses.Where(x => x.StudentId == stdPost.Id).ToList();
                if (stdPreCourses != null)
                {
                    context.StudentCourses.RemoveRange(stdPreCourses);
                    context.SaveChanges();
                }
                //Now Add Newly Added Courses
                List <StudentCourse> courseList = new List <StudentCourse>();
                if (stdPost.Courses != null)
                {
                    foreach (var Course in stdPost.Courses)
                    {
                        StudentCourse course_Obj = new StudentCourse();
                        course_Obj.StudentId = stdPost.Id;
                        course_Obj.CourseId  = Convert.ToInt32(Course);
                        courseList.Add(course_Obj);
                    }
                    context.StudentCourses.AddRange(courseList);
                    context.Entry(s).State = EntityState.Modified;
                    context.SaveChanges();
                }

                //Adding updated  Courses
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        public void GivenWillAddNewStudentDetailsCallToAddStudent(string name)
        {
            var obj = new
            {
                username   = "******",
                password   = "******",
                grant_type = "password"
            };
            var request = new HttpRequestWrapper()
                          .SetMethod(Method.POST)
                          .SetResourse("/Login")
                          .AddJsonContent(obj);

            _restResponse    = new RestResponse();
            _restResponse    = request.Execute();
            _statusCode      = _restResponse.StatusCode;
            _userResponseDto = JsonConvert.DeserializeObject <LoginUserDto>(_restResponse.Content);
            _Token           = _userResponseDto.access_token;
            Assert.AreEqual(_userResponseDto.token_type, "bearer");

            Dictionary <string, string> header = new Dictionary <string, string>();

            header.Add("Authorization", "bearer " + _Token);
            AddEditStudentDto student = new AddEditStudentDto();

            student.Name  = name;
            student.FName = "testfather";
            student.Email = "*****@*****.**";
            student.Dob   = "11/11/1995";
            List <int> courses = new List <int>();

            courses.Add(1);
            courses.Add(2);
            courses.Add(3);
            student.Courses = courses;
            var Request = new HttpRequestWrapper()
                          .SetMethod(Method.POST)
                          .AddHeaders(header)
                          .SetResourse("/api/Student")
                          .AddJsonContent(student);

            _restResponse   = new RestResponse();
            _restResponse   = Request.Execute();
            _statusCode     = _restResponse.StatusCode;
            _studentDtoResp = JsonConvert.DeserializeObject <StudentDtoResponse>(_restResponse.Content);
            Assert.AreEqual(_studentDtoResp.result, true);
        }
Ejemplo n.º 5
0
        public void GivenTheIdOfStudentToDeleteIs(int Id)
        {
            Dictionary <string, string> header = new Dictionary <string, string>();

            header.Add("Authorization", "bearer " + _Token);
            _id = Id;
            var Request = new HttpRequestWrapper()
                          .SetMethod(Method.GET)
                          .AddHeaders(header)
                          .SetResourse("/api/Student/?id=" + _id);

            _restResponse = new RestResponse();
            _restResponse = Request.Execute();
            model         = JsonConvert.DeserializeObject <AddEditStudentDto>(_restResponse.Content);

            Assert.AreEqual(HttpStatusCode.OK, _restResponse.StatusCode);
            Assert.AreNotEqual(model, null, "This Record Does Not exist in Database Change Id Please And Try Again This Test");
        }
Ejemplo n.º 6
0
        private void BtnEditStudent_Click(object sender, EventArgs e)
        {
            AddEditStudentDto model = new AddEditStudentDto();

            model.Courses = new List <int>();
            foreach (var item in listBox1.CheckedItems)
            {
                model.Courses.Add(Convert.ToInt32(item.GetType().GetProperty("CourseId").GetValue(item, null)));
            }
            model.Id              = StudentId;
            model.Name            = TxtName.Text;
            model.FName           = TxtFName.Text;
            model.Email           = TxtEmail.Text;
            model.Phone           = TxtStudentPhone.Text;
            model.Password        = TxtPassword.Text;
            model.ConfirmPassword = TxtConfirmPassword.Text;
            model.Dob             = DtpStudetDob.Text.ToString();
            model.UserId          = USER_ID;
            model.ImageUrl        = txtImageUrl.Text;
            _StudentRepo.UpdateStudent(model);
            RefreshStudentGridView();
            this.Close();
        }
Ejemplo n.º 7
0
 public bool AddStudent(AddEditStudentDto studentDto)
 {
     try
     {
         StudentCourse stdCourse = new StudentCourse();
         Student       s         = new Student();
         s.Name            = studentDto.Name;
         s.FName           = studentDto.FName;
         s.Dob             = studentDto.Dob;
         s.Email           = studentDto.Email;
         s.Phone           = studentDto.Phone;
         s.Password        = studentDto.Password;
         s.ImageUrl        = studentDto.ImageUrl;
         s.ThumbUrl        = studentDto.ThumbUrl;
         s.ConfirmPassword = studentDto.ConfirmPassword;
         s.UserId          = studentDto.UserId;
         context.Students.Add(s);
         List <StudentCourse> courseList = new List <StudentCourse>();
         if (studentDto.Courses != null)
         {
             foreach (var Course in studentDto.Courses)
             {
                 StudentCourse course_Obj = new StudentCourse();
                 course_Obj.StudentId = s.Id;
                 course_Obj.CourseId  = Convert.ToInt32(Course);
                 courseList.Add(course_Obj);
             }
             context.StudentCourses.AddRange(courseList);
         }
         context.SaveChanges();
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 8
0
 public IHttpActionResult Put([FromBody] AddEditStudentDto Model)
 {
     Model.UserId = USER_ID;
     return(Ok(_repo.UpdateStudent(Model)));
 }