示例#1
0
        // Method to handle user login validation, obtain user
        // information, and redirect client following login attempt.
        protected void EquipCheckLoginCtrl_Authenticate(object sender, AuthenticateEventArgs e)
        {
            EquipCheckAppUser user = new EquipCheckAppUser();

            user.Username = EquipCheckLoginCtrl.UserName;
            user.Password = EquipCheckLoginCtrl.Password;

            UserManager       userMgr      = new UserManager();
            EquipCheckAppUser userAtServer = userMgr.RetrieveUser(user);

            if (userAtServer != null)
            {
                e.Authenticated = true;

                EquipCheckAppUser userLocal = userMgr.RetrieveLocalUser(userAtServer);

                if (userLocal == null)
                {
                    userLocal = userMgr.CreateUser(userAtServer);
                    userLocal = ListCreation.CreateLists(userLocal);
                }

                // Get user's checklists
                CheckListManager checkListManager = new CheckListManager();
                List <CheckList> checkLists       = checkListManager.RetrieveCheckLists(userLocal);
                List <String>    checkListNames   = checkListManager.getCheckListNames(checkLists);

                userLocal.AllCheckList      = checkLists;
                userLocal.AllCheckListNames = checkListNames;

                // Get user's equipment lists
                EquipListManager     equipListManager = new EquipListManager();
                List <EquipmentList> equipLists       = equipListManager.RetrieveEquipLists(userLocal);

                if (equipLists == null || equipLists.Count == 0)
                {
                    userLocal = ListCreation.CreateLists(userLocal);
                }
                else
                {
                    List <String> equipListNames = equipListManager.getEquipmentListNames(equipLists);
                    userLocal.AllEquipLists     = equipLists;
                    userLocal.AllEquipListNames = equipListNames;
                }

                Session["user"] = userLocal;

                Response.Redirect("/Restricted/Welcome.aspx");
            }
            else
            {
                e.Authenticated = false;

                Session["user"]         = null;
                Session["message_type"] = "login_error";
                Session["message"]      = "Login Error.";
                Session["details"]      = "User Credentials Invalid.";
                Response.Redirect("/Restricted/Message.aspx");
            }
        }
示例#2
0
        // Method for saving a new Equipment Item to a user's Equipment List.
        protected void SaveItemButton_Click(object sender, EventArgs e)
        {
            EquipmentItem item = new EquipmentItem();
            item.EquipItemName = ItemNameTextBox.Text;
            item.EquipItemDesc = ItemDescriptionTextBox.Text;

            if (item.Validate() && !DropDownList.SelectedValue.Equals(""))
            {
                EquipCheckAppUser user = (EquipCheckAppUser)Session["user"];
                List<EquipmentList> lists = user.AllEquipLists;
                List<EquipmentItem> items = null;

                for (int i = 0; i < lists.Count; i++)
                {
                    if (lists[i].EquipListName.Equals(DropDownList.SelectedValue))
                    {
                        if (lists[i].EquipListItems != null)
                        {
                            items = lists[i].EquipListItems;
                        } else {
                            items = new List<EquipmentItem>();
                        }

                        EquipListManager listManager = new EquipListManager();
                        listManager.AddItemToList(user, lists[i], item);

                        items.Add(item);
                        lists[i].EquipListItems = items;
                        user.AllEquipLists = lists;

                        Session["user"] = user;
                        Session["listSelection"] = DropDownList.SelectedValue;
                        break;
                    }
                }

                Session["message_type"] = "item_success";
                Session["message"] = "Item Creation Successful.";
                Session["details"] = "Click OK to Continue!";

                Session["itemEntries"] = null;
            }
            else
            {
                Session["message_type"] = "item_error";
                Session["message"] = "Item Entry Error.";
                Session["details"] = "All Entries Required!";

                String[] itemEntries = { DropDownList.SelectedIndex.ToString(), ItemNameTextBox.Text, ItemDescriptionTextBox.Text };
                Session["itemEntries"] = itemEntries;
            }

            Response.Redirect("/Restricted/Message.aspx");
        }
示例#3
0
        public static EquipCheckAppUser CreateLists(EquipCheckAppUser user)
        {
            EquipListManager listMgr = new EquipListManager();
            List <String>    tempAllEquipListNames;

            // Create default equipment lists for user
            EquipmentList listCampEquip   = new EquipmentList();
            EquipmentList listCampClothes = new EquipmentList();
            EquipmentList listCampFood    = new EquipmentList();
            EquipmentList listCampMisc    = new EquipmentList();

            listCampEquip.EquipListName   = "Camping Equipment";
            listCampEquip.EquipListDesc   = "All the camping supplies in our inventory";
            listCampClothes.EquipListName = "Camping Clothes";
            listCampClothes.EquipListDesc = "Clothes that we typically take camping";
            listCampFood.EquipListName    = "Camping Food";
            listCampFood.EquipListDesc    = "Food items we typically purchase for camping trips";
            listCampMisc.EquipListName    = "Camping Miscellaneous";
            listCampMisc.EquipListDesc    = "Miscellaneous camping items that don't fit into other lists";

            // Associate the Equipment Lists with the user
            List <EquipmentList> tempAllEquipLists = new List <EquipmentList>();

            EquipmentList[] equipmentLists = { listCampEquip, listCampClothes, listCampFood, listCampMisc };
            tempAllEquipLists.AddRange(equipmentLists);
            user.AllEquipLists = tempAllEquipLists;

            tempAllEquipListNames = new List <String>();

            for (int i = 0; i < equipmentLists.Length; i++)
            {
                listMgr.CreateEquipList(user, equipmentLists[i]);
                tempAllEquipListNames.Add(equipmentLists[i].EquipListName);
            }

            user.AllEquipListNames = tempAllEquipListNames;

            return(user);
        }