コード例 #1
0
        public async Task <Student> AddStudentAsync(StudentInsertRequest request)
        {
            Student student = new Student()
            {
                Name         = request.Name,
                RollNo       = request.RollNo,
                Email        = request.Email,
                DepartmentId = request.DepartmentId
            };
            await _unitOfWork.StudentRepository.CreateAsync(student);

            if (await _unitOfWork.ApplicationSaveChangesAsync())
            {
                DepartmentStudentReportMongo deptStudentReportMongo = new DepartmentStudentReportMongo()
                {
                    DepartmentCode = student.Department.Code,
                    DepartmentName = student.Department.Name,
                    StudentName    = student.Name,
                    StudentEmail   = student.Email,
                    StudentRoll    = student.RollNo,
                };
                await _departmentStudentMongoRepository.Create(deptStudentReportMongo);

                return(student);
            }
            throw new MyAppException("Student Data Not save");
        }
        public async Task <List <DepartmentStudentReportMongo> > GetAll(DepartmentStudentReportMongo departmentStudentReportMongo)
        {
            var filterBuilder = Builders <DepartmentStudentReportMongo> .Filter;
            var filter        = filterBuilder.Empty;
            var sort          = Builders <DepartmentStudentReportMongo> .Sort.Descending("_id");

            return(await _context.DepartmentStudentReport.Find(filter).Sort(sort).ToListAsync());
        }
コード例 #3
0
        public ActionResult MongoTry()
        {
            var myroles = new List <Role>
            {
                new Role
                {
                    Name = "Admin",
                    ID   = "1234"
                }
            };
            var mongoReport = new DepartmentStudentReportMongo
            {
                StudentName    = "Arifur Rahman",
                StudentEmail   = "*****@*****.**",
                DepartmentCode = "CSE",
                DepartmentName = "Computer Science",
                Roles          = myroles
            };

            _mongoRepository.Create(mongoReport);
            return(Ok("Hello Mongo"));
        }
        public async Task <DepartmentStudentReportMongo> Create(DepartmentStudentReportMongo departmentStudentReportMongo)
        {
            await _context.DepartmentStudentReport.InsertOneAsync(departmentStudentReportMongo);

            return(departmentStudentReportMongo);
        }