Exemplo n.º 1
0
 public LectureController(IHrManagementRepository repo)
 {
     _repo = repo;
 }
Exemplo n.º 2
0
        public static Lecture CreateLecture(IHrManagementRepository repo, string directory, int category, string lectureTitle, string userId)
        {
            /*still have some work to do, check for thumbs in the folder, handle exercise file when browsing the zip*/

            Lecture lectureToAdd = new Lecture()
            {
                Title        = lectureTitle,
                DateCreated  = DateTime.Now,
                CategoryId   = category,
                AspNetUserId = userId
            };
            Lecture lectureAdded = repo.AddLecture(lectureToAdd, userId);
            string  path         = "Lecture" + lectureAdded.Id;

            try
            {
                DirectoryInfo currentDir = new DirectoryInfo(directory + "/" + lectureTitle);
                foreach (var dir in currentDir.GetDirectories())
                {
                    if (!dir.Name.StartsWith("Ex"))
                    {
                        Module moduleToAdd = new Module()
                        {
                            Title     = dir.Name.Split('.')[0],
                            LectureId = lectureAdded.Id
                        };
                        int i = 1;
                        foreach (var file in dir.GetFiles())
                        {
                            if (!file.Name.StartsWith("Thumbs"))
                            {
                                Video videoToAdd = new Video()
                                {
                                    Title = file.Name.Split('.')[0],
                                    Path  = path + "/" + moduleToAdd.Title + "/" + file.Name,
                                    Order = i
                                };
                                i++;
                                moduleToAdd.Videos.Add(videoToAdd);
                            }
                        }
                        lectureAdded.Modules.Add(moduleToAdd);
                    }
                }
                currentDir.MoveTo(directory + "/" + path);
                if (repo.Save())
                {
                    return(lectureAdded);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                // delete lecture if exception before returning false
                if (lectureAdded != null)
                {
                    repo.RemoveLecture(lectureAdded);
                }
                return(null);
            }
        }
Exemplo n.º 3
0
 public CategoryController(IHrManagementRepository repo)
 {
     _repo = repo;
 }