Exemplo n.º 1
0
        public Student Modify([FromBody] StudentInput modifiedStudent)
        {
            string cs      = @"Database\sample.db3;";
            string newPath = Path.GetFullPath(Path.Combine(@".\", cs));

            newPath       = "Data Source=" + newPath;
            using var con = new SQLiteConnection(newPath);
            con.Open();
            var age = Int32.Parse(modifiedStudent.Age);

            using var cmd   = new SQLiteCommand(con);
            cmd.CommandText = "UPDATE Student SET Username = @Username, FirstName = @FirstName, LastName = @LastName, Age = @Age, Career = @Career WHERE Id = @Id";

            cmd.Parameters.AddWithValue("@Username", modifiedStudent.Username);
            cmd.Parameters.AddWithValue("@FirstName", modifiedStudent.FirstName);
            cmd.Parameters.AddWithValue("@LastName", modifiedStudent.LastName);
            cmd.Parameters.AddWithValue("@Age", age);
            cmd.Parameters.AddWithValue("@Career", modifiedStudent.Career);
            cmd.Parameters.AddWithValue("@Id", modifiedStudent.Id);

            cmd.Prepare();

            cmd.ExecuteNonQuery();

            Console.WriteLine("row inserted");
            return(new Student());
        }
Exemplo n.º 2
0
        public Student Insert([FromBody] StudentInput newStudent)
        {
            string cs      = @"Database\sample.db3;";
            string newPath = Path.GetFullPath(Path.Combine(@".\", cs));

            newPath       = "Data Source=" + newPath;
            using var con = new SQLiteConnection(newPath);
            con.Open();
            var age = Int32.Parse(newStudent.Age);

            using var cmd   = new SQLiteCommand(con);
            cmd.CommandText = "INSERT INTO Student(Username, FirstName, LastName, Age, Career) VALUES(@Username, @FirstName, @LastName, @Age, @Career)";

            cmd.Parameters.AddWithValue("@Username", newStudent.Username);
            cmd.Parameters.AddWithValue("@FirstName", newStudent.FirstName);
            cmd.Parameters.AddWithValue("@LastName", newStudent.LastName);
            cmd.Parameters.AddWithValue("@Age", age);
            cmd.Parameters.AddWithValue("@Career", newStudent.Career);

            cmd.Prepare();

            cmd.ExecuteNonQuery();

            Console.WriteLine("row inserted");
            return(new Student());
        }
Exemplo n.º 3
0
        public Object Add(StudentInput input)
        {
            var param = new Student {
                Id = input.Id, Name = input.Name
            };

            _studentService.Add(param);
            return(param);
        }
Exemplo n.º 4
0
        public PagedResultDto <StudentListDto> GetPagedStudents(StudentInput input)
        {
            var query = GetStudentsByCondition(input);
            var count = query.Count();

            input.SkipCount      = ((input.PIndex ?? 1) - 1) * (input.PSize ?? 10);
            input.MaxResultCount = input.PSize ?? 10;
            var list = query.PageBy(input).ToList();

            return(new PagedResultDto <StudentListDto>(count, list.MapTo <List <StudentListDto> >()));
        }
Exemplo n.º 5
0
        private IQueryable <Student.Students> GetStudentsByCondition(StudentInput input)
        {
            //WhereIf 是ABP针对IQueryable<T>的扩展方法 第一个参数为条件,第二个参数为一个Predicate 当条件为true执行后面的条件过滤
            var query = _studentRepository.GetAll()
                        .WhereIf(!input.Id.IsNullOrEmpty(), o => o.Id == input.Id)
                        .WhereIf(!input.CnName.IsNullOrEmpty(), t => t.CnName.Contains(input.CnName))
                        .WhereIf(input.IsActive.HasValue, o => o.IsActive == input.IsActive)
                        .Where(o => o.IsDeleted == false);

            query = string.IsNullOrEmpty(input.Sorting)
                        ? query.OrderByDescending(t => t.CreationTime)
                        : query.OrderBy(t => input.Sorting);
            return(query);
        }
Exemplo n.º 6
0
 public ViewResult RsvpForm(StudentInput StudentInfo)
 {
     Repository.AddResponse(StudentInfo);
     return(View("Congratulations", StudentInfo));
 }
        public async Task Add(StudentInput input)
        {
            //验证传入参数
            if (!input.EntryDate.HasValue)
            {
                throw new UserFriendlyException("传入EntryDate参数不正确!");
            }

            //验证用户名是否存在
            var user = _userRepository.FirstOrDefault(x => x.UserName == input.StudentNo);

            if (user != null)
            {
                throw new UserFriendlyException($"登陆账号{input.StudentNo}已存在!");
            }

            var role = await _roleManager.GetRoleByNameAsync(StaticRoleNames.CourseSelecting.Student);

            if (role == null)
            {
                throw new UserFriendlyException("系统未初始化!");
            }

            //创建学生对象
            var student = new CourseSelecting.Users.Student
            {
                TenantId = AbpSession.TenantId,
                UserName = input.StudentNo,
                //用户名称
                Name         = input.Name,
                Surname      = input.Name,
                EmailAddress = "*****@*****.**",
                //入学时间
                EntryDate = input.EntryDate.Value,
                StudentNo = input.StudentNo
            };

            #region --非必填属性赋值--

            //密码属性赋值
            if (!string.IsNullOrEmpty(input.Password))
            {
                student.Password = new PasswordHasher().HashPassword(input.Password);
            }
            else
            {
                student.Password = new PasswordHasher().HashPassword(CourseSelecting.Users.Student.DefaultStudentPassword);
            }

            //性别属性赋值
            if (input.Gender.HasValue)
            {
                student.Gender = input.Gender.Value;
            }
            //专业属性赋值
            if (!string.IsNullOrEmpty(input.Major))
            {
                student.Major = input.Major;
            }
            //电话属性赋值
            if (!string.IsNullOrEmpty(input.Tel))
            {
                student.Tel = input.Tel;
            }
            //年级属性赋值
            if (!string.IsNullOrEmpty(input.Grade))
            {
                student.Grade = input.Grade;
            }
            //班级属性赋值
            if (!string.IsNullOrEmpty(input.Class))
            {
                student.Class = input.Class;
            }
            //生源地属性赋值
            if (!string.IsNullOrEmpty(input.OriginOfStudent))
            {
                student.OriginOfStudent = input.OriginOfStudent;
            }
            //专业等级属性赋值
            if (!string.IsNullOrEmpty(input.ProfessionLevel))
            {
                student.ProfessionLevel = input.ProfessionLevel;
            }
            //院系属性赋值
            if (!string.IsNullOrEmpty(input.Department))
            {
                student.Department = input.Department;
            }

            #endregion

            student = await _studentRepository.InsertAsync(student);

            var userRole = new UserRole
            {
                TenantId = AbpSession.TenantId,
                RoleId   = role.Id,
                UserId   = student.Id
            };

            await _userRoleRepository.InsertAsync(userRole);
        }
        public async Task Edit(StudentInput input)
        {
            var student = _studentRepository.FirstOrDefault(x => x.Id == input.Id);

            if (student == null)
            {
                throw new UserFriendlyException($"登陆账号{input.StudentNo}不存在!");
            }

            //验证用户名是否重复
            var user = await _userRepository.FirstOrDefaultAsync(x => x.UserName == input.StudentNo && x.Id != student.Id);

            if (user != null)
            {
                throw new UserFriendlyException($"登陆账号{input.StudentNo}已存在!");
            }


            if (!string.IsNullOrEmpty(input.StudentNo))
            {
                student.UserName = input.StudentNo;
            }
            if (!string.IsNullOrEmpty(input.Name))
            {
                student.Name = input.Name;
            }
            //入学时间
            if (input.EntryDate.HasValue)
            {
                student.EntryDate = input.EntryDate.Value;
            }
            #region --非必填属性赋值--

            //密码属性赋值
            if (!string.IsNullOrEmpty(input.Password))
            {
                student.Password = new PasswordHasher().HashPassword(input.Password);
            }
            else
            {
                student.Password = new PasswordHasher().HashPassword(CourseSelecting.Users.Student.DefaultStudentPassword);
            }

            //性别属性赋值
            if (input.Gender.HasValue)
            {
                student.Gender = input.Gender.Value;
            }
            //专业属性赋值
            if (!string.IsNullOrEmpty(input.Major))
            {
                student.Major = input.Major;
            }
            //电话属性赋值
            if (!string.IsNullOrEmpty(input.Tel))
            {
                student.Tel = input.Tel;
            }
            //年级属性赋值
            if (!string.IsNullOrEmpty(input.Grade))
            {
                student.Grade = input.Grade;
            }
            //班级属性赋值
            if (!string.IsNullOrEmpty(input.Class))
            {
                student.Class = input.Class;
            }
            //生源地属性赋值
            if (!string.IsNullOrEmpty(input.OriginOfStudent))
            {
                student.OriginOfStudent = input.OriginOfStudent;
            }
            //专业等级属性赋值
            if (!string.IsNullOrEmpty(input.ProfessionLevel))
            {
                student.ProfessionLevel = input.ProfessionLevel;
            }
            //院系属性赋值
            if (!string.IsNullOrEmpty(input.Department))
            {
                student.Department = input.Department;
            }

            #endregion
            await _studentRepository.UpdateAsync(student);
        }
Exemplo n.º 9
0
 public Student.Students GetStudent(StudentInput input)
 {
     return(GetStudentsByCondition(input).FirstOrDefault()); //_studentRepository.Get(input.Id);
 }