コード例 #1
0
        // GET: OpenFriendships/Edit/5
        public ActionResult Edit(int?id)
        {
            string         userId               = User.Identity.GetUserId();
            OpenFriendship openFriendship       = db.OpenFriendships.Find(id);
            string         openFriendshipBetaId = openFriendship.Clique.BetaId;

            if (id == null)
            {
                // You didn't pass an ID
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (openFriendship == null || openFriendshipBetaId != userId)
            {
                // It doesn't exist OR you don't manage it
                return(HttpNotFound());
            }
            if (openFriendship.Applications.Count != 0)
            {
                // People have applied already
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ViewBag.CliqueId     = new SelectList(db.Cliques.Where(c => c.BetaId == userId), "CliqueId", "Name", openFriendship.CliqueId);
            ViewBag.FriendshipId = new SelectList(db.Friendships, "FriendshipId", "Title", openFriendship.FriendshipId);
            return(View(openFriendship));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "OpenFriendshipId,FriendshipId,CliqueId")] OpenFriendship openFriendship)
        {
            if (ModelState.IsValid)
            {
                db.OpenFriendships.Add(openFriendship);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            string userId = User.Identity.GetUserId();

            ViewBag.CliqueId     = new SelectList(db.Cliques.Where(c => c.BetaId == userId), "CliqueId", "Name", openFriendship.CliqueId);
            ViewBag.FriendshipId = new SelectList(db.Friendships, "FriendshipId", "Title", openFriendship.FriendshipId);
            return(View(openFriendship));
        }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            string userId = User.Identity.GetUserId();
            string openFriendshipBetaId = db.OpenFriendships.Find(id).Clique.BetaId;

            if (openFriendshipBetaId != userId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            OpenFriendship openFriendship = db.OpenFriendships.Find(id);

            db.OpenFriendships.Remove(openFriendship);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        // GET: OpenFriendships/Delete/5
        public ActionResult Delete(int?id)
        {
            string userId = User.Identity.GetUserId();
            string openFriendshipBetaId = db.OpenFriendships.Find(id).Clique.BetaId;

            if (id == null || openFriendshipBetaId != userId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OpenFriendship openFriendship = db.OpenFriendships.Find(id);

            if (openFriendship == null)
            {
                return(HttpNotFound());
            }
            return(View(openFriendship));
        }
コード例 #5
0
        // GET: OpenFriendships/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OpenFriendship openFriendship = db.OpenFriendships.Find(id);
            string         userId         = User.Identity.GetUserId();

            // if the the openFriendship doesn't exist OR you are a Beta (Superior) AND you don't manage that position, OR
            // the openFriendship has been applied to
            if (openFriendship == null ||
                (User.IsInRole("Beta") && db.OpenFriendships.Find(id).Clique.BetaId != userId))
            {
                return(HttpNotFound());
            }

            return(View(openFriendship));
        }
コード例 #6
0
        public ActionResult Edit([Bind(Include = "OpenFriendshipId,FriendshipId,CliqueId")] OpenFriendship openFriendship)
        {
            if (openFriendship.Applications.Count != 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (ModelState.IsValid)
            {
                db.Entry(openFriendship).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            string userId = User.Identity.GetUserId();

            ViewBag.CliqueId     = new SelectList(db.Cliques.Where(c => c.BetaId == userId), "CliqueId", "Name", openFriendship.CliqueId);
            ViewBag.FriendshipId = new SelectList(db.Friendships, "FriendshipId", "Title", openFriendship.FriendshipId);
            return(View(openFriendship));
        }