Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public ActionResult Edit(group group)
 {
     if (ModelState.IsValid)
     {
         db.Entry(group).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.collection_id = new SelectList(db.collections, "collection_id", "collection_name", group.collection_id);
     return View(group);
 }