コード例 #1
0
        public async Task <StudentEntity> AddStudentAsync(StudentEntity student)
        {
            await _dbConext.Students.AddAsync(student);

            await _dbConext.SaveChangesAsync();

            return(student);
        }
コード例 #2
0
        public async Task <ActionResult> Create([Bind(Include = "DepartmentId,DepartmentCode,DepartmentName")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
コード例 #3
0
        public async Task <ActionResult> Create([Bind(Include = "StudentId,StudentName,RegNo,Age,DepartmentId")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentCode", student.DepartmentId);
            return(View(student));
        }
コード例 #4
0
        public async Task Complete(CancellationToken cancellationToken)
        {
            foreach (var entry in _context.ChangeTracker.Entries())
            {
                if (entry.Entity is ITrackable trackable)
                {
                    var now = DateTime.UtcNow;
                    switch (entry.State)
                    {
                    case EntityState.Modified:
                        trackable.LastUpdatedAt = now;
                        break;

                    case EntityState.Added:
                        trackable.CreatedAt     = now;
                        trackable.LastUpdatedAt = now;
                        break;
                    }
                }
            }

            try
            {
                await _context.SaveChangesAsync(cancellationToken);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #5
0
            public async Task <Unit> Handle(DeleteCourseCommand request, CancellationToken ct)
            {
                var course = await _dbContext.Courses.FindAsync(request.Id);

                _dbContext.Remove(course);
                await _dbContext.SaveChangesAsync();

                return(default);
コード例 #6
0
                public async Task <Unit> Handle(DeleteDepartmentCommand request, CancellationToken ct)
                {
                    var department = await _dbContext.Departments.FindAsync(request.Id);

                    _dbContext.Departments.Remove(department);
                    await _dbContext.SaveChangesAsync(ct);

                    return(default);
コード例 #7
0
        public async Task <IActionResult> UpdateStudent([FromBody] Student student)
        {
            using (var context = new UniversityDbContext())
            {
                context.Students.Update(student);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
コード例 #8
0
        public async Task <IActionResult> UpdateTeacher([FromBody] Teacher teacher)
        {
            using (var context = new UniversityDbContext())
            {
                context.Teachers.Update(teacher);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
コード例 #9
0
            public async Task <int> Handle(CreateDepartmentCommand request, CancellationToken ct)
            {
                var department = _mapper.Map <CreateDepartmentCommand, Department>(request);

                _dbContext.Departments.Add(department);

                await _dbContext.SaveChangesAsync(ct);

                return(department.Id);
            }
コード例 #10
0
        public async Task <IActionResult> UpdateCourse([FromBody] Course course)
        {
            using (var context = new UniversityDbContext())
            {
                context.Courses.Update(course);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
コード例 #11
0
            public async Task <int> Handle(CreateCourseCommand request, CancellationToken ct)
            {
                var course = _mapper.Map <CreateCourseCommand, Course>(request);

                course.Id = request.Number;

                _dbContext.Courses.Add(course);
                await _dbContext.SaveChangesAsync(ct);

                return(course.Id);
            }
コード例 #12
0
        public async Task <CourseDetail> CreateCourse(CourseCreationCommand courseToCreate)
        {
            var course = new Course
            {
                ClassDuration = courseToCreate.ClassDuration,
                CourseNumber  = courseToCreate.CourseNumber,
                DepartmentId  = courseToCreate.DepartmentId,
                Description   = courseToCreate.Description,
                EndDate       = courseToCreate.EndDate,
                Id            = courseToCreate.Id,
                InstructorId  = courseToCreate.InstructorId,
                Name          = courseToCreate.Name,
                StartDate     = courseToCreate.StartDate
            };

            await _context.Courses.AddAsync(course);

            await _context.SaveChangesAsync();

            return(await _repository.GetCourse(courseToCreate.Id));
        }
コード例 #13
0
        private async Task PrepareStudentCourseCertificate(UniversityDbContext db, decimal grade)
        {
            await db.Certificates.AddAsync(new Certificate
            {
                Id        = CertificateIdValid,
                StudentId = StudentEnrolledId,
                CourseId  = CourseValidId,
                GradeBg   = grade
            });

            await db.SaveChangesAsync();
        }
コード例 #14
0
        public async Task <IActionResult> DeleteTeacher([FromQuery] int id)
        {
            using (var context = new UniversityDbContext())
            {
                var teacher = await context.Teachers.FirstOrDefaultAsync(x => x.Id == id);

                if (teacher != null)
                {
                    context.Teachers.Remove(teacher);
                    await context.SaveChangesAsync();
                }
                return(Ok());
            }
        }
コード例 #15
0
        public async Task <IActionResult> DeleteStudent([FromQuery] int id)
        {
            using (var context = new UniversityDbContext())
            {
                var student = await context.Students.FirstOrDefaultAsync(x => x.Id == id);

                if (student != null)
                {
                    context.Students.Remove(student);
                    await context.SaveChangesAsync();
                }
                return(Ok());
            }
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,FirstName")] Name name)
        {
            if (ModelState.IsValid)
            {
                db.Names.Add(name);
                if (await db.SaveChangesAsync() > 0)
                {
                    TempData["Message"]     = string.Format("Name <b> {0} </b> Is Added Successfully!", name.FirstName);
                    TempData["MessageType"] = "success";
                }
            }

            return(View(name));
        }
コード例 #17
0
        public async Task <IActionResult> DeleteCourse([FromQuery] int id)
        {
            using (var context = new UniversityDbContext())
            {
                var course = await context.Courses.FirstOrDefaultAsync(x => x.Id == id);

                if (course != null)
                {
                    context.Courses.Remove(course);
                    await context.SaveChangesAsync();
                }
                return(Ok());
            }
        }
コード例 #18
0
        public async Task <ActionResult> Create([Bind(Include = "Id,DeptCode,DeptName")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                if (await db.SaveChangesAsync() > 0)
                {
                    TempData["Massage"]     = string.Format("Department <b> {0} </b> is Save Successfully", department.DeptCode);
                    TempData["MassageType"] = "success";
                }
                //db.SaveChanges();
                //return RedirectToAction("Create");
            }

            return(View(department));
        }
コード例 #19
0
    public async Task <IEvent> Handle(DeleteCourseCommand request, CancellationToken cancellationToken)
    {
        var course = await _context.Courses.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken);

        if (course is null)
        {
            return(new CourseNotFoundEvent());
        }
        _context.Courses.Remove(course);
        var saveResult = await _context.SaveChangesAsync(cancellationToken);

        if (saveResult <= 0)
        {
            throw new DeleteFailureException(nameof(course), request.Id, "Database save was not successful.");
        }
        return(new CourseDeletedEvent());
    }
コード例 #20
0
        public async Task <ActionResult> Create([Bind(Include = "Id,CourseCode,CourseName,CourseCredit,CourseDescription,CourseAssignTo,CourseStatus,DepartmentId,SemesterId")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                if (await db.SaveChangesAsync() > 0)
                {
                    TempData["Message"]     = string.Format("<b>{0}</b> Is Created Successfully.", course.CourseName);
                    TempData["MessageType"] = "success";
                }
                return(RedirectToAction("Create"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DeptCode", course.DepartmentId);
            ViewBag.SemesterId   = new SelectList(db.Semesters, "Id", "SemesterName", course.SemesterId);
            return(View(course));
        }
コード例 #21
0
        public async Task <IActionResult> CreateStudent([FromBody] Student student)
        {
            using (var context = new UniversityDbContext())
            {
                try
                {
                    context.Courses.Attach(student.Course);
                    context.Students.Add(student);
                    await context.SaveChangesAsync();

                    return(Ok());
                }
                catch (Exception e)
                {
                    return(Ok());
                }
            }
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,TeacherName,TeacherAddress,TeacherEmail,TeacherContactNo,DesignationId,DepartmentId,CreditTaken,CreditLeft")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                teacher.CreditLeft = teacher.CreditTaken;
                db.Teachers.Add(teacher);
                if (await db.SaveChangesAsync() > 0)
                {
                    TempData["Massage"]     = string.Format("Teacher <b> {0} </b> is Save Successfully", teacher.TeacherName);
                    TempData["MassageType"] = "success";
                }
                return(RedirectToAction("Create"));
            }

            //ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DeptCode", teacher.DepartmentId);

            //ViewBag.DesignationId = new SelectList(db.Designations, "Id", "DesignationName", teacher.DesignationId);
            return(View(teacher));
        }
コード例 #23
0
        public async Task <IActionResult> CreateTeaching([FromBody] Teaching teachings)
        {
            using (var context = new UniversityDbContext())
            {
                try
                {
                    context.Courses.Attach(teachings.Course);
                    context.Teachers.Attach(teachings.Teacher);
                    context.Teachings.Add(teachings);

                    await context.SaveChangesAsync();

                    return(Ok());
                }
                catch (Exception e)
                {
                    return(Ok());
                }
            }
        }
        public async Task <ActionResult> Create(Student student)
        {
            if (ModelState.IsValid)
            {
                student.StudentRegNo = GetRegistrationNumber(student);
                db.Students.Add(student);

                if (await db.SaveChangesAsync() > 0)
                {
                    ViewBag.Message     = string.Format("{0} Has Been Created Successfully", student.Name);
                    ViewBag.MessageType = "success";
                }

                //db.SaveChanges();
                //return RedirectToAction("Index");
            }

            ViewBag.Departments = db.Departments.ToList();
            return(View(student));
        }
コード例 #25
0
        private async Task PrepareStudentInCourse(UniversityDbContext db)
        {
            var student = new User {
                Id = StudentEnrolledId
            };
            var trainer = new User {
                Id = TrainerValidId
            };

            var course = new Course {
                Id = CourseValidId, TrainerId = TrainerValidId
            };

            course.Students.Add(new StudentCourse {
                StudentId = StudentEnrolledId
            });

            await db.Users.AddRangeAsync(student, trainer);

            await db.Courses.AddAsync(course);

            await db.SaveChangesAsync();
        }
コード例 #26
0
ファイル: Repository.cs プロジェクト: eryashmehta/SSW
 public async Task AddAsync(TEntity entity)
 {
     _context.Set <TEntity>().Add(entity);
     await _context.SaveChangesAsync();
 }
コード例 #27
0
 public async Task AddAsync(T model)
 {
     dbContext.Set <T>().Add(model);
     await dbContext.SaveChangesAsync();
 }