public static List<userGroup> getUserGroups() {
            List<userGroup> userGroups = null;

            using(SqlConnection con = connectionManager.getConnection()) {
                SqlCommand com = new SqlCommand("getUserGroups",con);
                com.CommandType = System.Data.CommandType.StoredProcedure;

                try {
                    con.Open();

                    SqlDataReader reader = com.ExecuteReader();
                    if(reader.HasRows) {
                        userGroups = new List<userGroup>();

                        while(reader.Read()) {
                            userGroup ugroup = new userGroup();
                            ugroup.id = Convert.ToInt32(reader["id"]);
                            ugroup.name = reader["name"].ToString();
                            ugroup.menuItems = dbItems.getItemsForGroup(ugroup.id);

                            userGroups.Add(ugroup);
                        }
                    };
                } catch { throw; };
            }

            return userGroups;
        }
        public static userGroup getUserGroup(int groupID) {
            userGroup userGroup = null;

            using(SqlConnection con = connectionManager.getConnection()) {
                SqlCommand com = new SqlCommand("getUserGroup",con);
                com.CommandType = System.Data.CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@groupID",groupID);

                try {
                    con.Open();

                    SqlDataReader reader = com.ExecuteReader();
                    if(reader.HasRows) {
                        while(reader.Read()) {
                            userGroup = new userGroup();
                            userGroup.id = groupID;
                            userGroup.name = reader["name"].ToString();
                            userGroup.menuItems = dbItems.getItemsForGroup(groupID);
                        }
                    };
                } catch { throw; };
            }

            return userGroup;
        }
        public ActionResult DeleteConfirmed(int id)
        {
            userGroup userGroup = db.userGroups.Find(id);

            db.userGroups.Remove(userGroup);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #4
0
 public ActionResult Edit([Bind(Include = "userGroupID,userGroupName")] userGroup userGroup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userGroup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userGroup));
 }
예제 #5
0
        public ActionResult Create([Bind(Include = "userGroupID,userGroupName")] userGroup userGroup)
        {
            if (ModelState.IsValid)
            {
                db.userGroups.Add(userGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userGroup));
        }
예제 #6
0
        // GET: userGroup/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            userGroup userGroup = db.userGroups.Find(id);

            if (userGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(userGroup));
        }