String GetFromMerchantIDCookie() { String MerchID = ""; HttpCookie cookie = Request.Cookies.Get("MerchantID"); if (cookie != null) { MerchID = cookie.Value; } MerchantIDAttribute Tester = new MerchantIDAttribute(); if ((!Tester.IsValid(MerchID)) || (MerchID.Length > 46)) { ModelState.AddModelError("", "Invalid Merchant ID"); MerchID = ""; } return(MerchID); }
// we are mixing in both data field validation and content validation bool ITerminalService.ValidateMerchantID(String MerchantID, out String Message) { // first do data field validation Message = "NO MERCH ID"; if (MerchantID == null) { return(false); } Message = "BAD MERCH ID"; if (MerchantID.Length > 46) { return(false); } MerchantIDAttribute MerchantTest = new MerchantIDAttribute(); if (!(MerchantTest.IsValid(MerchantID))) { return(false); } // then check the database to see if this merchant id is valid Message = "MID NOT FOUND"; using (GiftEntities GiftEntity = new GiftEntities()) { IMerchantDAO MerchantData = new MerchantDAO(GiftEntity); Merchant Merch = MerchantData.GetMerchant(MerchantID); if (Merch == null) { return(false); } Message = "MID NOT ACTIVE"; if (Merch.GiftActive != "A") { return(false); } return(true); } }