public ActionResult Create(FormCollection sForm) { var _user = GetLoggedUser(); if (_user == null) { return Redirect("~/Account/LogOn/"); } ViewBag.User = _user; try { using (TransactionScope scope = new TransactionScope()) { //create a record in collection //create a record in set //create a record in collection_photos collection _setCollection = new collection { collection_name = sForm["title"], created_by = _user.id, created_date = DateTime.Now }; db.collections.Add(_setCollection); db.SaveChanges(); set _set = new set(); _set.collection = _setCollection; db.sets.Add(_set); db.SaveChanges(); if (sForm["photos"] != null) { string[] AllPhotos = sForm["photos"].ToString().Split(','); foreach (var p in AllPhotos) { collection_photos cp = new collection_photos { collection = _setCollection, photo_id = Int32.Parse(p) }; db.collection_photos.Add(cp); db.SaveChanges(); } } scope.Complete(); } var _userPhotos = from p in db.photos where p.user_id == _user.id select p; ViewBag.UserPhotos = _userPhotos.ToList(); // TODO: Add insert logic here return Redirect(string.Format("/User/{0}/Sets",Session["LoggedInUser"].ToString())); } catch { return View(); } }
public ActionResult Create(group group) { var _user = GetLoggedUser(); if (_user == null) { return RedirectToAction("LogOn", "Account"); } if (ModelState.IsValid) { using (TransactionScope scope = new TransactionScope()) { collection coll = new collection { collection_name = group.collection.collection_name, created_by = _user.id, created_date = DateTime.Now }; db.collections.Add(coll); db.SaveChanges(); group newgroup = new Models.group { collection = coll, description = group.description }; db.groups.Add(newgroup); db.SaveChanges(); //add the user who created the group as one of the group member group_members gm = new group_members { group = newgroup, user_id = _user.id }; db.group_members.Add(gm); db.SaveChanges(); scope.Complete(); } return RedirectToAction("Index"); } ModelState.AddModelError("", "Could not create new group"); return View(group); }
public ActionResult Create(FormCollection sForm) { var _user = GetLoggedUser(); if (_user == null) { return Redirect("~/Account/LogOn/"); } ViewBag.User = _user; var _userPhotos = from p in db.photos where p.user_id == _user.id select p; ViewBag.UserPhotos = _userPhotos.ToList(); try { using (TransactionScope scope = new TransactionScope()) { //create a record in collection //create a record in story //create a record in collection_photos collection storyCollection = new collection { collection_name = sForm["title"], created_by = _user.id, created_date = DateTime.Now }; db.collections.Add(storyCollection); db.SaveChanges(); story currentStory = new story { description = sForm["description"], tags = sForm["tags"] }; currentStory.collection = storyCollection; db.stories.Add(currentStory); db.SaveChanges(); if (sForm["photos"] != null) { string[] AllPhotos = sForm["photos"].ToString().Split(','); foreach (var p in AllPhotos) { collection_photos cp = new collection_photos { collection = storyCollection, photo_id = Int32.Parse(p) }; db.collection_photos.Add(cp); db.SaveChanges(); } } scope.Complete(); return Redirect(string.Format("/User/{0}/Stories", Session["LoggedInUser"].ToString())); } } catch { return View(); } }