public static void EnsureDatabaseIsCreated()
 {
     using (var dbContext = new UniversityDbContext())
     {
         dbContext.Database.Initialize(true);
     }
 }
 public CertificateService(
     UniversityDbContext db,
     IMapper mapper)
 {
     this.db     = db;
     this.mapper = mapper;
 }
 public ExamService(
     UniversityDbContext db,
     IMapper mapper)
 {
     this.db     = db;
     this.mapper = mapper;
 }
 public async Task <IActionResult> GetTeacher([FromQuery] int id)
 {
     using (var context = new UniversityDbContext())
     {
         return(Ok(await context.Teachers.FirstOrDefaultAsync(x => x.Id == id)));
     }
 }
Example #5
0
        public async Task <IActionResult> GetStudents()
        {
            try
            {
                await parallelism.WaitAsync();

                using (var context = new UniversityDbContext())
                {
                    var studentsToReturn = context.Students.ToList();
                    foreach (var stud in studentsToReturn)
                    {
                        context.Entry(stud).Reference(c => c.Course).Load();
                    }
                    return(Ok(studentsToReturn));
                }
            }
            catch (Exception e)
            {
                int i = 0;
            }
            finally
            {
                parallelism.Release();
            }
            return(Ok(null));
        }
 public AdminCourseService(
     UniversityDbContext db,
     IMapper mapper)
 {
     this.db     = db;
     this.mapper = mapper;
 }
Example #7
0
 public AdminCurriculumService(
     UniversityDbContext db,
     IMapper mapper)
 {
     this.db     = db;
     this.mapper = mapper;
 }
 public void TestConnection()
 {
     using (var ctx = new UniversityDbContext())
     {
         Assert.AreEqual(ctx.Courses.Count(), 2);
     }
 }
 public EditCourseCommandHandler(UniversityDbContext context, IMapper mapper,
                                 ILogger <EditCourseCommandHandler> logger)
 {
     _dbContext = context;
     _mapper    = mapper;
     _logger    = logger;
 }
        private IArticleService InitializeArticleService(UniversityDbContext db)
        {
            var htmlService = HtmlServiceMock.GetMock;

            htmlService.Sanitize(SanitizedContent);

            return(new ArticleService(db, htmlService.Object, Tests.Mapper));
        }
Example #11
0
 public CreateDepartmentCommandHandler(
     UniversityDbContext context,
     IMapper mapper
     )
 {
     _dbContext = context;
     _mapper    = mapper;
 }
Example #12
0
 public DataAccess()
 {
     _context               = new UniversityDbContext();
     _coursesRepository     = new CoursesRepository(_context);
     _departmentsRepository = new DepartmentsRepository(_context);
     _studentsRepository    = new StudentsRepository(_context);
     _enrollemntsRepository = new EnrollementsRepository(_context);
 }
 public ArticleService(
     UniversityDbContext db,
     IHtmlService htmlService,
     IMapper mapper)
 {
     this.db          = db;
     this.htmlService = htmlService;
     this.mapper      = mapper;
 }
Example #14
0
        public async Task <IActionResult> UpdateCourse([FromBody] Course course)
        {
            using (var context = new UniversityDbContext())
            {
                context.Courses.Update(course);
                await context.SaveChangesAsync();

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

                return(Ok());
            }
        }
Example #16
0
        public async Task <IActionResult> UpdateStudent([FromBody] Student student)
        {
            using (var context = new UniversityDbContext())
            {
                context.Students.Update(student);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
        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();
        }
 public IActionResult SetupDatabase()
 {
     lock (setupLock)
     {
         using (var context = new UniversityDbContext())
         {
             // Create database
             context.Database.EnsureCreated();
         }
         return(Ok("database university created"));
     }
 }
Example #19
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 <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());
            }
        }
Example #21
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());
            }
        }
Example #22
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            AutofacConfig.ConfigureContainer();

            Database.SetInitializer(new DataInitializer());
            UniversityDbContext context = new UniversityDbContext();

            context.Database.Initialize(true);
        }
Example #23
0
        static void Main(string[] args)
        {
            // This will get the current WORKING directory (i.e. ...\bin\Debug)
            string workingDirectory = Directory.GetCurrentDirectory();

            // This will get the current PROJECT directory
            string projectDirectory = Directory.GetParent(workingDirectory).Parent.Parent.FullName;

            UniversityDbContext dbContext = new UniversityDbContext();
            IUniversityApi      api       = new UniversityApi(dbContext);

            string           filePath = projectDirectory + @"\Resources\StudentPointsData.csv";
            ScoresFileReader sfr      = new ScoresFileReader(filePath, api);

            sfr.ReadAndStoreFileData();
        }
Example #24
0
        public static void Main()
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion <UniversityDbContext, Configuration>());
            var db = new UniversityDbContext();

            // var course = new Course
            // {
            //     Name = "Random course",
            //     Desctiption = "Here is the Description."
            // };
            //
            // db.Courses.Add(course);
            // db.SaveChanges();
            Console.WriteLine(db.Courses.Count());
        }
        public async Task <IActionResult> GetTeachers()
        {
            try
            {
                await parallelism.WaitAsync();

                using (var context = new UniversityDbContext())
                {
                    return(Ok(context.Teachers.ToList()));
                }
            }
            finally
            {
                parallelism.Release();
            }
        }
        public JsonResult UnAssignCourses(int noOfCourses)
        {
            var listOfCourseId = db.Courses.Where(c => c.CourseStatus == 1).Select(c => c.CourseId);

            using (var ctx = new UniversityDbContext())
            {
                foreach (var acourseId in listOfCourseId)
                {
                    Course selectedCors = new Course();
                    selectedCors = ctx.Courses.Where(id => id.CourseId == acourseId).Single();
                    selectedCors.CourseStatus     = 0;
                    ctx.Entry(selectedCors).State = EntityState.Modified;
                    ctx.SaveChanges();
                }
            }
            return(Json(true));
        }
        private void ReportHeader(StudentResult studentResult)
        {
            _fontStyle                    = FontFactory.GetFont("Tahoma", 11f, 1);
            _pdfPCell                     = new PdfPCell(new Phrase("Eastern University", _fontStyle));
            _pdfPCell.Colspan             = _totalColumn;
            _pdfPCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfPCell.Border              = 0;
            _pdfPCell.BackgroundColor     = BaseColor.WHITE;
            _pdfPCell.ExtraParagraphSpace = 0;
            _pdfTable.AddCell(_pdfPCell);
            _pdfTable.CompleteRow();

            _fontStyle                    = FontFactory.GetFont("Tahoma", 9f, 1);
            _pdfPCell                     = new PdfPCell(new Phrase("Result Sheet", _fontStyle));
            _pdfPCell.Colspan             = _totalColumn;
            _pdfPCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfPCell.Border              = 0;
            _pdfPCell.BackgroundColor     = BaseColor.WHITE;
            _pdfPCell.ExtraParagraphSpace = 0;
            _pdfTable.AddCell(_pdfPCell);
            _pdfTable.CompleteRow();

            _fontStyle                    = FontFactory.GetFont("Tahoma", 9f);
            _pdfPCell                     = new PdfPCell(new Phrase("Date : " + DateTime.Now, _fontStyle));
            _pdfPCell.Colspan             = _totalColumn;
            _pdfPCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfPCell.Border              = 0;
            _pdfPCell.BackgroundColor     = BaseColor.WHITE;
            _pdfPCell.ExtraParagraphSpace = 0;
            _pdfTable.AddCell(_pdfPCell);

            /////////
            UniversityDbContext db = new UniversityDbContext();
            var regNo = db.RegisterStudents.Where(s => s.Id == studentResult.RegisterStudentId)
                        .Select(s => new { regNo = s.RegNo });

            _fontStyle                    = FontFactory.GetFont("Tahoma", 9f);
            _pdfPCell                     = new PdfPCell(new Phrase("Reg No : " + regNo.FirstOrDefault().regNo, _fontStyle));
            _pdfPCell.Colspan             = _totalColumn;
            _pdfPCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfPCell.Border              = 0;
            _pdfPCell.BackgroundColor     = BaseColor.WHITE;
            _pdfPCell.ExtraParagraphSpace = 0;
            _pdfTable.AddCell(_pdfPCell);
            ////////
        }
Example #28
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 static void Main()
        {
            var db = new UniversityDbContext();

            //var student = new Student()
            //{
            //    FirstName = "Pesho",
            //    LastName = "Peshev",
            //    ForumPoints = 0
            //};

            //db.Students.Add(student);
            //db.SaveChanges();

            var savedStudent = db.Students.First();
            db.Students.Remove(savedStudent);
            db.SaveChanges();
        }
        // GET: Base
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            UniversityDbContext db = new UniversityDbContext();
            var session            = ((UserLogin)Session[ModelPr.CommonClass.CommonCls.User_session]);

            if (session == null)
            {
            }
            else if (session != null)
            {
                var userRole = db.Accounts.Find(session.UserID).Role;
                if (userRole.Equals("QAM"))
                {
                    filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { Controller = "CateGrIdea", action = "Index", Area = "QAManager" }));
                }
            }
            base.OnActionExecuting(filterContext);
        }
        public static void Main()
        {
            var db = new UniversityDbContext();

            //var student = new Student()
            //{
            //    FirstName = "Pesho",
            //    LastName = "Peshev",
            //    ForumPoints = 0
            //};

            //db.Students.Add(student);
            //db.SaveChanges();

            var savedStudent = db.Students.First();

            db.Students.Remove(savedStudent);
            db.SaveChanges();
        }