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 PhotoAdd(FormCollection coll) { string grpId = coll["group_id"].ToString(); using (TransactionScope scope = new TransactionScope()) { string[] selectedPhotos = coll["photos"].ToString().Split(','); if (selectedPhotos.Count() > 0) { foreach (var sp in selectedPhotos) { collection_photos cp = new collection_photos { collection_id = Int32.Parse(coll["collection_id"]), photo_id = Int32.Parse(sp) }; db.collection_photos.Add(cp); db.SaveChanges(); } } scope.Complete(); } return Redirect(string.Format("/Group/Details/{0}",grpId)); }
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(); } }