Exemple #1
0
        /// <summary>
        /// this method was created to verify the identity of an user
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="userToken"></param>
        /// <returns></returns>
        public bool Login(string userName, string userPassword)
        {
            ApplicationSettings settings  = JsonDataSaverReader.ReadAppSettings();
            DbConnector         connector = new DbConnector(settings.ConnectionString);
            string loginQuery             = "SELECT HashPassword, ID FROM users WHERE Name = '" + userName + "'";

            List <List <object> > queryResult = connector.Select(loginQuery);

            if (queryResult.Count == 1)
            {
                List <object> row            = queryResult[0];
                string        userHashPsw    = row[0].ToString();
                string        hashedInputPsw = this.Hash(userPassword);

                if (hashedInputPsw == userHashPsw)
                {
                    this.userName = userName;
                    this.idUser   = int.Parse(queryResult[0][1].ToString());
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// This Method sets all the value needed by the object and get all the payments associate to the active account from the current month.
        /// </summary>
        /// <param name="activeAccount">This is the active account from the connected user</param>
        /// <returns></returns>
        public bool displayPayment(Account activeAccount)
        {
            string currentMonth = DateTime.Now.ToString("MM");

            allPayments = new List <Payment>();

            ApplicationSettings settings    = JsonDataSaverReader.ReadAppSettings();
            DbConnector         dbConnector = new DbConnector(settings.ConnectionString);

            string query = "SELECT * FROM payments WHERE DatePay LIKE '%-" + currentMonth + "-%' AND (FkIDAccountOwner = " + activeAccount.IdAccount + " OR FkIDAccountRecipient =" + activeAccount.IdAccount + ")";

            List <List <object> > queryResult = dbConnector.Select(query);

            if (queryResult.Count >= 1)
            {
                foreach (List <object> row in queryResult)
                {
                    int      idPayment              = Convert.ToInt32(row[0]);
                    int      activeAccountId        = Convert.ToInt32(row[1]);
                    string   accountRecipient       = row[2].ToString();
                    decimal  amount                 = Convert.ToDecimal(row[3]);
                    DateTime datePayment            = (DateTime)row[4];
                    string   informationTransmitted = row[5].ToString();
                    string   personalInformation    = row[6].ToString();
                    allPayments.Add(new Payment(idPayment, activeAccountId, datePayment, accountRecipient, amount, informationTransmitted, personalInformation));
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// This Method sets all the value needed by the object and get all the payments associate to the active account from the selected date for filter.
        /// </summary>
        /// <param name="activeAccount"></param>
        /// <param name="firstDate"></param>
        /// <param name="lastDate"></param>
        /// <returns></returns>
        public bool displayPaymentSort(Account activeAccount, DateTime firstDate, DateTime lastDate)
        {
            firstDate = firstDate.Date;
            lastDate  = lastDate.Date.AddDays(1).AddSeconds(-1);


            allPayments = new List <Payment>();

            ApplicationSettings settings    = JsonDataSaverReader.ReadAppSettings();
            DbConnector         dbConnector = new DbConnector(settings.ConnectionString);

            string query = "SELECT * FROM payments WHERE (FkIDAccountOwner = " + activeAccount.IdAccount + " OR FkIDAccountRecipient =" + activeAccount.IdAccount + ") AND DatePay BETWEEN '" + firstDate.ToString("yyyy-MM-dd-HH-mm-ss") + "' AND '" + lastDate.ToString("yyyy-MM-dd-HH-mm-ss") + "'";

            List <List <object> > queryResult = dbConnector.Select(query);

            if (queryResult.Count >= 1)
            {
                foreach (List <object> row in queryResult)
                {
                    int      idPayment              = Convert.ToInt32(row[0]);
                    int      activeAccountId        = Convert.ToInt32(row[1]);
                    string   accountRecipient       = row[2].ToString();
                    decimal  amount                 = Convert.ToDecimal(row[3]);
                    DateTime datePayment            = (DateTime)row[4];
                    string   informationTransmitted = row[5].ToString();
                    string   personalInformation    = row[6].ToString();
                    allPayments.Add(new Payment(idPayment, activeAccountId, datePayment, accountRecipient, amount, informationTransmitted, personalInformation));
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        /// <summary>
        /// This function load the account from the user
        /// </summary>
        /// <param name="idAccount"></param>
        /// <param name="accountNumber"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public bool loadAccount(int idAccount, string accountNumber, decimal amount)
        {
            ApplicationSettings settings  = JsonDataSaverReader.ReadAppSettings();
            DbConnector         connector = new DbConnector(settings.ConnectionString);
            string accountQuery           = "SELECT ID, AccountNumber, Amount FROM accounts WHERE FkID = " + ActiveUser.IdUser;

            List <List <object> > queryResult = connector.Select(accountQuery);

            if (queryResult.Count == 1)
            {
                this.idAccount     = Convert.ToInt32(queryResult[0][0]);
                this.accountNumber = queryResult[0][1].ToString();
                this.amount        = Convert.ToDecimal(queryResult[0][2]);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// This method add the current payment in the database and update the amount of each accounts.
        /// </summary>
        /// <param name="activeAccount">This is active account</param>
        /// <param name="idAccountRecipient">This is the id of the Recipient's account</param>
        /// <param name="datePayment">This is date of the payment</param>
        /// <param name="amount">This is the amount of the payment</param>
        /// <param name="informationSent">This is the information transmitted by the customer to the other one </param>
        /// <param name="personalInformation">This is the personal information that is only see by the sender</param>
        /// <returns></returns>
        public bool addPayment(Account activeAccount, int idAccountRecipient, DateTime datePayment, decimal amount, string informationSent, string personalInformation)
        {
            ApplicationSettings settings    = JsonDataSaverReader.ReadAppSettings();
            DbConnector         dbConnector = new DbConnector(settings.ConnectionString);
            string querySelect = "SELECT ID from accounts WHERE AccountNumber = " + "'" + this.accountRecipient + "'";

            List <List <object> > queryResultSelect = dbConnector.Select(querySelect);

            if (queryResultSelect.Count == 1)
            {
                this.idAccountRecipient = Convert.ToInt32(queryResultSelect[0][0]);
                string query       = "INSERT INTO payments(`FkIDAccountOwner`,`FkIDAccountRecipient`,`Amount`,`DatePay`,`InformationTransmitted`,`PersonalInformation`) VALUES ('" + activeAccount.IdAccount.ToString() + "', '" + this.idAccountRecipient + "','" + amount + "','" + datePayment.ToString("yyyy-MM-dd-HH-mm-ss") + "','" + informationSent + "','" + personalInformation + "');";
                bool   queryResult = dbConnector.Insert(query);
                if (queryResult == false)
                {
                    return(false);
                }
                else
                {
                    string querySelectOwner = "SELECT Amount from accounts WHERE AccountNumber = " + "'" + activeAccount.AccountNumber + "'";
                    List <List <object> > queryResultSelectOwner = dbConnector.Select(querySelectOwner);
                    if (queryResultSelectOwner.Count == 1)
                    {
                        decimal amountFinalOwner  = Convert.ToDecimal(queryResultSelectOwner[0][0]) - amount;
                        string  queryUpdate       = "UPDATE accounts SET Amount = " + amountFinalOwner + " WHERE ID =" + activeAccount.IdAccount.ToString();
                        bool    queryResultUpdate = dbConnector.Update(queryUpdate);
                        if (queryResultUpdate == true)
                        {
                            string querySelectRecipient = "SELECT Amount from accounts WHERE AccountNumber = " + "'" + accountRecipient + "'";
                            List <List <object> > queryResultSelecRecipient = dbConnector.Select(querySelectRecipient);
                            if (queryResultSelecRecipient.Count == 1)
                            {
                                decimal amountFinalRecipient       = Convert.ToDecimal(queryResultSelecRecipient[0][0]) + amount;
                                string  queryUpdateRecipient       = "UPDATE accounts SET Amount = " + amountFinalRecipient + " WHERE ID =" + this.idAccountRecipient;
                                bool    queryResultUpdateRecipient = dbConnector.Update(queryUpdateRecipient);
                                if (queryResultUpdateRecipient == true)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }