コード例 #1
0
ファイル: MethodRepository.cs プロジェクト: proxy51/LMS
 internal List<Class> GetClasses(User currentUser)
 {
     return currentUser.Classes.ToList();
 }
コード例 #2
0
ファイル: MethodRepository.cs プロジェクト: proxy51/LMS
 internal int Redo(int stateId, User teacher)
 {
     db.States.Find(stateId).HandedIn = false;
     db.States.Find(stateId).Redo = true;
     db.SaveChanges();
     State state = db.States.Find(stateId);
     TaskItem task = db.Tasks.Single(t => t.States.Select(s => s.Id).Contains(stateId));
     Class zeClass = GetClass(db.Schedule.Single(s => s.TaskId == task.Id).ClassId);
     var dir = new System.IO.DirectoryInfo(Path.Combine(HttpRuntime.AppDomainAppPath, "/UploadedFiles/", zeClass.TaskPath, task.Code));
     string userName = db.Users.Single(u => u.Id == state.UserId).UserName;
     string filePath = dir.GetFiles("*" + userName)[0].FullName;
     if (System.IO.File.Exists(filePath))
     {
         System.IO.File.Delete(filePath);
     }
     string message = "You have not recieved a passing grade on the task " + db.Tasks.Single(t => t.States.Select(s => s.Id).Contains(stateId)).Name + ", and need to submit a new file for re-examination.";
     repo.SendMessage(message, db.States.Find(stateId).UserId, teacher);
     return db.Tasks.Single(t => t.States.Select(s => s.Id).Contains(stateId)).Id;
 }
コード例 #3
0
ファイル: MethodRepository.cs プロジェクト: proxy51/LMS
        internal filelist GetClassSharedFiles(User user, Class userclass)
        {
            filelist myList = new filelist();
            List<Class> userclasses = GetClasses(user);


            string pathextension = userclass.SharedPath;
            var dir = new System.IO.DirectoryInfo(Path.Combine(HttpRuntime.AppDomainAppPath, "/UploadedFiles/", pathextension));
            List<System.IO.FileInfo> filenames = dir.GetFiles("*.*").ToList();

            var results = from f in filenames
                          select new filelistviewmodel()
                          {
                              filename = f.Name,
                              filecreation = f.CreationTimeUtc,
                              filepath = f.FullName,

                          };
            foreach (var item in results)
            {
                myList.SharedFilelist.Add(item);
            }
            return myList;
        }
コード例 #4
0
ファイル: MethodRepository.cs プロジェクト: proxy51/LMS
 internal UserTaskViewModel GetStudentTask(int taskId, User currentUser)
 {
     var userid = currentUser.Id;
     TaskItem task = db.Tasks.Find(taskId);
     State state = task.States.Single(s => s.UserId == userid);
     DateTime deadline = db.Schedule.Single(s => s.TaskId == taskId).StopTime;
     return new UserTaskViewModel(task, state, deadline);
 }
コード例 #5
0
ファイル: MethodRepository.cs プロジェクト: proxy51/LMS
 internal int PassStudent(int stateId, User teacher)
 {
     db.States.Find(stateId).Passed = true;
     db.States.Find(stateId).Redo = false;
     db.SaveChanges();
     string message = "You have recieved a passing grade on the task " + db.Tasks.Single(t => t.States.Select(s => s.Id).Contains(stateId)).Name + ".";
     repo.SendMessage(message, db.States.Find(stateId).UserId, teacher);
     return db.Tasks.Single(t => t.States.Select(s => s.Id).Contains(stateId)).Id;
 }
コード例 #6
0
ファイル: MethodRepository.cs プロジェクト: proxy51/LMS
 internal List<ScheduleItem> GetSchedule(int? classId, User currentUser)
 {
     List<ScheduleItem> schedule;
     if (classId == null)
     {
         schedule = new List<ScheduleItem>();
         foreach (Class cl in currentUser.Classes)
         {
             schedule.AddRange(db.Schedule.Where(s => s.ClassId == cl.Id).ToList());
         }
         return (schedule.OrderBy(s => s.StartTime).ToList());
     }
     return (db.Schedule.OrderBy(s => s.StartTime).Where(s => s.ClassId == classId).ToList());
             
 }
コード例 #7
0
ファイル: MethodRepository.cs プロジェクト: proxy51/LMS
 public int CreateClass(FormCollection collection, User currentUser)
 {
     string name = collection.Get("name");
     string code = collection.Get("code");
     var dir = Path.Combine(HttpRuntime.AppDomainAppPath,"/UploadedFiles/");
     string classpath = dir + code;
     string sharedPath = classpath + "/shared/";
     string taskPath = classpath + "/task/";
     Directory.CreateDirectory(sharedPath);
     Directory.CreateDirectory(taskPath);
     Class zeClass = new Class { Name = name, Code = code, SharedPath = code + "/shared/", TaskPath = code + "/task/", Users = new List<User>() };
     db.Classes.Add(zeClass);
     db.SaveChanges();
     if (collection.Get("teach") == "on")
     {
         Associate(currentUser.Id, zeClass.Id);
     }
     return zeClass.Id;
 }
コード例 #8
0
ファイル: AccountController.cs プロジェクト: proxy51/LMS
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.Email, Email = model.Email, Name = model.Name };
                
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    //Assign Role to user Here 
                    await this.UserManager.AddToRoleAsync(user.Id, model.Userrole);
                    //Ends Here

                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #9
0
ファイル: DocumentCRUD.cs プロジェクト: CasDev/Lexicon_LMS
 public static Document FindAssignment(User user, Activity activity, ApplicationDbContext db, HttpServerUtilityBase server)
 {
     string folder = server.MapPath("~/documents/ovning/" + activity.Id + "/" + user.Id + "/");
     string name = "Inlämning för " + user.FirstName + " " + user.LastName;
     return FindDocument(folder, name, db);
 }
コード例 #10
0
        public ActionResult CreateUser(CreateUserViewModel model)
        {
            // skillnaderna mellan en vymodel såsom LoginViewModel och en FormCollection
            //LoginViewModel Model = new LoginViewModel();
            //
            //if (!ModelState.IsValid)
            //{
            //    // här händer nåt
            //}
            //
            //var epost = Model.Email;
            //var password = Model.Password;
            //bool Remember = Model.RememberMe;
            //
            // med en vymodel så sköter MVC mycket själv.
            // t.ex. denna validering kan lätt ändras till en enkel
            // if (!ModelState.IsValid) {
            // så kontrollerar den ifall vymodel EJ är giltig och sedan får programmeraren
            // göra det som skall, t.ex. skicka tillbaka datat och felmedellandena ( som
            // även sköts av vymodelen )
            //epost = Collection["email"];
            //if (epost.Length > 9)
            //{
            //    // OK
            //}
            //password = Collection["password"];
            //if (password.Length > 9)
            //{
            //    // OK
            //}
            //if (Boolean.TryParse(Collection["RememberMe"], out Remember))
            //{
            //    // OK
            //}
            Menu(Home: true);
            SetBreadcrumbs(
                one: new MenyItem { Link = "~/Teacher/", Text = "Se alla kurser" });

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            bool HasError = false;
            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("ConfirmPassword", "Det konfirmerande lösenordet är ej detsamma som lösenordet du har angett");
                HasError = true;
            }
            if (model.Role != "Teacher" && model.Role != "Student")
            {
                ModelState.AddModelError("Role", "Användare kan enbart vara av roll lärare eller elev");
                HasError = true;
            }
            if (HasError)
            {
                return View(model);
            }

            var uStore = new UserStore<User>(db);
            var uManager = new UserManager<User>(uStore);

            User user = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, UserName = model.Email };
            uManager.Create(user, model.Password);

            user = uManager.FindByName(model.Email);
            uManager.AddToRole(user.Id, model.Role);

            return Redirect("~/Teacher/");
        }