public ActionResult Delete(Card card)
        {
            //deleting both the card and the employee to elimate all personal information from the db
            context.DeleteCard(card.ID);
            context.DeleteEmployee(card.EmployeeID);

            return RedirectToAction("Index");
        }
        public void SaveCard(Card card)
        {
            if (card.ID == 0)
            {
                context.Cards.Add(card);
                context.SaveChanges();
            }
            else
            {
                Card dbEntry = context.Cards.Find(card.ID);

                if (dbEntry != null)
                {
                    dbEntry.CardName = card.CardName;
                    dbEntry.EmployeeID = card.EmployeeID;

                    context.SaveChanges();
                }
            }
        }
        public ActionResult CreateEmployee(CreateEmployeeVM vm)
        {
            if (ModelState.IsValid)
            {
                var model = new Employee
                {
                    FirstName = vm.FirstName,
                    LastName = vm.LastName,
                    PhoneNumber = vm.PhoneNumber,
                    Email = vm.Email,
                    JobTitle = vm.JobTitle,
                    CompanyID = vm.CompanyID
                };

                context.SaveEmployee(model);

                //DRJ - now let's build the card
                //DRJ - finding the newly created employee's id
                int employeeID = context.Employees
                    .Where(e => e.LastName == model.LastName && e.CompanyID == model.CompanyID)
                    .Select(e => e.ID)
                    .FirstOrDefault();

                var card = new Card
                {
                    CardName = vm.FirstName + " " + vm.LastName + "'s Business Card",
                    EmployeeID = employeeID
                };

                //DRJ - creating the card
                context.SaveCard(card);

                int cardID = context.Cards
                    .Where(c => c.CardName == card.CardName && c.EmployeeID == card.EmployeeID)
                    .Select(c => c.ID)
                    .FirstOrDefault();

                //DRJ - sending the user to view their business card
                return RedirectToAction("Index", "Card", new { id = cardID });
            }

            //need to repopulate list if there are model binding issues
            vm.CompanyList = context.Companies
                                .OrderBy(c => c.CompanyName)
                                .Select(c => new SelectListItem { Text = c.CompanyName, Value = c.ID.ToString() });

            return View(vm);
        }
        public ActionResult Edit(CardAdminVM vm)
        {
            if (ModelState.IsValid)
            {
                var Card = new Card
                {
                    CardName = vm.FirstName + " " + vm.LastName + "'s Business Card",
                    EmployeeID = vm.EmployeeID
                };

                var Employee = new Employee
                {
                    ID = vm.EmployeeID,
                    FirstName = vm.FirstName,
                    LastName = vm.LastName,
                    JobTitle = vm.JobTitle,
                    PhoneNumber = vm.PhoneNumber,
                    Email = vm.Email,
                    CompanyID = vm.CompanyID
                };

                context.SaveEmployee(Employee);
                //context.SaveCard(Card);

                return RedirectToAction("Index");
            }

            //DRJ - getting the company list
            vm.CompanyList = context.Companies
                .OrderBy(c => c.CompanyName)
                .Select(c => new SelectListItem { Text = c.CompanyName, Value = c.ID.ToString() });

            //DRJ - getting the state list
            vm.StateList = context.States.OrderBy(s => s.Abbreviation)
                .Select(s => new SelectListItem { Text = s.Name, Value = s.Abbreviation });

            return View(vm);
        }