public ActionResult Delete(int id)
        {
            //Check if changes are allowed to Cards for this Database
            CreditCardBehavior creditCardBehavior = new CreditCardBehavior();

            creditCardBehavior = creditCardRepository.GetCreditCardBehavior();
            if (!creditCardBehavior.CanChangeCreditCardsFlag)
            {
                ViewData["ActionMethod"] = "DeleteGet";
                return(View("Error"));
            }

            //Check Exists
            CreditCardClientSubUnitTravelerType creditCardClientSubUnitTravelerType = new CreditCardClientSubUnitTravelerType();

            creditCardClientSubUnitTravelerType = creditCardClientSubUnitTravelerTypeRepository.GetCreditCardClientSubUnitTravelerType(id);

            if (creditCardClientSubUnitTravelerType == null)
            {
                ViewData["ActionMethod"] = "DeleteGet";
                return(View("RecordDoesNotExistError"));
            }

            string csu = creditCardClientSubUnitTravelerType.ClientSubUnitGuid;
            string tt  = creditCardClientSubUnitTravelerType.TravelerTypeGuid;

            ClientSubUnitTravelerTypeCreditCardVM clientSubUnitTravelerTypeCreditCardVM = new ClientSubUnitTravelerTypeCreditCardVM();

            clientSubUnitTravelerTypeCreditCardVM.TravelerType  = travelerTypeRepository.GetTravelerType(tt);
            clientSubUnitTravelerTypeCreditCardVM.ClientSubUnit = clientSubUnitRepository.GetClientSubUnit(csu);

            CreditCard creditCard = new CreditCard();

            creditCard = creditCardRepository.GetCreditCard(id, false);
            creditCardRepository.EditForDisplay(creditCard);
            clientSubUnitTravelerTypeCreditCardVM.CreditCard = creditCard;

            //Log View Of Credit Card
            LogRepository logRepository = new LogRepository();

            logRepository.LogApplicationUsage(8, csu, tt, "", creditCard.CreditCardToken, creditCard.CreditCardTypeId, true);


            return(View(clientSubUnitTravelerTypeCreditCardVM));
        }
        // GET: /View
        public ActionResult View(int id)
        {
            //Check Exists
            CreditCardClientSubUnitTravelerType creditCardClientSubUnitTravelerType = new CreditCardClientSubUnitTravelerType();

            creditCardClientSubUnitTravelerType = creditCardClientSubUnitTravelerTypeRepository.GetCreditCardClientSubUnitTravelerType(id);

            if (creditCardClientSubUnitTravelerType == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }

            string csu = creditCardClientSubUnitTravelerType.ClientSubUnitGuid;
            string tt  = creditCardClientSubUnitTravelerType.TravelerTypeGuid;

            ClientSubUnitTravelerTypeCreditCardVM clientSubUnitTravelerTypeCreditCardVM = new ClientSubUnitTravelerTypeCreditCardVM();

            clientSubUnitTravelerTypeCreditCardVM.TravelerType  = travelerTypeRepository.GetTravelerType(tt);
            clientSubUnitTravelerTypeCreditCardVM.ClientSubUnit = clientSubUnitRepository.GetClientSubUnit(csu);


            CreditCard creditCard = new CreditCard();

            creditCard = creditCardRepository.GetCreditCard(id, false);
            creditCardRepository.EditForDisplay(creditCard);
            clientSubUnitTravelerTypeCreditCardVM.CreditCard = creditCard;

            //Log View Of Credit Card
            LogRepository logRepository = new LogRepository();

            logRepository.LogApplicationUsage(8, csu, tt, "", creditCard.CreditCardToken, creditCard.CreditCardTypeId, true);


            return(View(clientSubUnitTravelerTypeCreditCardVM));
        }
        public ActionResult Delete(int id, FormCollection collection)
        {
            //Check if changes are allowed to Cards for this Database
            CreditCardBehavior creditCardBehavior = new CreditCardBehavior();

            creditCardBehavior = creditCardRepository.GetCreditCardBehavior();
            if (!creditCardBehavior.CanChangeCreditCardsFlag)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("Error"));
            }


            //Check Exists
            CreditCardClientSubUnitTravelerType creditCardClientSubUnitTravelerType = new CreditCardClientSubUnitTravelerType();

            creditCardClientSubUnitTravelerType = creditCardClientSubUnitTravelerTypeRepository.GetCreditCardClientSubUnitTravelerType(id);

            if (creditCardClientSubUnitTravelerType == null)
            {
                ViewData["ActionMethod"] = "DeletePost";
                return(View("RecordDoesNotExistError"));
            }

            string csu = creditCardClientSubUnitTravelerType.ClientSubUnitGuid;
            string tt  = creditCardClientSubUnitTravelerType.TravelerTypeGuid;

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToClientSubUnitCreditCards(csu))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            CreditCard creditCard = new CreditCard();

            creditCard = creditCardRepository.GetCreditCard(id, false);

            //Delete Item
            try
            {
                creditCard.VersionNumber = Int32.Parse(collection["CreditCard.VersionNumber"]);
                creditCardClientSubUnitTravelerTypeRepository.Delete(creditCard);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/CreditCardClientSubUnitTravelerType.mvc/Delete/" + id.ToString();
                    return(View("VersionError"));
                }
                //Generic Error
                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }


            return(RedirectToAction("List", new { csu = csu, tt = tt }));
        }
        public ActionResult Edit(ClientSubUnitTravelerTypeCreditCardEditableVM clientSubUnitTravelerTypeCreditCardVM, FormCollection collection)
        {
            //Check if changes are allowed to Cards for this Database
            CreditCardBehavior creditCardBehavior = new CreditCardBehavior();

            creditCardBehavior = creditCardRepository.GetCreditCardBehavior();
            if (!creditCardBehavior.CanChangeCreditCardsFlag)
            {
                ViewData["ActionMethod"] = "EditPost";
                return(View("Error"));
            }

            int creditCardId = clientSubUnitTravelerTypeCreditCardVM.CreditCard.CreditCardId;

            //Check Exists
            CreditCardClientSubUnitTravelerType creditCardClientSubUnitTravelerType = new CreditCardClientSubUnitTravelerType();

            creditCardClientSubUnitTravelerType = creditCardClientSubUnitTravelerTypeRepository.GetCreditCardClientSubUnitTravelerType(creditCardId);
            if (creditCardClientSubUnitTravelerType == null)
            {
                ViewData["ActionMethod"] = "EditPost";
                return(View("RecordDoesNotExistError"));
            }

            string csu = clientSubUnitTravelerTypeCreditCardVM.ClientSubUnit.ClientSubUnitGuid;
            string tt  = clientSubUnitTravelerTypeCreditCardVM.TravelerType.TravelerTypeGuid;

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToClientSubUnitCreditCards(csu))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Get Item From Database
            CreditCardEditable creditCard = new CreditCardEditable();

            creditCard = creditCardRepository.GetCreditCardEditable(creditCardId, true);

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <CreditCardEditable>(creditCard, "CreditCard");
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }


            //Database Update
            try
            {
                creditCard.ClientSubUnitGuid = csu;
                creditCard.TravelerTypeGuid  = tt;
                creditCard.VersionNumber     = Int32.Parse(collection["CreditCard.VersionNumber"]);
                creditCardRepository.Edit(creditCard);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/CreditCardClientSubUnitTravelerType.mvc/Edit?id=" + creditCardId;
                    return(View("VersionError"));
                }
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }
            return(RedirectToAction("List", new { csu = csu, tt = tt }));
        }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Check if changes are allowed to Cards for this Database
            CreditCardBehavior creditCardBehavior = new CreditCardBehavior();

            creditCardBehavior = creditCardRepository.GetCreditCardBehavior();
            if (!creditCardBehavior.CanChangeCreditCardsFlag)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("Error"));
            }

            //Check Exists
            CreditCardClientSubUnitTravelerType creditCardClientSubUnitTravelerType = new CreditCardClientSubUnitTravelerType();

            creditCardClientSubUnitTravelerType = creditCardClientSubUnitTravelerTypeRepository.GetCreditCardClientSubUnitTravelerType(id);

            if (creditCardClientSubUnitTravelerType == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            string csu = creditCardClientSubUnitTravelerType.ClientSubUnitGuid;
            string tt  = creditCardClientSubUnitTravelerType.TravelerTypeGuid;

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToClientSubUnitCreditCards(csu))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }


            ClientSubUnitTravelerTypeCreditCardVM clientSubUnitTravelerTypeCreditCardVM = new ClientSubUnitTravelerTypeCreditCardVM();

            clientSubUnitTravelerTypeCreditCardVM.TravelerType  = travelerTypeRepository.GetTravelerType(tt);
            clientSubUnitTravelerTypeCreditCardVM.ClientSubUnit = clientSubUnitRepository.GetClientSubUnit(csu);

            ClientSubUnit clientSubUnit = new ClientSubUnit();

            clientSubUnit = clientSubUnitRepository.GetClientSubUnit(csu);

            CreditCard creditCard = new CreditCard();

            creditCard = creditCardRepository.GetCreditCard(id, true);
            creditCardRepository.EditForDisplay(creditCard);
            clientSubUnitTravelerTypeCreditCardVM.CreditCard = creditCard;

            CreditCardTypeRepository creditCardTypeRepository = new CreditCardTypeRepository();

            clientSubUnitTravelerTypeCreditCardVM.CreditCardTypes = new SelectList(creditCardTypeRepository.GetAllCreditCardTypes().ToList(), "CreditCardTypeId", "CreditCardTypeDescription", creditCard.CreditCardTypeId);

            CreditCardVendorRepository creditCardVendorRepository = new CreditCardVendorRepository();

            clientSubUnitTravelerTypeCreditCardVM.CreditCardVendors = new SelectList(creditCardVendorRepository.GetAllCreditCardVendors().ToList(), "CreditCardVendorCode", "CreditCardVendorName", creditCard.CreditCardVendorCode);

            //Populate List of Products
            ProductRepository productRepository = new ProductRepository();
            SelectList        products          = new SelectList(productRepository.GetAllProducts().ToList(), "ProductId", "ProductName");

            ViewData["ProductList"] = products;

            //Log View Of Credit Card
            LogRepository logRepository = new LogRepository();

            logRepository.LogApplicationUsage(8, csu, tt, "", creditCard.CreditCardToken, creditCard.CreditCardTypeId, true);

            //Show Form
            return(View(clientSubUnitTravelerTypeCreditCardVM));
        }