Example #1
0
        /// <summary>
        /// Fetches information about the Customer based on their Account Information
        /// </summary>
        /// <param name="Account"></param>
        /// <returns>A reference to the Current Customer</returns>
        internal static Customer GetCurrentCustomer(UserAccount Account)
        {
            Customer CurrentCustomer;

            using (var DB = new P0Context())
            {
                Customer customer = new Customer();

                UserAccountDAO.LoadUserAccountsList(DB);
                foreach (UserAccount a in DB.UserAccountsList)
                {
                    if (Account.Username == a.Username && Account.Password == a.Password)
                    {
                        customer.CustomerID = Account.CustomerID;
                        break;
                    }
                }

                CustomerDAO.LoadCustomersList(DB);
                foreach (Customer c in DB.CustomersList)
                {
                    if (customer.CustomerID == c.CustomerID)
                    {
                        customer.FirstName = c.FirstName;
                        customer.LastName  = c.LastName;
                        break;
                    }
                }
                CurrentCustomer = customer;
            }
            return(CurrentCustomer);
        }
        /*private static P1Context _context;
         * public static void SetContext(P1Context context)
         * {
         *  _context = context;
         * }*/
        /// <summary>
        /// Creates a new entries in the Customers Table and UserAccounts Table for new Users
        /// </summary>
        /// <param name="Account"></param>
        public static void RegisterAccount(UserAccount Account, Customer c, P1Context _context)
        {
            var DB = _context;

            CustomerDAO.AddCustomer(c, DB);
            Account.Customer = c;
            UserAccountDAO.AddUserAccount(Account, DB);
        }
Example #3
0
 /// <summary>
 /// Creates a new entries in the Customers Table and UserAccounts Table for new Users
 /// </summary>
 /// <param name="Account"></param>
 public static void RegisterAccount(UserAccount Account, Customer c)
 {
     using (var DB = new P0Context())
     {
         CustomerDAO.AddCustomer(c, DB);
         Account.Customer = c;
         UserAccountDAO.AddUserAccount(Account, DB);
     }
 }
        public static bool AccountExists(string username, P1Context _context)
        {
            bool exists;
            var  DB = _context;

            UserAccountDAO.LoadUserAccountsList(DB);
            exists = DB.UserAccountsList.Any(a => a.Username == username);
            return(exists);
        }
 public IActionResult LoginApplication(UserAccount login)
 {
     try
     {
         CurUser      = UserAccountDAO.GetAccount(login.EmailAddress, login.Password);
         ViewBag.Name = CurUser.Name;
         return(View("Dashboard"));
     }
     catch
     {
         return(View("Login"));
     }
 }
        internal static List <UserAccount> Accounts(List <Customer> customers, P1Context _context)
        {
            List <UserAccount> accounts = new List <UserAccount>();
            var DB = _context;

            foreach (Customer c in customers)
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                UserAccount a = DB.UserAccountsList.First(u => u.CustomerID == c.CustomerID);
                a.Customer = c;
                accounts.Add(a);
            }
            return(accounts);
        }
        /// <summary>
        /// Takes in the Login Information and verifies that the user exits
        /// </summary>
        /// <param name="Account"></param>
        /// <returns>True if user exists, false if username or password doesn't match</returns>
        internal static bool LoginSuccesful(UserAccount Account, P1Context _context)
        {
            bool success = false;
            var  DB      = _context;

            UserAccountDAO.LoadUserAccountsList(DB);
            foreach (UserAccount a in DB.UserAccountsList)
            {
                if (Account.Username == a.Username && Account.Password == a.Password)
                {
                    Account.CustomerID = a.CustomerID;
                    success            = true;
                    break;
                }
            }
            return(success);
        }
Example #8
0
        /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
        /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
        /// <param name="expressionToExecute">The expression to execute. Can be null</param>
        /// <param name="aggregateToApply">Aggregate function to apply. </param>
        /// <param name="filter">The filter to apply to retrieve the scalar</param>
        /// <param name="relations">The relations to walk</param>
        /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param>
        /// <returns>the scalar value requested</returns>
        public virtual object GetScalar(UserAccountFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause)
        {
            EntityFields fields = new EntityFields(1);

            fields[0] = EntityFieldFactory.Create(fieldIndex);
            if ((fields[0].ExpressionToApply == null) || (expressionToExecute != null))
            {
                fields[0].ExpressionToApply = expressionToExecute;
            }
            if ((fields[0].AggregateFunctionToApply == AggregateFunction.None) || (aggregateToApply != AggregateFunction.None))
            {
                fields[0].AggregateFunctionToApply = aggregateToApply;
            }
            UserAccountDAO dao = DAOFactory.CreateUserAccountDAO();

            return(dao.GetScalar(fields, base.Transaction, filter, relations, groupByClause));
        }
Example #9
0
        /// <summary> Retrieves in this UserAccountCollection object all UserAccountEntity objects which have data in common with the specified related Entities.
        /// If one is omitted, that entity is not used as a filter. All current elements in the collection are removed from the collection.</summary>
        /// <param name="accountInstance">AccountEntity instance to use as a filter for the UserAccountEntity objects to return</param>
        /// <param name="userInstance">UserEntity instance to use as a filter for the UserAccountEntity objects to return</param>
        /// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return with this retrieval query.</param>
        /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified, no sorting is applied.</param>
        /// <param name="filter">Extra filter to limit the resultset. Predicate expression can be null, in which case it will be ignored.</param>
        /// <param name="pageNumber">The page number to retrieve.</param>
        /// <param name="pageSize">The page size of the page to retrieve.</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public virtual bool GetMultiManyToOne(IEntity accountInstance, IEntity userInstance, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicateExpression filter, int pageNumber, int pageSize)
        {
            bool validParameters = false;

            validParameters |= (accountInstance != null);
            validParameters |= (userInstance != null);
            if (!validParameters)
            {
                return(GetMulti(filter, maxNumberOfItemsToReturn, sortClauses, null, pageNumber, pageSize));
            }
            if (!base.SuppressClearInGetMulti)
            {
                this.Clear();
            }
            UserAccountDAO dao = DAOFactory.CreateUserAccountDAO();

            return(dao.GetMulti(base.Transaction, this, maxNumberOfItemsToReturn, sortClauses, base.EntityFactoryToUse, filter, accountInstance, userInstance, pageNumber, pageSize));
        }
Example #10
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //Input validation
            if (!(String.IsNullOrEmpty(textBoxUsername.Text) || String.IsNullOrEmpty(textBoxPassword.Text)))
            {
                var username = textBoxUsername.Text.Trim().ToLowerInvariant();
                var password = textBoxPassword.Text.Trim();

                //User identification
                var identifiedUser = UserAccountDAO.identifyUser(username);
                if (identifiedUser != null)
                {
                    //User authentication
                    var loginSuccessful = UserAccountDAO.authenticateUser
                                              (identifiedUser, password);
                    if (loginSuccessful)
                    {
                        //Login OK
                        Hide();
                        var mainForm = new MainForm(identifiedUser);
                        mainForm.Show();
                    }
                    else
                    {
                        lblLoginFalse.Text = "Pogrešna lozinka!";
                        textBoxPassword.Clear();
                    }
                }
                else
                {
                    lblLoginFalse.Text = "Neuspješna prijava!";
                    textBoxPassword.Clear();
                    textBoxUsername.Clear();
                }
            }
            else
            {
                lblLoginFalse.Text = "Uniesi korisničko ime i loznku!";
            }
        }
Example #11
0
        public void CreateAccountShouldAdd1Customer()
        {
            UserAccount U = new UserAccount
            {
                Username = "******",
                Password = "******"
            };

            Customer C = new Customer
            {
                FirstName = "Statyve",
                LastName  = "Thomas"
            };

            int numC;
            int numU;
            int nC;
            int nU;

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                numU = DB.UserAccountsList.Count;
                numC = DB.CustomersList.Count;
            }

            DatabaseControl.RegisterAccount(U, C);

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                nU = DB.UserAccountsList.Count - 1;
                nC = DB.CustomersList.Count - 1;
            }

            Assert.Equal(numC, nU);
        }
Example #12
0
        public void CreateAccountShouldAdd1UserAccount()
        {
            UserAccount U = new UserAccount
            {
                Username = "******",
                Password = "******"
            };

            Customer C = new Customer
            {
                FirstName = "Paul",
                LastName  = "Wall"
            };

            int numC;
            int numU;
            int nC;
            int nU;

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                numU = DB.UserAccountsList.Count;
                numC = DB.CustomersList.Count;
            }

            DatabaseControl.RegisterAccount(U, C);

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                nU = DB.UserAccountsList.Count - 1;
                nC = DB.CustomersList.Count - 1;
            }

            Assert.Equal(numU, nU);
        }
 public IActionResult ListAccounts()
 {
     return(View(UserAccountDAO.GetAccounts()));
 }
Example #14
0
 public IActionResult Account()
 {
     return(View("AccountManagement", UserAccountDAO.GetAccounts()));
 }
Example #15
0
 public void SignIn([FromBody] UserAccountDAO dao)
 {
 }
 public IActionResult Register(UserAccount account)
 {
     UserAccountDAO.CreateAccount(account);
     return(View("Login"));
 }
Example #17
0
        /// <summary> Retrieves Entity rows in a datatable which match the specified filter. It will always create a new connection to the database.</summary>
        /// <param name="selectFilter">A predicate or predicate expression which should be used as filter for the entities to retrieve.</param>
        /// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return with this retrieval query.</param>
        /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified, no sorting is applied.</param>
        /// <param name="relations">The set of relations to walk to construct to total query.</param>
        /// <param name="pageNumber">The page number to retrieve.</param>
        /// <param name="pageSize">The page size of the page to retrieve.</param>
        /// <returns>DataTable with the rows requested.</returns>
        public static DataTable GetMultiAsDataTable(IPredicate selectFilter, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, int pageNumber, int pageSize)
        {
            UserAccountDAO dao = DAOFactory.CreateUserAccountDAO();

            return(dao.GetMultiAsDataTable(maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, pageNumber, pageSize));
        }
Example #18
0
        /// <summary> Updates in the persistent storage all UserAccount entities which have data in common with the specified related Entities. If one is omitted, that entity is not used as a filter.
        /// Which fields are updated in those matching entities depends on which fields are <i>changed</i> in the passed in entity entityWithNewValues. The new values of these fields are read from entityWithNewValues. </summary>
        /// <param name="entityWithNewValues">UserAccountEntity instance which holds the new values for the matching entities to update. Only changed fields are taken into account</param>
        /// <param name="accountInstance">AccountEntity instance to use as a filter for the UserAccountEntity objects to return</param>
        /// <param name="userInstance">UserEntity instance to use as a filter for the UserAccountEntity objects to return</param>
        /// <returns>Amount of entities affected, if the used persistent storage has rowcounting enabled.</returns>
        public int UpdateMultiManyToOne(UserAccountEntity entityWithNewValues, IEntity accountInstance, IEntity userInstance)
        {
            UserAccountDAO dao = DAOFactory.CreateUserAccountDAO();

            return(dao.UpdateMulti(entityWithNewValues, base.Transaction, accountInstance, userInstance));
        }
Example #19
0
        /// <summary> Deletes from the persistent storage all UserAccount entities which have data in common with the specified related Entities. If one is omitted, that entity is not used as a filter.</summary>
        /// <remarks>Runs directly on the persistent storage. It will not delete entity objects from the current collection.</remarks>
        /// <param name="accountInstance">AccountEntity instance to use as a filter for the UserAccountEntity objects to return</param>
        /// <param name="userInstance">UserEntity instance to use as a filter for the UserAccountEntity objects to return</param>
        /// <returns>Amount of entities affected, if the used persistent storage has rowcounting enabled.</returns>
        public int DeleteMultiManyToOne(IEntity accountInstance, IEntity userInstance)
        {
            UserAccountDAO dao = DAOFactory.CreateUserAccountDAO();

            return(dao.DeleteMulti(base.Transaction, accountInstance, userInstance));
        }