public async Task <ActionResult> EditStudent(Guid?studentId, Guid schoolId)
        {
            if (!studentId.HasValue || studentId == Guid.Empty)
            {
                return(this.PartialView("StudentDetails", new StudentModel {
                    SchoolId = schoolId
                }));
            }

            using (var dbContextScope = this.dbContextScopeFactory.CreateReadOnly())
            {
                var existingStudent =
                    await
                    dbContextScope.DbContexts.Get <SchoolDbContext>()
                    .Students.SingleOrDefaultAsync(s => s.Id == studentId.Value);

                if (existingStudent == null)
                {
                    throw new Entities.Exceptions.ApplicationException($"Could not find student with id {studentId}");
                }

                var model = StudentModel.CreateFromEntity(existingStudent);
                model.SchoolId = schoolId;
                return(this.PartialView("StudentDetails", model));
            }
        }
示例#2
0
        public async Task <ActionResult> EditStudent(Guid?studentId, Guid schoolId)
        {
            if (!studentId.HasValue || studentId == Guid.Empty)
            {
                return(this.PartialView("StudentDetails", new StudentModel {
                    SchoolId = schoolId
                }));
            }

            using (var unitOfWork = this.unitOfWorkFactory.CreateReadOnly())
            {
                var existingStudent =
                    await
                    unitOfWork.Repository <Student>().Get().SingleOrDefaultAsync(s => s.Id == studentId.Value);

                if (existingStudent == null)
                {
                    throw new ApplicationException($"Could not find student with id {studentId}");
                }

                var model = StudentModel.CreateFromEntity(existingStudent);
                model.SchoolId = schoolId;
                return(this.PartialView("StudentDetails", model));
            }
        }
示例#3
0
        public async Task <ActionResult> ConfirmDelete(Guid studentId, Guid schoolId)
        {
            using (var unitOfWork = this.unitOfWorkFactory.CreateReadOnly())
            {
                var existingStudent =
                    await
                    unitOfWork.Repository <Student>().Get().SingleOrDefaultAsync(s => s.Id == studentId);

                if (existingStudent == null)
                {
                    throw new ApplicationException($"Could not find student with id {studentId}");
                }

                var model = StudentModel.CreateFromEntity(existingStudent);
                model.SchoolId = schoolId;
                return(this.PartialView("ConfirmDelete", model));
            }
        }
        public async Task <ActionResult> ConfirmDelete(Guid studentId, Guid schoolId)
        {
            using (var dbContextScope = this.dbContextScopeFactory.CreateReadOnly())
            {
                var existingStudent =
                    await
                    dbContextScope.DbContexts.Get <SchoolDbContext>()
                    .Students.SingleOrDefaultAsync(s => s.Id == studentId);

                if (existingStudent == null)
                {
                    throw new Entities.Exceptions.ApplicationException($"Could not find student with id {studentId}");
                }

                var model = StudentModel.CreateFromEntity(existingStudent);
                model.SchoolId = schoolId;
                return(this.PartialView("ConfirmDelete", model));
            }
        }