Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "cardID,cardNumber,cardExpirationDate,cardSecurityCode, accountID,firstName,lastName")] CreditCard creditCard)
        {
            if (ModelState.IsValid)
            {
                //Get a random card number from the table NewCardNumbers and store it in cardNumber of table CreditCards:
                //getRandomCardNumber(creditCard.cardID);
                //check if the card number matches another existing card:
                Boolean duplicateCard = checkDuplicateCard(creditCard.cardNumber);
                //check if the first number = 9:
                Boolean valid = invalidCardNumber(creditCard.cardNumber);
                if (duplicateCard)
                {
                    ModelState.AddModelError("cardNumber", "The card number you entered matches another card.");
                    ViewBag.accountID = new SelectList(db.Accounts, "accountID", "accountNumber", creditCard.accountID);
                    return(View(creditCard));
                }
                else if (!valid)
                {
                    ModelState.AddModelError("cardNumber", "The card number you entered must not start with the number 9");
                    ViewBag.accountID = new SelectList(db.Accounts, "accountID", "accountNumber", creditCard.accountID);
                    return(View(creditCard));
                }
                db.CreditCards.Add(creditCard);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.accountID = new SelectList(db.Accounts, "accountID", "accountNumber", creditCard.accountID);
            return(View(creditCard));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "SecurityQuestionsID,AspNetUserID,QuestionID,Answer")] SecurityQuestion securityQuestion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(securityQuestion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(securityQuestion));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "relayConnectionID,relayID,relayID2,relayWeight")] RelayToRelayConnection relayToRelayConnection)
        {
            if (ModelState.IsValid)
            {
                db.RelayToRelayConnections.Add(relayToRelayConnection);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(relayToRelayConnection));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "accountID, accountNumber,accountBalance,accountName,accountFirstName,accountLastName,accountAddress,accountCity,accountState,accountZip,accountPhone,accountMax")] Account account,
            [Bind(Include = "cardID, cardNumber, cardExpirationDate, cardSecurityCode, accountID, firstName, lastName")] CreditCard creditCard)
        {
            var vModel = new AccountsCreditsViewModel();



            //if (ModelState.IsValid)
            //{
            //db.CreditCards.Add(creditCard);                
            //db.Accounts.Add(account);
            //db.SaveChanges();
            Boolean thereIsAnError = false;
            if (account.accountBalance > 9999999999999999 || account.accountBalance < -9999999999999999)
            {
                ModelState.AddModelError("account.accountBalance", "The balance must between -9999999999999999 and 9999999999999999");
                thereIsAnError = true;
                //return View(vModel.account);
            }
            Boolean duplicateCard = checkDuplicateCard(creditCard.cardNumber);
            if (duplicateCard)
            {
                ModelState.AddModelError("creditCard.cardNumber", "The card number you entered matches another card.");
                ViewBag.accountID = new SelectList(db.Accounts, "accountID", "accountNumber", creditCard.accountID);
                thereIsAnError = true;                
            }
            if (thereIsAnError)
            {
                return View(vModel.account);
            }
            db.Accounts.Add(account);                
            db.SaveChanges();            
            //The below is to to get the last created accountID and copy it to the account number
            //I could not think of a better way to represent the account number other than having it as the id itself:
            int lastAccountId = duplicateAccountNumberFromAccountId();
            saveCreditCard(creditCard.cardID, creditCard.cardNumber, creditCard.cardExpirationDate, creditCard.cardSecurityCode, 
                lastAccountId, creditCard.firstName, creditCard.lastName);
            //Get the last card ID which is for the one just created:
            int lastCardId = getLastCardId();
            //Get a random card number from the table NewCardNumbers and store it in cardNumber of table CreditCards:
            //getRandomCardNumber(lastCardId);
            return RedirectToAction("Index");
            //}            
            //return View(vModel.account);
            //return View(account);
        }
Exemplo n.º 5
0
        public void changeQueueLimit(string ip, int?newLimit)
        {
            string id = getId(ip);

            //abes code to set inactive
            var relay = db.Relays.Find(id);

            relay.isActive = false;
            db.SaveChanges();
            //end of abes code to set inactive

            connect.Open();
            SqlCommand cmd = connect.CreateCommand();

            cmd.CommandText = "update Relays set relayQueue = '" + newLimit + "' where relayId = '" + id + "' ";
            cmd.ExecuteScalar();
            connect.Close();
        }
Exemplo n.º 6
0
        public ActionResult NodePositions(IEnumerable <NodeLocation> nodePosition)
        {
            var temp = nodePosition;

            foreach (var node in nodePosition)
            {
                //find the pc...
                if (node.id.Equals("192.168.0.1"))
                {
                    var x = "here";
                }

                NodePosition nodeConfiguration = db.NodePositions.Find(node.id);
                //if it doesn't exist, create a new instance
                if (nodeConfiguration == null)
                {
                    nodeConfiguration = new NodePosition()
                    {
                        Ip = node.id,
                        x  = node.pos.x,
                        y  = node.pos.y
                    };
                    if (node.category == 1)
                    {
                        var relay = db.Relays.Find(node.id); // doesn't work, getting IP instead of ID
                        relay.isActive = node.isActive;
                    }
                    db.NodePositions.Add(nodeConfiguration);
                }
                //otherwise update current positions
                else
                {
                    nodeConfiguration.x = node.pos.x;
                    nodeConfiguration.y = node.pos.y;
                    if (node.category == 1)
                    {
                        var relay = db.Relays.Find(node.id); // doesn't work, getting IP instead of ID
                        relay.isActive = node.isActive;
                    }
                    if (node.category == 2)
                    {
                        var x = "is a pc";
                    }
                }
            }

            db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 7
0
        public ActionResult ProcessTransaction(TransactionViewModel trans)
        {
            // var transaction = db.Transactions.Find(trans.transId);
            Encryption cl = new Encryption();

            cl.decryptAndStoreTransaction(trans.transId + "");

            //now grab transaction from DB and check that it is valid.
            var transaction = db.Transactions.Find(trans.transId);
            var valid       = true;
            //cant check if the card attached to the account matches one in the database, because it must in order
            //to be a valid transaction....

            //check if card exists in creditcards
            var creditCard = (from cd in db.CreditCards where cd.cardNumber == transaction.cardNumber select cd).FirstOrDefault();

            //if there is no such credit card with that number, the transaction is invalid.
            if (creditCard == null)
            {
                valid = false;
            }

            //check if the card is expired
            else
            {
                if (creditCard.cardExpirationDate < transaction.transactionTime)
                {
                    valid = false;
                }

                //check if the merchant's name and Ip match in the database
                var store = (from st in db.Stores where st.storeIP == transaction.storeIP select st).FirstOrDefault();
                //no such IP
                if (store == null)
                {
                    valid = false;
                }
                //no matching store name IF the transactionMerchant is not "SELF"
                else if (transaction.transactionMerchant != "SELF" && transaction.transactionMerchant != "Self")
                {
                    if (transaction.transactionMerchant != store.storeName)
                    {
                        valid = false;
                    }
                }



                //check if the account has enough balance for the amount mentioned
                //first check debit,
                //var account = transaction.CreditCard.Account;

                if (!valid)
                {
                    var account = creditCard.Account;
                    //no more need for checking Debit...
                    if (transaction.transactionType.Equals("Debit"))
                    {
                        account.accountBalance -= System.Convert.ToDecimal(transaction.transactionAmount);
                    }
                    if (transaction.transactionType.Equals("Credit"))
                    {
                        if (account.accountBalance + System.Convert.ToDecimal(transaction.transactionAmount) > account.accountMax)
                        {
                            valid = false;
                        }
                        else
                        {
                            account.accountBalance += System.Convert.ToDecimal(transaction.transactionAmount);
                        }
                    }
                    db.SaveChanges();
                }
            }



            if (valid)
            {
                return(Json(new { success = true, responseText = "Succeeded transaction" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { success = false, responseText = "Failed transaction" }, JsonRequestBehavior.AllowGet));
            }
            //eturn RedirectToAction("Index", "Home");
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "regionID,regionName,gatewayIP")] Regions regions,
                                   [Bind(Include = "relayID, relayName, relayIP, regionID, isActive, relayQueue, isGateway")] Relay relay,
                                   [Bind(Include = "storeID, storeName, storeWeight, relayID, storeIP, regionID")] Store store,
                                   [Bind(Include = "relayToProcessCenterConnectionID, relayID, processCenterID, isActive, relayToProcessCenterConnectionWeight")] RelayToProcessCenterConnection relayToProcessCenterConnection,
                                   string ip, int?gatewayWeight)
        {
            var vModel = new RegionsRelaysStoresViewModel();
            //
            Boolean thereIsAnError          = false;
            string  gateway_duplicate_error = "";
            string  gateway_input_error     = "";
            Boolean gateway_correctIP       = true;

            //check if Gateway IP field is empty:
            if (string.IsNullOrEmpty(regions.gatewayIP))//check for empty input
            {
                ModelState.AddModelError("regions.gatewayIP", "The Region Gateway IP field is required");
                thereIsAnError = true;
            }
            else
            {
                //check gateway IP if it the correct format: 192.168.0.XXX; XXX: 0 -> 255
                gateway_correctIP = checkForCorrectIP(regions.gatewayIP, out gateway_input_error);
                if (!gateway_correctIP)
                {
                    ModelState.AddModelError("regions.gatewayIP", gateway_input_error);
                    thereIsAnError = true;
                }
            }
            if (gateway_correctIP && !thereIsAnError)//this is to avoid input error with special characters that would crash the application
            {
                //check gateway IP if it matches another IP
                Boolean gateway_duplicate = checkDuplicateIP(regions.gatewayIP, out gateway_duplicate_error);
                if (gateway_duplicate)
                {
                    ModelState.AddModelError("regions.gatewayIP", gateway_duplicate_error);
                    thereIsAnError = true;
                }
            }
            //regions.regionName = regions.regionID.ToString();
            ////check if regions.regionName == NULL:
            //if(string.IsNullOrWhiteSpace(regions.regionName))
            //{
            //    ModelState.AddModelError("regions.regionName", "The Region Name field is required");
            //    thereIsAnError = true;
            //}
            ////check if relay.relayName == NULL: (relay is the gateway)
            //if (string.IsNullOrWhiteSpace(relay.relayName))
            //{
            //    ModelState.AddModelError("relay.relayName", "The Gateway Name field is required");
            //    thereIsAnError = true;
            //}
            //check if relay.relayQueue == NULL
            if (string.IsNullOrWhiteSpace(relay.relayQueue.ToString()))
            {
                ModelState.AddModelError("relay.relayQueue", "The Gateway Queue Limit field is required");
                thereIsAnError = true;
            }
            //check if relay.relayQueue <1 || > 500
            else if (relay.relayQueue < 1 || relay.relayQueue > 500)
            {
                ModelState.AddModelError("relay.relayQueue", "The Gateway Queue Limit must be from 1 to 500");
                thereIsAnError = true;
            }
            //check for store.storeIP input
            string  store_duplicate_error = "";
            string  store_input_error     = "";
            Boolean store_correctIP       = true;

            //check if Store IP field is empty:
            if (string.IsNullOrEmpty(store.storeIP))//check for empty input
            {
                ModelState.AddModelError("store.storeIP", "The Store IP field is required");
                thereIsAnError = true;
            }
            //check if the store IP is duplicate to the input of gateway IP:
            else if (store.storeIP.Equals(regions.gatewayIP))
            {
                ModelState.AddModelError("store.storeIP", "The Store IP must be different from the Gateway IP");
                thereIsAnError = true;
            }
            else
            {
                //check store IP if it the correct format: 192.168.0.XXX; XXX: 0 -> 255
                store_correctIP = checkForCorrectIP(store.storeIP, out store_input_error);
                if (!store_correctIP)
                {
                    ModelState.AddModelError("store.storeIP", store_input_error);
                    thereIsAnError = true;
                }
            }
            if (store_correctIP && !thereIsAnError)//this is to avoid input error with special characters that would crash the application
            {
                //check store IP if it matches another IP
                Boolean store_duplicate = checkDuplicateIP(store.storeIP, out store_duplicate_error);
                if (store_duplicate)
                {
                    ModelState.AddModelError("store.storeIP", store_duplicate_error);
                    thereIsAnError = true;
                }
            }
            //check if store.storeName == NULL
            if (string.IsNullOrEmpty(store.storeName))//check for empty input
            {
                ModelState.AddModelError("store.storeName", "The Store Name field is required");
                thereIsAnError = true;
            }
            //check if store.storeWeight == NULL
            if (string.IsNullOrWhiteSpace(store.storeWeight.ToString()))
            {
                ModelState.AddModelError("store.storeWeight", "The Store Weight field is required");
                thereIsAnError = true;
            }
            //check if store.storeWeight < 1 || > 500
            else if (store.storeWeight < 1 || store.storeWeight > 500)
            {
                ModelState.AddModelError("store.storeWeight", "Input Error: The Weight must be from 1 to 500");
                thereIsAnError = true;
            }
            ////check if relay to PC Weight == NULL
            //if (string.IsNullOrWhiteSpace(relayToProcessCenterConnection.relayToProcessCenterConnectionWeight.ToString()))
            //{
            //    ModelState.AddModelError("relayToProcessCenterConnection.relayToProcessCenterConnectionWeight", "The Relay to PC Weight field is required");
            //    thereIsAnError = true;
            //}
            //check if relay to PC Weight < 1 || > 500
            //else if (relayToProcessCenterConnection.relayToProcessCenterConnectionWeight < 1 || relayToProcessCenterConnection.relayToProcessCenterConnectionWeight > 500)
            //{
            //    ModelState.AddModelError("store.storeWeight", "Input Error: The Weight must be from 1 to 500");
            //    thereIsAnError = true;
            //}
            //check if gateway weight is null:
            if (gatewayWeight == null)
            {
                ModelState.AddModelError("gatewayWeight", "Input Error: The Weight must be from 1 to 500");
                thereIsAnError = true;
            }
            //check if there is an error anywhere. If there is, return the viewModel:
            if (thereIsAnError)
            {
                //get all relay IPs
                getAllIps();
                return(View(vModel));
            }
            //
            db.Regions.Add(regions);
            db.SaveChanges();
            //
            //get the last RegionID which was just created:
            int lastRegionId = getLastRegionId();

            //update region name and set it to region ID:
            updateRegionName(lastRegionId);
            //get the last existing RelayID in the database then add 1 to it:
            string lastRelayId = (Convert.ToInt32(getLastRelayId()) + 1).ToString();

            //add the new gateway in the relays table:
            saveRelay(lastRelayId, relay.relayName, regions.gatewayIP, lastRegionId, relay.isActive, relay.relayQueue, relay.isGateway);
            //get the last RelayID that was just created:
            lastRelayId = getLastRelayId();
            //add a connection from gateway to process center:
            //saveRelayToProcessCenter(lastRelayId, 1, true, relayToProcessCenterConnection.relayToProcessCenterConnectionWeight);
            connectGatewayToIP(regions.gatewayIP, ip, gatewayWeight);
            //get the last existing Store in the database then add 1 to it:
            string lastStoreId = (Convert.ToInt32(getLastStoreId()) + 1).ToString();

            //add the new store in the stores table:
            saveStore(lastStoreId, store.storeName, store.storeWeight, lastRelayId, store.storeIP, lastRegionId);
            //get the last StoreID that was just created:
            lastStoreId = getLastStoreId();
            //add storeID & relayID to StoreToRelays table:
            saveStoresToRelays(lastRelayId, lastStoreId, true, store.storeWeight);
            //
            //return RedirectToAction("Index");
            ViewBag.SuccessMessage = "The new region has been successfully added to the network!";
            //get all relay IPs
            getAllIps();
            return(View());
        }
Exemplo n.º 9
0
        public ActionResult Create([Bind(Include = "relayID,relayName,relayIP,regionID,isGateway,relayQueue,isActive")] Relay relay, int?weight, string ip)
        {
            getAllIps(1);
            Boolean thereIsAnError = false;
            string  relayId        = (Convert.ToInt32(getLastRelayId()) + 1).ToString();
            //Check if ip1 is store, relay, or process center
            int ipType = getIpType(ip); //Type: 1=PC, 2=Relay, 3=Store
            //get region ID for IP 1:
            int ipRegionId = getRegionId(ip, ipType);

            relay.relayID   = relayId;
            relay.isActive  = true;
            relay.isGateway = false;
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //check for relay.relayIP input
            string  relay_duplicate_error = "";
            string  relay_input_error     = "";
            Boolean relay_correctIP       = true;

            //check if relay IP field is empty:
            if (string.IsNullOrEmpty(relay.relayIP))//check for empty input
            {
                ModelState.AddModelError("relayIP", "The relay IP field is required");
                thereIsAnError = true;
            }
            else
            {
                //check relay IP if it the correct format: 192.168.0.XXX; XXX: 0 -> 255
                relay_correctIP = checkForCorrectIP(relay.relayIP, out relay_input_error);
                if (!relay_correctIP)
                {
                    ModelState.AddModelError("relayIP", relay_input_error);
                    thereIsAnError = true;
                }
            }
            if (relay_correctIP && !thereIsAnError)//this is to avoid input error with special characters that would crash the application
            {
                //check relay IP if it matches another IP
                Boolean relay_duplicate = checkDuplicateIP(relay.relayIP, out relay_duplicate_error);
                if (relay_duplicate)
                {
                    ModelState.AddModelError("relayIP", relay_duplicate_error);
                    thereIsAnError = true;
                }
            }
            ////check if relay.relayName == NULL
            //if (string.IsNullOrEmpty(relay.relayName))//check for empty input
            //{
            //    ModelState.AddModelError("relayName", "The Relay Name field is required");
            //    thereIsAnError = true;
            //}
            //check if relay.relayQueue == NULL
            if (string.IsNullOrWhiteSpace(relay.relayQueue.ToString()))
            {
                ModelState.AddModelError("relayQueue", "The Relay Queue Limit field is required");
                thereIsAnError = true;
            }
            //check if relay.relayQueue <1 || > 500
            else if (relay.relayQueue < 1 || relay.relayQueue > 500)
            {
                ModelState.AddModelError("relayQueue", "The Relay Queue Limit must be from 1 to 500");
                thereIsAnError = true;
            }
            //check if weight == NULL
            if (string.IsNullOrWhiteSpace(weight.ToString()))
            {
                ModelState.AddModelError("weight", "The Weight field is required");
                thereIsAnError = true;
            }
            //check if weight < 1 || > 500
            else if (weight < 1 || weight > 500)
            {
                ModelState.AddModelError("weight", "The Weight must be from 1 to 500");
                thereIsAnError = true;
            }
            //if the second ip is relay and in different region, the connection is prohibited
            if (ipType == 2 && (ipRegionId != relay.regionID))
            {
                ModelState.AddModelError("ip", "The relay IP is in a different region.");
                thereIsAnError = true;
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (thereIsAnError)
            {
                ViewBag.regionID = new SelectList(db.Regions, "regionID", "regionName", relay.regionID);
                return(View(relay));
            }
            db.Relays.Add(relay);
            db.SaveChanges();
            Boolean ipIsGateway = IsGateway(ip, ipType);

            if (ipIsGateway)
            {
                saveRelayToRelay(relay.relayID, relay.regionID, weight, ipIsGateway);
            }
            else
            {
                saveRelayToRelay(relay.relayID, relay.regionID, weight, ipIsGateway);
            }
            //return RedirectToAction("Index");
            ViewBag.SuccessMessage = "The new relay has been successfully added to the network!";
            ViewBag.regionID       = new SelectList(db.Regions, "regionID", "regionName", relay.regionID);
            return(View(relay));
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "storeID,storeIP,storeName,storeWeight,relayID,regionID")] Store store, string relayIp)
        {
            //if (ModelState.IsValid)
            //{
            Boolean thereIsAnError = false;
            string  storeId        = (Convert.ToInt32(getLastStoreId()) + 1).ToString();

            store.storeID = storeId;

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //get relayID from relayIP:
            store.relayID = getRelayIdFromIp(relayIp);

            //check for store.storeIP input
            string  store_duplicate_error = "";
            string  store_input_error     = "";
            Boolean store_correctIP       = true;

            //check if store IP field is empty:
            if (string.IsNullOrEmpty(store.storeIP))//check for empty input
            {
                ModelState.AddModelError("storeIP", "The Store IP field is required");
                thereIsAnError = true;
            }
            else
            {
                //check store IP if it the correct format: 192.168.0.XXX; XXX: 0 -> 255
                store_correctIP = checkForCorrectIP(store.storeIP, out store_input_error);
                if (!store_correctIP)
                {
                    ModelState.AddModelError("storeIP", store_input_error);
                    thereIsAnError = true;
                }
            }
            if (store_correctIP && !thereIsAnError)//this is to avoid input error with special characters that would crash the application
            {
                //check store IP if it matches another IP
                Boolean store_duplicate = checkDuplicateIP(store.storeIP, out store_duplicate_error);
                if (store_duplicate)
                {
                    ModelState.AddModelError("storeIP", store_duplicate_error);
                    thereIsAnError = true;
                }
            }
            //check if store.storeName == NULL
            if (string.IsNullOrEmpty(store.storeName))//check for empty input
            {
                ModelState.AddModelError("storeName", "The Store Name field is required");
                thereIsAnError = true;
            }
            //check if store.storeWeight == NULL
            if (string.IsNullOrWhiteSpace(store.storeWeight.ToString()))
            {
                ModelState.AddModelError("storeWeight", "The Store Weight field is required");
                thereIsAnError = true;
            }
            //check if store.storeWeight <1 || > 500
            else if (store.storeWeight < 1 || store.storeWeight > 500)
            {
                ModelState.AddModelError("storeWeight", "The Store Weight must be from 1 to 500");
                thereIsAnError = true;
            }

            store.regionID = getRelaysRegion(store.relayID);
            if (store.regionID == 0)
            {
                ModelState.AddModelError("relayID", "The selected Relay does not belong to a Region");
                thereIsAnError = true;
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (thereIsAnError)
            {
                ViewBag.regionID = new SelectList(db.Regions, "regionID", "regionName", store.regionID);
                ViewBag.relayID  = new SelectList(db.Relays, "relayID", "relayName", store.relayID);
                getAllIps();
                return(View(store));
            }


            db.Stores.Add(store);
            db.SaveChanges();
            //add storeID & relayID to StoreToRelays table:
            saveStoresToRelays(store.relayID, storeId, true, store.storeWeight);
            //return RedirectToAction("Index");
            ViewBag.SuccessMessage = "The new store has been successfully added to the network!";
            ViewBag.regionID       = new SelectList(db.Regions, "regionID", "regionName", store.regionID);
            ViewBag.relayID        = new SelectList(db.Relays, "relayID", "relayName", store.relayID);
            getAllIps();
            return(View(store));
            //}

            //ViewBag.regionID = new SelectList(db.Regions, "regionID", "regionName", store.regionID);
            //ViewBag.relayID = new SelectList(db.Relays, "relayID", "relayName", store.relayID);
            //return View(store);
        }