示例#1
0
        public bool AddSubjects(string SubjectName, string ImagePath, string password, string userID)
        {
            var mySubject = new Models.subjects
            {
                SubjectName = SubjectName,
                ImagePath   = ImagePath,
                IsPrivate   = false
            };

            using (Model1 _db = new Model1())
            {
                if (!string.IsNullOrEmpty(password))
                {
                    mySubject.SubjectPassword = password;
                    mySubject.IsPrivate       = true;
                }
                _db.subjects.Add(mySubject);
                _db.SaveChanges();

                if (!string.IsNullOrEmpty(password))
                {
                    AddJoinSubjectUser join = new AddJoinSubjectUser();
                    join.AddJoinSubjectUsers(mySubject.SubjectID, userID);
                }

                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Subjects/" + mySubject.SubjectID));
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Subjects/" + mySubject.SubjectID) + "/Images");
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Subjects/" + mySubject.SubjectID) + "/Tasks");
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Subjects/" + mySubject.SubjectID) + "/Downloadables");
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Subjects/" + mySubject.SubjectID) + "/Audios");
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Subjects/" + mySubject.SubjectID) + "/Tests");
            }
            return(true);
        }
示例#2
0
        public bool MakePrivate(int subjectID, string password, string userID)
        {
            using (Model1 _db = new Model1())
            {
                Models.subjects sub = (from subjects in _db.subjects where subjects.SubjectID == subjectID select subjects).FirstOrDefault();
                sub.IsPrivate       = true;
                sub.SubjectPassword = password;
                _db.SaveChanges();


                joinsubjectusers join = (from joins in _db.joinsubjectusers where joins.SubjectID == subjectID && joins.UserID == userID select joins).FirstOrDefault();
                if (join == null)
                {
                    AddJoinSubjectUser addJoin = new AddJoinSubjectUser();
                    addJoin.AddJoinSubjectUsers(subjectID, userID);
                }
            }
            return(true);
        }