Пример #1
0
 public InstructorModule(UniContext context) : base("/instructor", context)
 {
     After += ctx =>
     {
         UpdateUserCache(ctx.Request.Method, ModifiedItem);
     };
 }
Пример #2
0
 public async Task EditInstanceAsync(Course model, UniContext ctx, CancellationToken token)
 {
     Name    = model.Name;
     Code    = model.Code;
     Ects    = model.Ects;
     Program = await ctx.Programs.FindAsync(token, model.Program.Id);
 }
Пример #3
0
 public StudentModule(UniContext context) : base("/student", context)
 {
     After += ctx =>
     {
         UpdateUserCache(ctx.Request.Method, ModifiedItem);
     };
 }
Пример #4
0
 public FuncionariosController(UniContext context, UserManager <IdentityUser> userManager, IEmailSender emailSender, RoleManager <IdentityRole> roleManager)
 {
     _context     = context;
     _userManager = userManager;
     _emailSender = emailSender;
     _roleManager = roleManager;
 }
Пример #5
0
 public StudentActionModule(UniContext context) : base("/student", typeof(Student))
 {
     this.context = context;
     Post("/register", RegisterSectionAsync);
     Post("/unregister", UnregisterSectionAsync);
     Get("/sections/registered", GetRegisteredSectionsAsync);
     Get("/courses", GetAvailableCoursesAsync);
     Get("/grades", GetGradesAsync);
 }
Пример #6
0
 // Delete book
 public void delete(string strBookID)
 {
     using (var context = new UniContext())
     {
         var book = context.Books.Where(x => x.BookID.ToString().Equals(strBookID)).Single();
         context.Books.Remove(book);
         context.SaveChanges();
     }
 }
Пример #7
0
 // Edit book
 public void Edit(string strBookID)
 {
     using (var context = new UniContext())
     {
         var book = context.Books.Where(x => x.BookID.ToString().Equals(strBookID)).Single();
         book.BookName = "BookEdit";
         context.SaveChanges();
     }
 }
Пример #8
0
 public async Task EditInstanceAsync(Student model, UniContext ctx, CancellationToken token)
 {
     EditInstance(model);
     StudentId = model.StudentId;
     Semester  = model.Semester;
     Year      = model.Year;
     Cgpa      = model.Cgpa;
     Program   = await ctx.Programs.FindAsync(token, model.Program.Id);
 }
 public InstructorActionModule(UniContext context) : base("/instructor", typeof(Instructor))
 {
     this.context = context;
     Get("/sections", GetSectionsAsync);
     Get("/section/{id}/students", GetSectionStudentsAsync);
     Get("/gradetypes/{id}", GetGradeTypesAsync);
     Post("/gradetypes/{id}", SetGradeTypesAsync);
     Get("/grades/{id}", GetStudentGradesAsync);
     Post("/grade/{id}", SetStudentGradeAsync);
 }
Пример #10
0
        public async Task EditInstanceAsync(Section model, UniContext ctx, CancellationToken token)
        {
            Number   = model.Number;
            Capacity = model.Capacity;
            Course   = await ctx.Courses.FindAsync(token, model.Course.Id);

            Instructor = await ctx.Instructors.FindAsync(token, model.Instructor.Id);

            TimeTable.Clear();
            TimeTable.AddRange(model.TimeTable);
        }
Пример #11
0
        /// <summary>
        /// Loads configuration data from json file.
        /// </summary>
        /// <param name="workingDirectory">Path to config.json directory</param>
        public static void Init(string workingDirectory = "")
        {
            var     configJson = File.ReadAllText(workingDirectory + "config.json");
            dynamic config     = JsonConvert.DeserializeObject(configJson);
            string  connType   = config.DbType;
            string  dbname     = config.DbName;
            string  srvname    = config.ServerName;
            string  userid     = config.UserId;
            string  password   = config.Password;

            //This switch statement binds a return function for each of the different possible database connections
            switch (connType.ToUpper())
            {
            case "MYSQL":
                var connectionString = new MySqlConnectionStringBuilder
                {
                    Database = dbname,
                    UserID   = userid,
                    Password = password,
                    Server   = srvname
                }.ConnectionString;
                GetDbConnection = () => new MySqlConnection(connectionString);;
                break;

            case "MSSQL":
                connectionString = new SqlConnectionStringBuilder
                {
                    DataSource     = srvname,
                    InitialCatalog = dbname,
                    UserID         = userid,
                    Password       = password
                }.ConnectionString;
                GetDbConnection = () => new SqlConnection(connectionString);
                break;

            case "LOCALDB":
                connectionString = dbname;
                GetDbConnection  = () => new LocalDbConnectionFactory("mssqllocaldb").CreateConnection(connectionString);
                break;
            }
            AppKey      = config.AppKey;
            HostUri     = config.HostUri;
            LogFileName = config.LogFileName;
            using (var context = new UniContext())
            {
                context.Database.CreateIfNotExists();
            }
            UserCache.Reload();
        }
Пример #12
0
        public StudentController(UniContext context)   // dependency injection of SudentRepo class instance
        {
            this.context = context;

            if (context.Students.Count() == 0)
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.

                foreach (var item in studs)
                {
                    context.Students.Add(item);
                }

                context.SaveChanges();
            }
        }
Пример #13
0
 /// <summary>
 /// Reloads the list of all users.
 /// </summary>
 public static void Reload()
 {
     if (Users == null)
     {
         Users = new List <User>();
     }
     else
     {
         Users.Clear();
     }
     using (var context = new UniContext())
     {
         Users.AddRange(context.Admins.ToList());
         Users.AddRange(context.Instructors.ToList());
         Users.AddRange(context.Students.ToList());
     }
 }
Пример #14
0
 protected CrudModule(string uri, UniContext context) : base(uri, typeof(Admin))
 {
     propVal      = new string[2];
     this.context = context;
     Get("/", GetItemsAsync);
     Get("/with/{props}", GetItemsWithPropsAsync);
     Get("/where/{prop}={value}", GetItemsWherePropAsync);
     Get("/where/{prop}={value}/with/{props}", GetItemsWherePropWithPropsAsync);
     Get("/range/{value1}-{value2}", GetItemsRangeAsync);
     Get("/range/{value1}-{value2}/with/{props}", GetItemsRangeWithPropsAsync);
     Get("/range/{prop}={value1}-{value2}", GetItemsRangePropAsync);
     Get("/range/{prop}={value1}-{value2}/with/{props}", GetItemsRangePropWithPropsAsync);
     Get("/{id}", GetItemByIdAsync);
     Get("/{id}/with/{props}", GetItemByIdWithPropsAsync);
     Post("/", AddItemAsync);
     Put("/{id}", EditItemAsync);
     Delete("/{id}", DeleteItemAsync);
 }
Пример #15
0
        // Add new book
        public void Add()
        {
            using (var context = new UniContext())
            {
                var book = new Book
                {
                    BookID    = "BK00000001",
                    BookName  = "FullStack React",
                    Tags      = "React",
                    Publisher = "FullStack.io",
                    Authors   = "FullStack.io",
                    Pages     = 678,
                    Size      = 12.3
                };

                context.Books.Add(book);
                context.SaveChanges();
            }
        }
Пример #16
0
        /// <summary>
        /// Admin registration.
        /// Should be disabled once an admin is registered.
        /// </summary>
        /// <param name="_">Not used</param>
        /// <param name="token">Cancellation token if request is cancelled</param>
        /// <returns>User details in JSON format</returns>
        private async Task <object> RegisterAsync(dynamic _, CancellationToken token)
        {
            var data = Request.Form;

            using (var context = new UniContext())
            {
                //Hashes password using BCrypt with work factor 8
                string pw = await Task.Run(() => HashPassword(data.password, GenerateSalt(8)), token);

                var admin = context.Admins.Add(new Admin
                {
                    Email     = data.email,
                    FirstName = data.firstname,
                    LastName  = data.lastname,
                    Password  = pw
                });
                await context.SaveChangesAsync(token);

                UserCache.Users.Add(admin);
                return(Response.AsJson(admin));
            }
        }
Пример #17
0
 public HistoricoStatusController(UniContext context)
 {
     _context = context;
 }
Пример #18
0
 public HistoricoSalariosController(UniContext context)
 {
     _context = context;
 }
Пример #19
0
 public StudentController(StudentService studentService, UniContext context)
 {
     this.studentService = studentService;
     this.context        = context;
 }
Пример #20
0
 public async Task BindInstanceAsync(UniContext ctx, CancellationToken token)
 {
 }
Пример #21
0
 public SectionModule(UniContext context) : base("/section", context)
 {
 }
Пример #22
0
 public async Task BindInstanceAsync(UniContext ctx, CancellationToken token)
 {
     Program = await ctx.Programs.FindAsync(token, Program.Id);
 }
Пример #23
0
 public async Task EditInstanceAsync(Admin model, UniContext ctx, CancellationToken token)
 {
     EditInstance(model);
 }
Пример #24
0
#pragma warning disable 1998
        public async Task EditInstanceAsync(Department model, UniContext ctx, CancellationToken token)
#pragma warning restore 1998
        {
            Name = model.Name;
        }
Пример #25
0
 public TelefonesController(UniContext context)
 {
     _context = context;
 }
Пример #26
0
 public async Task BindInstanceAsync(UniContext ctx, CancellationToken token)
 {
     Department = await ctx.Departments.FindAsync(token, Department.Id);
 }
Пример #27
0
 public async Task EditInstanceAsync(Instructor model, UniContext ctx, CancellationToken token)
 {
     EditInstance(model);
     InstructorId = model.InstructorId;
     Department   = await ctx.Departments.FindAsync(token, model.Department.Id);
 }
Пример #28
0
 public ClientesController(UniContext context)
 {
     _context = context;
 }
Пример #29
0
#pragma warning disable 1998
        public async Task BindInstanceAsync(UniContext ctx, CancellationToken token)
#pragma warning restore 1998
        {
        }
Пример #30
0
 public CotacaoProdutoesController(UniContext context)
 {
     _context = context;
 }