public static string CreateUniqueInstructorHandle(ClassDartDBContext db, string firstname, string lastname) { string tempUrl = string.Empty; if (!string.IsNullOrEmpty(firstname)) { tempUrl += (firstname.Replace(' ', '-')).ToLower(); } if (!string.IsNullOrEmpty(lastname)) { tempUrl += (lastname.Replace(' ', '-')).ToLower(); } //remove unwanted chars tempUrl = tempUrl.Replace(",", ""); tempUrl = tempUrl.Replace("'", ""); tempUrl = tempUrl.Replace(".", ""); //replace chars with text tempUrl = tempUrl.Replace("&", "and"); //Check if there are duplicate handles. int matches = db.Instructors.Count(instructorObj => instructorObj.Handle.Contains(tempUrl)); if (matches > 0) { tempUrl += (matches + 1).ToString(); } return(tempUrl); }
public static IOrderedQueryable <Class> GetInstructorClassesFromEmail(ClassDartDBContext db, string userEmail) { return(from allClasses in db.Classes where allClasses.Instructor == userEmail orderby allClasses.Name ascending select allClasses); }
public static bool GetClassObjFromId(ClassDartDBContext db, int classId, out Class classObj) { classObj = db.Classes.Find(classId); if (classObj == null) { return(false); } return(true); }
public static bool GetInstructorObjFromEmail(ClassDartDBContext db, string userEmail, out Instructor instructorObj) { IOrderedQueryable <Instructor> allInstructors = from allInstructor in db.Instructors where allInstructor.User == userEmail orderby allInstructor.User ascending select allInstructor; //there should only be one! if (allInstructors == null || allInstructors.Count() != 1) { instructorObj = null; return(false); } instructorObj = allInstructors.Single(); return(true); }
/// <summary> /// Constructor /// </summary> public V1(Class classObj, Instructor instructorObj) { if (classObj != null) { m_db = new ClassDartDBContext(); m_class = classObj; if (instructorObj != null) { m_instructor = instructorObj; } else { //instructor not provided, so get it Utilities.GetInstructorObjFromEmail(m_db, classObj.Instructor, out instructorObj); m_instructor = instructorObj; } } }
public static void SaveToDb(ClassDartDBContext db, object databaseObj) { db.Entry(databaseObj).State = EntityState.Modified; db.SaveChanges(); }