public ActionResult DeleteAnnouncementConfirmed(int id, int index) { Class classObj = db.Classes.Find(id); if (classObj == null) { return(HttpNotFound()); } IList <Announcement> currentAnnouncements = V1.DeserializeAnnouncements(classObj.Announcements); currentAnnouncements.RemoveAt(index); classObj.Announcements = V1.SerializeAnnouncements(currentAnnouncements); //save classObj in DB db.Entry(classObj).State = EntityState.Modified; db.SaveChanges(); Utilities.SaveToClassDart(classObj, null); return(RedirectToAction("Index", "Editor", new { id = id })); }
public ActionResult Index(HomeViewModel model, string returnUrl, string submitButton) { if (submitButton == "Sign In") { if (ModelState.IsValid) { if (Membership.ValidateUser(model.SignInViewModel.UserName, model.SignInViewModel.Password)) { FormsAuthentication.SetAuthCookie(model.SignInViewModel.UserName, model.SignInViewModel.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("Sign In Error", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return(View(model)); } else if (submitButton == "Sign Up Free") { if (ModelState.IsValid) { // Attempt to create the user account MembershipCreateStatus createStatus; MembershipUser creationInfo = Membership.CreateUser(model.NewUserViewModel.UserName, model.NewUserViewModel.Password, model.NewUserViewModel.UserName, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.NewUserViewModel.UserName, false /* createPersistentCookie */); //create Instructor profile Instructor instructorObj = new Instructor(); instructorObj.User = model.NewUserViewModel.UserName; instructorObj.FirstName = model.NewUserViewModel.FirstName; instructorObj.LastName = model.NewUserViewModel.LastName; instructorObj.Handle = Utilities.CreateUniqueInstructorHandle(db, model.NewUserViewModel.FirstName, model.NewUserViewModel.LastName); db.Instructors.Add(instructorObj); db.SaveChanges(); /* * //Email welcome message to user * try //TODO: remove try/catch when using real SMTP server in production * { * new MailController().SendSignUpEmail(model.Email).Deliver(); * * //send to Support email, too * new MailController().NewUserNoticeEmail(model.Email).Deliver(); * } * catch * { * } * * if (!string.IsNullOrEmpty(model.ReturnAction) && !string.IsNullOrEmpty(model.ReturnController)) * { * return RedirectToAction(model.ReturnAction, model.ReturnController, new { id = model.ReturnMenuId }); * } * else * { * //send to Dashboard by default * return RedirectToAction("Index", "Dashboard"); * } */ //return, but signed in return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("New User Error", Utilities.ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); } else if (submitButton == "Create") { if ((ModelState.IsValid) && (!string.IsNullOrEmpty(model.CreateClassViewModel.ClassName))) { List <Class> tempClassList = new List <Class>(); //get all existing classes MembershipUser currentUser = null; try { currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */); } catch (Exception e) { //Utilities.LogAppError("Could not retrieve user account.", e); return(HttpNotFound()); } if (currentUser != null) { IOrderedQueryable <Class> classes = Utilities.GetInstructorClassesFromEmail(db, currentUser.Email); if (classes != null) { tempClassList = classes.ToList(); } } //check if class name already exists if (!tempClassList.Any(x => x.Name.ToLower() == model.CreateClassViewModel.ClassName.ToLower())) { //add new class Class newClass = new Class(); newClass.Name = model.CreateClassViewModel.ClassName; newClass.Instructor = currentUser.Email; newClass.Template = "Licorice"; //get Instructor profile Instructor instructorObj; Utilities.GetInstructorObjFromEmail(db, currentUser.Email, out instructorObj); newClass.Url = Utilities.CreateClassDartUrl(instructorObj.Handle, model.CreateClassViewModel.ClassName); db.Classes.Add(newClass); db.SaveChanges(); //create classdart page and create/update instructor page Utilities.SaveToClassDartAndInstructorPage(newClass, instructorObj); tempClassList.Add(newClass); TempData["ClassList"] = tempClassList; } else { return(RedirectToAction("DuplicateClassName")); } } return(RedirectToAction("Index", "Home")); } else { //search classes // If we got this far, something failed, redisplay form return(View(model)); } }
public static void SaveToDb(ClassDartDBContext db, object databaseObj) { db.Entry(databaseObj).State = EntityState.Modified; db.SaveChanges(); }