コード例 #1
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            try
            {
                string   id             = actionContext.Request.Headers.GetCookies("appUser").First()["appUser"].Value;
                string[] identity       = id.Split(',');
                string   identifier     = identity[0];
                SHA512   SHA            = new SHA512Managed();
                string   password       = identity[1];
                var      password_bytes = ASCIIEncoding.ASCII.GetBytes(password);
                byte[]   passBytes      = new byte[password_bytes.Length];
                for (int i = 0; i < password_bytes.Length; i++)
                {
                    passBytes[i] = password_bytes[i];
                }
                string hashedPass = Convert.ToBase64String(SHA.ComputeHash(passBytes));
                using (var context = new AcademicSystemContext())
                {
                    var user = context.Usuarios.Where(u => (u.UserId.ToString() == identifier || u.Email == identifier) && u.Password == hashedPass).FirstOrDefault();
                    if (user != null)
                    {
                        Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(user.UserId.ToString()), null);
                    }

                    else
                    {
                        actionContext.Response = actionContext.Request.CreateResponse(System.Net.HttpStatusCode.Unauthorized);
                    }
                }
            }
            catch (Exception e)
            {
                actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }
        }
コード例 #2
0
 // GET: api/Rooms
 public IEnumerable <object> Get()
 {
     using (var context = new AcademicSystemContext())
     {
         return(context.Rooms.ToList());
     }
 }
コード例 #3
0
 public object Post(HorarioDTO @new)
 {
     try
     {
         using (var context = new AcademicSystemContext())
         {
             context.Horarios.Add(new Horario
             {
                 Asignatura = context.PeriodAsignature
                              .Where(a => a.PeriodAsignatureID == @new.PeriodAsigID)
                              .FirstOrDefault(),
                 Aula      = context.Rooms.Where(r => r.RoomID == @new.roomID).FirstOrDefault(),
                 Day       = @new.day,
                 HourInit  = @new.FechaInit,
                 HourUntil = @new.FechaFin
             });
             context.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
コード例 #4
0
 public object Post(PeriodoDTO @newPeriodo)
 {
     using (var context = new AcademicSystemContext())
     {
         var incompletos = context.Periodos.Where(p => p.Status == SchemaTypes.PeriodStatus.En_Curso).ToList();
         if (incompletos.Count > 0)
         {
             foreach (var periodo in incompletos)
             {
                 periodo.Status = SchemaTypes.PeriodStatus.Completado;
             }
         }
         var newP = new Periodo
         {
             fechaFin               = newPeriodo.fechaFin,
             fechaInicio            = newPeriodo.fechaInicio,
             fechaInicioPreselecion = newPeriodo.fechaInicioPreselecion,
             fechafinPreseleccion   = newPeriodo.fechafinPreseleccion,
             fechainicioSeleccion   = newPeriodo.fechainicioSeleccion,
             fechaLimiteRetiro      = newPeriodo.fechaLimiteRetiro,
             fechafinSeleccion      = newPeriodo.fechafinSeleccion,
             Status = SchemaTypes.PeriodStatus.En_Curso
         };
         context.Periodos.Add(newP);
         context.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.Created, newP.PeriodoID));
     }
 }
コード例 #5
0
        public object FillDB()
        {
            string[] ppName = { "Abbott", "Acevedo", "Acosta", "Adams", "Adkins", "Aguilar", "Aguirre", "Albert", "Alexander", "Alford", "Allen", "Allison", "Alston", "Alvarado", "Alvarez", "Anderson", "Andrews", "Anthony", "Armstrong", "Arnold", "Ashley", "Atkins", "Atkinson", "Austin", "Avery", "Avila", "Ayala", "Ayers", "Bailey", "Baird", "Baker", "Baldwin", "Ball", "Ballard", "Banks", "Barber", "Barker", "Barlow", "Barnes", "Barnett", "Barr", "Barrera", "Barrett", "Barron", "Barry", "Bartlett", "Barton", "Bass", "Bates", "Battle", "Bauer", "Baxter", "Beach", "Bean", "Beard", "Beasley", "Beck", "Becker", "Bell", "Bender", "Benjamin", "Bennett", "Benson", "Bentley", "Benton", "Berg", "Berger", "Bernard", "Berry", "Best", "Bird", "Bishop", "Black", "Blackburn", "Blackwell", "Blair", "Blake", "Blanchard", "Blankenship", "Blevins", "Bolton", "Bond", "Bonner", "Booker", "Boone", "Booth", "Bowen", "Bowers", "Bowman", "Boyd", "Boyer", "Boyle", "Bradford", "Bradley", "Bradshaw", "Brady", "Branch", "Bray", "Brennan", "Brewer", "Bridges", "Briggs", "Bright", "Britt", "Brock", "Brooks", "Brown", "Browning", "Bruce", "Bryan", "Bryant", "Buchanan", "Buck", "Buckley", "Buckner", "Bullock", "Burch", "Burgess", "Burke", "Burks", "Burnett", "Burns", "Burris", "Burt", "Burton", "Bush", "Butler", "Byers", "Byrd", "Cabrera", "Cain", "Calderon", "Caldwell", "Calhoun", "Callahan", "Camacho", "Cameron", "Campbell", "Campos", "Cannon", "Cantrell", "Cantu", "Cardenas", "Carey", "Carlson", "Carney", "Carpenter", "Carr", "Carrillo", "Carroll", "Carson", "Carter", "Carver", "Case", "Casey", "Cash", "Castaneda", "Castillo", "Castro", "Cervantes", "Chambers", "Chan", "Chandler", "Chaney", "Chang", "Chapman", "Charles", "Chase", "Chavez", "Chen", "Cherry", "Christensen", "Christian", "Church", "Clark", "Clarke", "Clay", "Clayton", "Clements", "Clemons", "Cleveland", "Cline", "Cobb", "Cochran", "Coffey", "Cohen", "Cole", "Coleman", "Collier", "Collins", "Colon", "Combs", "Compton", "Conley", "Conner", "Conrad", "Contreras", "Conway", "Cook", "Cooke", "Cooley", "Cooper", "Copeland", "Cortez", "Cote", "Cotton", "Cox", "Craft", "Craig", "Crane", "Crawford", "Crosby", "Cross", "Cruz", "Cummings", "Cunningham", "Curry", "Curtis", "Dale", "Dalton", "Daniel", "Daniels", "Daugherty", "Davenport", "David", "Davidson", "Davis", "Dawson", "Day", "Dean", "Decker", "Dejesus", "Delacruz", "Delaney", "Deleon", "Delgado", "Dennis", "Diaz", "Dickerson", "Dickson", "Dillard", "Dillon", "Dixon", "Dodson", "Dominguez", "Donaldson", "Donovan", "Dorsey", "Dotson", "Douglas", "Downs", "Doyle", "Drake", "Dudley", "Duffy", "Duke", "Duncan", "Dunlap", "Dunn", "Duran", "Durham", "Dyer", "Eaton", "Edwards", "Elliott", "Ellis", "Ellison", "Emerson", "England", "English", "Erickson", "Espinoza", "Estes", "Estrada", "Evans", "Everett", "Ewing", "Farley", "Farmer", "Farrell", "Faulkner", "Ferguson", "Fernandez", "Ferrell", "Fields", "Figueroa", "Finch", "Finley", "Fischer", "Fisher", "Fitzgerald", "Fitzpatrick", "Fleming", "Fletcher", "Flores", "Flowers", "Floyd", "Flynn", "Foley", "Forbes", "Ford", "Foreman", "Foster", "Fowler", "Fox", "Francis", "Franco", "Frank", "Franklin", "Franks", "Frazier", "Frederick", "Freeman", "French", "Frost", "Fry", "Frye", "Fuentes", "Fuller", "Fulton", "Gaines", "Gallagher", "Gallegos", "Galloway", "Gamble", "Garcia", "Gardner", "Garner", "Garrett", "Garrison", "Garza", "Gates", "Gay", "Gentry", "George", "Gibbs", "Gibson", "Gilbert", "Giles", "Gill", "Gillespie", "Gilliam", "Gilmore", "Glass", "Glenn", "Glover", "Goff", "Golden", "Gomez", "Gonzales", "Gonzalez", "Good", "Goodman", "Goodwin", "Gordon", "Gould", "Graham", "Grant", "Graves", "Gray", "Green", "Greene", "Greer", "Gregory", "Griffin", "Griffith", "Grimes", "Gross", "Guerra", "Guerrero", "Guthrie", "Gutierrez", "Guy", "Guzman", "Hahn", "Hale", "Haley", "Hall", "Hamilton", "Hammond", "Hampton", "Hancock", "Haney", "Hansen", "Hanson", "Hardin", "Harding", "Hardy", "Harmon", "Harper", "Harrell", "Harrington", "Harris", "Harrison", "Hart", "Hartman", "Harvey", "Hatfield", "Hawkins", "Hayden", "Hayes", "Haynes", "Hays", "Head", "Heath", "Hebert", "Henderson", "Hendricks", "Hendrix", "Henry", "Hensley", "Henson", "Herman", "Hernandez", "Herrera", "Herring", "Hess", "Hester", "Hewitt", "Hickman", "Hicks", "Higgins", "Hill", "Hines", "Hinton", "Hobbs", "Hodge", "Hodges", "Hoffman", "Hogan", "Holcomb", "Holden", "Holder", "Holland", "Holloway", "Holman", "Holmes", "Holt", "Hood", "Hooper", "Hoover", "Hopkins", "Hopper", "Horn", "Horne", "Horton", "House", "Houston", "Howard", "Howe", "Howell", "Hubbard", "Huber", "Hudson", "Huff", "Huffman", "Hughes", "Hull", "Humphrey", "Hunt", "Hunter", "Hurley", "Hurst", "Hutchinson", "Hyde", "Ingram", "Irwin", "Jackson", "Jacobs", "Jacobson", "James", "Jarvis", "Jefferson", "Jenkins", "Jennings", "Jensen", "Jimenez", "Johns", "Johnson", "Johnston", "Jones", "Jordan", "Joseph", "Joyce", "Joyner", "Juarez", "Justice", "Kane", "Kaufman", "Keith", "Keller", "Kelley", "Kelly", "Kemp", "Kennedy", "Kent", "Kerr", "Key", "Kidd", "Kim", "King", "Kinney", "Kirby", "Kirk", "Kirkland", "Klein", "Kline", "Knapp", "Knight", "Knowles", "Knox", "Koch", "Kramer", "Lamb", "Lambert", "Lancaster", "Landry", "Lane", "Lang", "Langley", "Lara", "Larsen", "Larson", "Lawrence", "Lawson", "Le", "Leach", "Leblanc", "Lee", "Leon", "Leonard", "Lester", "Levine", "Levy", "Lewis", "Lindsay", "Lindsey", "Little", "Livingston", "Lloyd", "Logan", "Long", "Lopez", "Lott", "Love", "Lowe", "Lowery", "Lucas", "Luna", "Lynch", "Lynn", "Lyons", "Macdonald", "Macias", "Mack", "Madden", "Maddox", "Maldonado", "Malone", "Mann", "Manning", "Marks", "Marquez", "Marsh", "Marshall", "Martin", "Martinez", "Mason", "Massey", "Mathews", "Mathis", "Matthews", "Maxwell", "May", "Mayer", "Maynard", "Mayo", "Mays", "Mcbride", "Mccall", "Mccarthy", "Mccarty", "Mcclain", "Mcclure", "Mcconnell", "Mccormick", "Mccoy", "Mccray", "Mccullough", "Mcdaniel", "Mcdonald", "Mcdowell", "Mcfadden", "Mcfarland", "Mcgee", "Mcgowan", "Mcguire", "Mcintosh", "Mcintyre", "Mckay", "Mckee", "Mckenzie", "Mckinney", "Mcknight", "Mclaughlin", "Mclean", "Mcleod", "Mcmahon", "Mcmillan", "Mcneil", "Mcpherson", "Meadows", "Medina", "Mejia", "Melendez", "Melton", "Mendez", "Mendoza", "Mercado", "Mercer", "Merrill", "Merritt", "Meyer", "Meyers", "Michael", "Middleton", "Miles", "Miller", "Mills", "Miranda", "Mitchell", "Molina", "Monroe", "Montgomery", "Montoya", "Moody", "Moon", "Mooney", "Moore", "Morales", "Moran", "Moreno", "Morgan", "Morin", "Morris", "Morrison", "Morrow", "Morse", "Morton", "Moses", "Mosley", "Moss", "Mueller", "Mullen", "Mullins", "Munoz", "Murphy", "Murray", "Myers", "Nash", "Navarro", "Neal", "Nelson", "Newman", "Newton", "Nguyen", "Nichols", "Nicholson", "Nielsen", "Nieves", "Nixon", "Noble", "Noel", "Nolan", "Norman", "Norris", "Norton", "Nunez", "Obrien", "Ochoa", "Oconnor", "Odom", "Odonnell", "Oliver", "Olsen", "Olson", "Oneal", "Oneil", "Oneill", "Orr", "Ortega", "Ortiz", "Osborn", "Osborne", "Owen", "Owens", "Pace", "Pacheco", "Padilla", "Page", "Palmer", "Park", "Parker", "Parks", "Parrish", "Parsons", "Pate", "Patel", "Patrick", "Patterson", "Patton", "Paul", "Payne", "Pearson", "Peck", "Pena", "Pennington", "Perez", "Perkins", "Perry", "Peters", "Petersen", "Peterson", "Petty", "Phelps", "Phillips", "Pickett", "Pierce", "Pittman", "Pitts", "Pollard", "Poole", "Pope", "Porter", "Potter", "Potts", "Powell", "Powers", "Pratt", "Preston", "Price", "Prince", "Pruitt", "Puckett", "Pugh", "Quinn", "Ramirez", "Ramos", "Ramsey", "Randall", "Randolph", "Rasmussen", "Ratliff", "Ray", "Raymond", "Reed", "Reese", "Reeves", "Reid", "Reilly", "Reyes", "Reynolds", "Rhodes", "Rice", "Rich", "Richard", "Richards", "Richardson", "Richmond", "Riddle", "Riggs", "Riley", "Rios", "Rivas", "Rivera", "Rivers", "Roach", "Robbins", "Roberson", "Roberts", "Robertson", "Robinson", "Robles", "Rocha", "Rodgers", "Rodriguez", "Rodriquez", "Rogers", "Rojas", "Rollins", "Roman", "Romero", "Rosa", "Rosales", "Rosario", "Rose", "Ross", "Roth", "Rowe", "Rowland", "Roy", "Ruiz", "Rush", "Russell", "Russo", "Rutledge", "Ryan", "Salas", "Salazar", "Salinas", "Sampson", "Sanchez", "Sanders", "Sandoval", "Sanford", "Santana", "Santiago", "Santos", "Sargent", "Saunders", "Savage", "Sawyer", "Schmidt", "Schneider", "Schroeder", "Schultz", "Schwartz", "Scott", "Sears", "Sellers", "Serrano", "Sexton", "Shaffer", "Shannon", "Sharp", "Sharpe", "Shaw", "Shelton", "Shepard", "Shepherd", "Sheppard", "Sherman", "Shields", "Short", "Silva", "Simmons", "Simon", "Simpson", "Sims", "Singleton", "Skinner", "Slater", "Sloan", "Small", "Smith", "Snider", "Snow", "Snyder", "Solis", "Solomon", "Sosa", "Soto", "Sparks", "Spears", "Spence", "Spencer", "Stafford", "Stanley", "Stanton", "Stark", "Steele", "Stein", "Stephens", "Stephenson", "Stevens", "Stevenson", "Stewart", "Stokes", "Stone", "Stout", "Strickland", "Strong", "Stuart", "Suarez", "Sullivan", "Summers", "Sutton", "Swanson", "Sweeney", "Sweet", "Sykes", "Talley", "Tanner", "Tate", "Taylor", "Terrell", "Terry", "Thomas", "Thompson", "Thornton", "Tillman", "Todd", "Torres", "Townsend", "Tran", "Travis", "Trevino", "Trujillo", "Tucker", "Turner", "Tyler", "Tyson", "Underwood", "Valdez", "Valencia", "Valentine", "Valenzuela", "Vance", "Vang", "Vargas", "Vasquez", "Vaughan", "Vaughn", "Vazquez", "Vega", "Velasquez", "Velazquez", "Velez", "Villarreal", "Vincent", "Vinson", "Wade", "Wagner", "Walker", "Wall", "Wallace", "Waller", "Walls", "Walsh", "Walter", "Walters", "Walton", "Ward", "Ware", "Warner", "Warren", "Washington", "Waters", "Watkins", "Watson", "Watts", "Weaver", "Webb", "Weber", "Webster", "Weeks", "Weiss", "Welch", "Wells", "West", "Wheeler", "Whitaker", "White", "Whitehead", "Whitfield", "Whitley", "Whitney", "Wiggins", "Wilcox", "Wilder", "Wiley", "Wilkerson", "Wilkins", "Wilkinson", "William", "Williams", "Williamson", "Willis", "Wilson", "Winters", "Wise", "Witt", "Wolf", "Wolfe", "Wong", "Wood", "Woodard", "Woods", "Woodward", "Wooten", "Workman", "Wright", "Wyatt", "Wynn", "Yang", "Yates", "York", "Young", "Zamora", "Zimmerman" };
            using (var context = new AcademicSystemContext())
            {
                for (int i = 0; i < 150000; i++)
                {
                    Random r     = new Random();
                    int    rInt  = r.Next(0, ppName.Length); //for ints
                    int    rInt2 = r.Next(0, ppName.Length); //for ints
                    int    rInt3 = r.Next(0, ppName.Length); //for ints

                    context.Usuarios.Add(new Classes.User
                    {
                        Name               = ppName[rInt],
                        BirthDate          = DateTime.Now,
                        Sex                = FixedValues.sex.Femenine,
                        Email              = ppName[rInt] + i.ToString() + "*****@*****.**",
                        LastName           = ppName[rInt2],
                        Name2              = ppName[rInt3],
                        PhoneNum           = rInt + rInt2 + rInt3 + i,
                        UserType           = SchemaTypes.UserTypes.Student,
                        ProfilePicturePath = "/UsersData/17/images.png",
                        Password           = "******"
                    });

                    if (i == 5000 || i == 10000 || i == 10000 * 2 || i == 10000 * 3 || i == 10000 * 4 || i == 10000 * 5 || i == 10000 * 6 || i == 10000 * 7 || i == 10000 * 8 || i == 10000 * 9 || i == 10000 * 10)
                    {
                        context.SaveChanges();
                    }
                }
                context.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
コード例 #6
0
        public HttpResponseMessage ChangeProfilePicture(int userId)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            try
            {
                var httpRequest = HttpContext.Current.Request;
                foreach (string file in httpRequest.Files)
                {
                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
                    var postedFile = httpRequest.Files[file];
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        int MaxContentLength = 1024 * 1024 * 1; //Size = 1 MB

                        IList <string> AllowedFileExtensions = new List <string> {
                            ".jpg", ".gif", ".png"
                        };
                        var ext       = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
                        var extension = ext.ToLower();
                        if (!AllowedFileExtensions.Contains(extension))
                        {
                            var message = string.Format("Please Upload image of type .jpg,.gif,.png.");
                            dict.Add("error", message);
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, dict));
                        }
                        else if (postedFile.ContentLength > MaxContentLength)
                        {
                            var message = string.Format("Please Upload a file upto 1 mb.");
                            dict.Add("error", message);
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, dict));
                        }
                        else
                        {
                            string Foldername       = "~/UsersData/" + userId;
                            string MappedFoldername = HostingEnvironment.MapPath(Foldername);
                            Directory.CreateDirectory(MappedFoldername);
                            var filePath = HttpContext.Current.Server.MapPath(Foldername + '/' + postedFile.FileName);
                            postedFile.SaveAs(filePath);
                            using (var context = new AcademicSystemContext())
                            {
                                var USER = context.Usuarios.Where(u => u.UserId == userId).FirstOrDefault();
                                USER.ProfilePicturePath = "/UsersData/" + userId + "/" + postedFile.FileName;
                                context.SaveChanges();
                                return(Request.CreateResponse(HttpStatusCode.OK, USER.ProfilePicturePath));
                            }
                        }
                    }
                    var message1 = string.Format("Image Updated Successfully.");
                    return(Request.CreateErrorResponse(HttpStatusCode.OK, message1));;
                }
                var res = string.Format("Please Upload a image.");
                dict.Add("error", res);
                return(Request.CreateResponse(HttpStatusCode.NotFound, dict));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, dict));
            }
        }
コード例 #7
0
 public object fetchUsers(string query)
 {
     using (var context = new AcademicSystemContext())
     {
         var data = context.Usuarios
                    .Where(u =>
                           (u.Name + u.Email + u.UserId.ToString() + u.Name2 + u.LastName).Contains(query)
                           )
                    .Take(50)
                    .Select(d => new
         {
             nombre     = d.Name + " " + d.Name2,
             apellido   = d.LastName,
             id         = d.UserId,
             profilepic = d.ProfilePicturePath,
             tipo       = d.UserType == SchemaTypes.UserTypes.Student ? "Est."
                                                      : d.UserType == SchemaTypes.UserTypes.Teacher ? "Prof."
                                                      : "Admin",
             carrera = context.StudentMajors
                       .Where(m => m.Student.UserId == d.UserId)
                       .OrderBy(o => o.InitDate)
                       .Select(op => new
             {
                 titulo = op.Major.MajorTitle,
                 inicio = op.InitDate
             })
                       .FirstOrDefault()
         }).ToList();
         return(data);
     }
 }
コード例 #8
0
 public HttpResponseMessage createAsignatura(AsignaturaDTO @new)
 {
     try
     {
         using (var c = new AcademicSystemContext())
         {
             c.Asignaturas.Add(new Asignatura
             {
                 Credits        = @new.Creditos,
                 Name           = @new.NombreAsignatura,
                 TipoAsignatura = @new.TipoAsignatura,
                 Codigo         = @new.Codigo
             });
             c.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Created));
         }
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             return(Request.CreateResponse(HttpStatusCode.InternalServerError));
         }
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
コード例 #9
0
 public object fetchUser(int userId)
 {
     using (var c = new AcademicSystemContext())
     {
         return(c.Usuarios.Where(u => u.UserId == userId)
                .Select(d => new
         {
             d.Name,
             d.Name2,
             d.LastName,
             d.Email,
             d.BirthDate,
             d.PhoneNum,
             d.UserType,
             d.ProfilePicturePath,
             isActive = c.StudentMajors.Any(sm => sm.Student.UserId == d.UserId && sm.Status == SchemaTypes.StudentMajorStatus.Cursando),
             carreras = c.StudentMajors
                        .Where(sm => sm.Student.UserId == d.UserId)
                        .Select(data => new
             {
                 carrera = data.Major.MajorTitle,
                 status = data.Status,
                 indice = data.GPA,
                 inicio = data.InitDate,
                 fin = data.FinDate
             }).ToList()
         }).FirstOrDefault());
     }
 }
コード例 #10
0
 public object getAsignatura(int id)
 {
     using (var c = new AcademicSystemContext())
     {
         return(c.Asignaturas
                .Where(a => a.AsignatureID == id)
                .Select(s => new
         {
             s.Codigo,
             s.Credits,
             s.Name,
             s.TipoAsignatura,
             teachers = c.AsignatureTeachers
                        .Where(at => at.Asignatura.AsignatureID == s.AsignatureID)
                        .Select(data => new
             {
                 asignID = data.id,
                 data.AsignDate,
                 teacherID = data.Teacher.UserId,
                 Teacher = data.Teacher.Name + " " + data.Teacher.Name2 + " " + data.Teacher.LastName
             }).ToList()
         })
                .FirstOrDefault());
     }
 }
コード例 #11
0
        public object fetchAsignaturas(string query)
        {
            using (var context = new AcademicSystemContext())
            {
                var d = context.Asignaturas
                        .Where(ad => ad.Name.Contains(query) || ad.Codigo.Contains(query))

                        .Select(a => new
                {
                    Nombre   = a.Name,
                    Creditos = a.Credits,
                    ID       = a.AsignatureID,
                    Tipo     = a.TipoAsignatura,
                    codigo   = a.Codigo
                }).Select(dd => new
                {
                    nombre   = dd.Nombre,
                    tipo     = (dd.Tipo == 0) ? "Laboratorio" : "Teoria",
                    id       = dd.ID,
                    creditos = dd.Creditos,
                    codigo   = dd.codigo
                }).ToList();
                return(d);
            }
        }
コード例 #12
0
 public object getCurrent()
 {
     using (var context = new AcademicSystemContext())
     {
         return(context.Periodos.Where(p => p.Status == SchemaTypes.PeriodStatus.En_Curso).First());
     }
 }
コード例 #13
0
        public object getStudentDashboard(int id)
        {
            using (var context = new AcademicSystemContext())
            {
                var data = context.Usuarios.Where(u => u.UserId == id && u.UserType == SchemaTypes.UserTypes.Student)
                           .Select(d => new
                {
                    periodosCursados     = context.StudentsHistories.GroupBy(g => g.Asignatura.Periodo.PeriodoID).Count(),
                    asignaturasAprobadas = context.StudentsHistories.Where(h => h.Status == SchemaTypes.HistorialStatus.Aprobada).Count(),
                    programa             = context.StudentMajors
                                           .Where(m => m.Student.UserId == id && m.Status == SchemaTypes.StudentMajorStatus.Cursando)
                                           .FirstOrDefault(),

                    programaMajor = context.StudentMajors
                                    .Where(m => m.Student.UserId == id && m.Status == SchemaTypes.StudentMajorStatus.Cursando)
                                    .FirstOrDefault().Major,
                    ultimaCondicion = context.StudentsHistories
                                      .OrderByDescending(o => o.Asignatura.Periodo.fechaFin)
                                      .Take(1)
                                      .FirstOrDefault().Asignatura.Periodo
                }).FirstOrDefault();



                return(data);
            }
        }
コード例 #14
0
        public object getContext()
        {
            try
            {
                int userID = int.Parse(Thread.CurrentPrincipal.Identity.Name);
                using (var context = new AcademicSystemContext())
                {
                    var identity = context.Usuarios.Where(u => u.UserId == userID).Select(d => new
                    {
                        idusuario          = d.UserId,
                        nombre             = d.Name,
                        apellido           = d.LastName,
                        tipousuario        = d.UserType,
                        profilePicturePath = d.ProfilePicturePath
                    }).First();

                    if (identity.tipousuario == SchemaTypes.UserTypes.Student)
                    {
                        var studentDash = getStudentDashboard(identity.idusuario);
                        return(new { identity, studentDash });
                    }

                    return(identity);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #15
0
        public object getSection(int id)
        {
            using (var context = new AcademicSystemContext())
            {
                var QuerySet = context.PeriodAsignature
                               .Where(p => p.PeriodAsignatureID == id)
                               .Select(D => new
                {
                    PeriodoID   = D.Periodo.PeriodoID,
                    fechaInicio = D.Periodo.fechaInicio,
                    fechaFin    = D.Periodo.fechaFin,

                    seccion        = D.seccion,
                    profesor       = D.Profesor.Name + " " + D.Profesor.Name2 + " " + D.Profesor.LastName,
                    profesorID     = D.Profesor.UserId,
                    Asignatura     = D.Asignatura.Codigo,
                    AsignaturaName = D.Asignatura.Name,
                })

                               .OrderBy(a => a.Asignatura)
                               .OrderBy(a => a.seccion)
                               .Select(D => new
                {
                    Periodo    = D.PeriodoID,
                    PInicio    = D.fechaInicio,
                    PFin       = D.fechaFin,
                    seccion    = (D.seccion < 10) ? "0" + D.seccion.ToString() : D.seccion.ToString(),
                    profesor   = D.profesor,
                    profesorID = D.profesorID,
                    Asignatura = D.Asignatura,

                    AsignaturaName = D.AsignaturaName
                }).ToList();

                var Horarios = context.Horarios.Where(H => H.Asignatura.PeriodAsignatureID == id).ToList();

                var EstudiantesInscritos = context
                                           .StudentsHistories
                                           .Where(s => s.Asignatura.PeriodAsignatureID == id)
                                           .Select(d => new
                {
                    NombreEst   = d.StudentMajor.Student.Name + " " + d.StudentMajor.Student.Name2 + " " + d.StudentMajor.Student.LastName,
                    IdEst       = d.StudentMajor.Student.UserId,
                    FotoEst     = d.StudentMajor.Student.ProfilePicturePath,
                    CarreraEst  = d.StudentMajor.Major.MajorTitle,
                    idHistorial = d.HistoryLineId
                })
                                           .ToList();

                var data = new
                {
                    QuerySet,
                    Horarios,
                    EstudiantesInscritos
                };

                return(data);
            }
        }
コード例 #16
0
 public object DeleteTeacher(int asignid)
 {
     using (var context = new AcademicSystemContext())
     {
         context.AsignatureTeachers.Remove(context.AsignatureTeachers.Where(at => at.id == asignid).FirstOrDefault());
         context.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
 }
コード例 #17
0
 public HttpStatusCode deletePensumLine(int id)
 {
     using (var context = new AcademicSystemContext())
     {
         context.Pensums.Remove(context.Pensums.Where(p => p.PensumID == id).FirstOrDefault());
         context.SaveChanges();
         return(HttpStatusCode.OK);
     }
 }
コード例 #18
0
 // GET: api/SeccionesDePeriodos/5
 public IEnumerable <object> Get(int id)
 {
     using (var context = new AcademicSystemContext())
     {
         return(context
                .PeriodAsignature
                .Where(p => p.Periodo.PeriodoID == id)
                .ToList());
     }
 }
コード例 #19
0
 public object conclude(int id)
 {
     using (var context = new AcademicSystemContext())
     {
         context.Periodos
         .Where(p => p.PeriodoID == id).FirstOrDefault()
         .Status = SchemaTypes.PeriodStatus.Completado;
         context.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
 }
コード例 #20
0
        public object fetchStudents(string query, int seccionID)
        {
            using (var context = new AcademicSystemContext())
            {
                var d = context.StudentMajors
                        .Where
                        (
                    sm => sm.Status == SchemaTypes.StudentMajorStatus.Cursando
                    &&
                    (sm.Student.Name + sm.Student.Email + sm.Student.UserId.ToString() + sm.Student.Name2 + sm.Student.LastName).Contains(query)

                    &&
                    // Que el estudiante no este ya inscrito en la seccion
                    !context
                    .StudentsHistories
                    .Any(v => (v.Asignatura.PeriodAsignatureID == seccionID && v.StudentMajor.Student.UserId == sm.Student.UserId))
                    &&
                    // Que el estudiante no este inscrito en ninguna otra seccion de esa materia
                    !context.StudentsHistories
                    .Any(
                        v => v.StudentMajor.Student.UserId == sm.Student.UserId
                        &&
                        v.Asignatura.Asignatura.AsignatureID ==
                        context.PeriodAsignature.Where(s => s.PeriodAsignatureID == seccionID)
                        .FirstOrDefault()
                        .Asignatura
                        .AsignatureID
                        // Solo toma en cuenta los historicos que estan en curso.
                        &&
                        v.Status == SchemaTypes.HistorialStatus.En_Curso
                        )
                        )
                        .Select(u => new
                {
                    nombre     = u.Student.Name + " " + u.Student.Name2,
                    apellido   = u.Student.LastName,
                    id         = u.Student.UserId,
                    profilepic = u.Student.ProfilePicturePath,
                    carrera    = context.StudentMajors
                                 .Where(m => m.Student.UserId == u.Student.UserId)
                                 .OrderBy(o => o.InitDate)
                                 .Select(op => new
                    {
                        titulo = op.Major.MajorTitle,
                        inicio = op.InitDate
                    })
                                 .FirstOrDefault()
                }).ToList();

                return(d);
            }
        }
コード例 #21
0
 public object getStudentsMajors(int id)
 {
     using (var context = new AcademicSystemContext())
     {
         return(context.StudentMajors
                .Where(sm => sm.Student.UserId == id)
                .Select(d => new
         {
             name = d.Major.MajorTitle,
             id = d.Major.MajorID,
         }).ToList());
     }
 }
コード例 #22
0
 public object getAsignatureTeachers(int id)
 {
     using (var context = new AcademicSystemContext())
     {
         return(context.AsignatureTeachers.Where(a => a.Asignatura.AsignatureID == id).Select(d => new
         {
             d.Teacher.UserId,
             d.Teacher.Name,
             d.Teacher.Name2,
             d.Teacher.LastName
         }).ToList());
     }
 }
コード例 #23
0
        public object BorrarEstudiante(int id)
        {
            using (var context = new AcademicSystemContext())
            {
                var SH = context.StudentsHistories
                         .Where(sh => sh.HistoryLineId == id)
                         .FirstOrDefault();

                context.StudentsHistories.Remove(SH);
                context.SaveChanges();
                return(HttpStatusCode.OK);
            }
        }
コード例 #24
0
 public HttpStatusCode addPensumLine(pensumLineDTO PensumLine)
 {
     using (var context = new AcademicSystemContext())
     {
         context.Pensums.Add(new Pensum
         {
             Asignatura     = context.Asignaturas.Where(a => a.AsignatureID == PensumLine.AsignaturaID).FirstOrDefault(),
             Major          = context.Majors.Where(m => m.MajorID == PensumLine.MajorID).FirstOrDefault(),
             TrimestreOrder = 1
         });
         context.SaveChanges();
         return(HttpStatusCode.OK);
     }
 }
コード例 #25
0
 public object fetchAsignatures(string query)
 {
     using (var context = new AcademicSystemContext())
     {
         return(context.Asignaturas.Where(a =>
                                          (a.Codigo + a.Name).Contains(query)).Select(d => new
         {
             codigo = d.Codigo,
             nombre = d.Name,
             creditos = d.Credits,
             id = d.AsignatureID
         }).ToList());
     }
 }
コード例 #26
0
 public object PostLine(PreseleccionDTO @new)
 {
     using (var context = new AcademicSystemContext())
     {
         int currP = context.Periodos.Where(p => p.Status == SchemaTypes.PeriodStatus.En_Curso).First().PeriodoID;
         context.Preselecciones.Add(new Preseleccion
         {
             Asignatura   = context.PeriodAsignature.Where(p => p.Periodo.PeriodoID == currP && p.Asignatura.AsignatureID == @new.AsignatureID).First(),
             Student      = context.Usuarios.Where(u => u.UserId == @new.userID).First(),
             TandaDeseada = @new.Tanda
         });
         context.SaveChanges();
     }
     return(HttpStatusCode.OK);
 }
コード例 #27
0
 public object inscribirEst(InscripcionDTO @new)
 {
     using (var context = new AcademicSystemContext())
     {
         PeriodAsignature sec = context.PeriodAsignature.Where(p => p.PeriodAsignatureID == @new.periodSeccionID).FirstOrDefault();
         context.StudentsHistories.Add(new StudentHistory
         {
             Asignatura   = sec,
             StudentMajor = context.StudentMajors.Where(s => s.Student.UserId == @new.estudentID && s.Status == SchemaTypes.StudentMajorStatus.Cursando).First(),
             Status       = SchemaTypes.HistorialStatus.En_Curso
         });
         context.SaveChanges();
     }
     return(Request.CreateResponse(HttpStatusCode.Created));
 }
コード例 #28
0
 public object GetOferta(int id)
 {
     using (var context = new AcademicSystemContext())
     {
         var querySet = context.Database.SqlQuery <ofertaDTO>(
             "SELECT [Asignatura_AsignatureID] as 'id',[Name], [Codigo]"
             + "FROM [dbo].[PeriodAsignatures] "
             + "JOIN [dbo].[Asignaturas] "
             + "ON [Asignatura_AsignatureID] = [AsignatureID] "
             + "WHERE [Periodo_PeriodoID] = " + id.ToString()
             + " GROUP BY [Asignatura_AsignatureID],[Name] ,[Codigo]"
             );
         var result = querySet.ToList();
         return(result);
     }
 }
コード例 #29
0
 public object getPeriods(string Query)
 {
     using (var context = new AcademicSystemContext())
     {
         var ResultSet = context.Periodos
                         .Where(p => p.fechaInicio.ToString().Contains(Query) || p.fechaFin.ToString().Contains(Query))
                         .Select(d => new
         {
             d.PeriodoID,
             d.fechaInicio,
             d.fechaFin
         })
                         .ToList();
         return(ResultSet);
     }
 }
コード例 #30
0
 public object Post(StudentMajorDTO @new)
 {
     using (var context = new AcademicSystemContext())
     {
         StudentMajor newSM = new StudentMajor();
         newSM.Student = context.Usuarios
                         .Where(u => u.UserId == @new.StudentID)
                         .FirstOrDefault();
         newSM.InitDate = DateTime.Now;
         newSM.Status   = SchemaTypes.StudentMajorStatus.Cursando;
         newSM.Major    = context.Majors.Where(m => m.MajorID == @new.MajorID).FirstOrDefault();
         newSM.GPA      = 0;
         context.StudentMajors.Add(newSM);
         context.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
 }