/// <summary>
        /// Handles the view call, and process the resident information from the view, and inserts it to the text file
        /// </summary>
        /// <param name="newResident">Contains the complete information of the new resident, except for an residentId/param>
        public void PostAddResident(IResident newResident)
        {
            List <Resident> residents = dbEnt.Resident.Residents();

            newResident.Resident.ResidentId = residents.Count > 0 ? residents.Max(m => m.ResidentId) + 1 : 1;

            bool status = dbEnt.Resident.InsertResident(newResident.Resident);

            if (status)
            {
                MessageBox.Show("Resident " + newResident.Resident.FirstName + " " + newResident.Resident.LastName + " was successfully added.", "New Resident Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewContext.Dispose();
                // go back to landing page
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("New resident record with name: " + newResident.Resident.FirstName + " " + newResident.Resident.LastName);
                MenuHelper.MenuInput();
            }
            else
            {
                MessageBox.Show("Resident was not added.", "New Resident Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ViewContext.Dispose();
                // reload view
                new ResidentPresenter().GetAddResident();
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the creation of a summon report using the field text from the view
        /// </summary>
        /// <param name="newSummon">Contains the report information given by the user</param>
        public void PostCreateSummon(ISummon newSummon)
        {
            Summon summon = newSummon.Summon;

            summon.ReportedDate = DateTime.Now.Date;

            List <Summon> summons = dbEnt.Summon.Summons();

            summon.SummonId  = summons.Count > 0 ? summons.Max(m => m.SummonId) + 1 : 1;
            summon.AccountId = UserSession.User.AccountId;

            bool status = dbEnt.Summon.InsertSummon(summon);

            if (status)
            {
                MessageBox.Show("New summon report created successfully.", "New Summon Report", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewContext.Dispose();
                // go back to landing page
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("New summon created with Id " + summon.SummonId);
                MenuHelper.MenuInput();
            }
            else
            {
                MessageBox.Show("Unavailable to create new summon report.", "New Summon Report", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // reload view
                new SummonPresenter().GetCreateSummon();
            }
        }
        /// <summary>
        /// Receives the parameters from the view and finds the residents using the resident ids to create a family record
        /// </summary>
        /// <param name="parentOneId"></param>
        /// <param name="parentTwoId">Optional</param>
        /// <param name="familyMembers">Number of family members</param>
        public void PostSaveFamily(int parentOneId, int parentTwoId, int familyMembers)
        {
            List <Family> families = dbEnt.Family.Families();

            Family newFamily = new Family();

            newFamily.FamilyId      = families.Count > 0 ? families.Max(m => m.FamilyId) + 1 : 1;
            newFamily.FamilyMembers = familyMembers;
            newFamily.ParentOneId   = parentOneId;

            if (parentTwoId != null || parentTwoId > 0)
            {
                newFamily.ParentTwoId = parentTwoId;
            }

            bool status = dbEnt.Family.InsertFamily(newFamily);

            if (status)
            {
                MessageBox.Show("Family record was successfully created.", "New Family Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewContext.Dispose();
                // go back to landing page
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("New family recorded.");
                MenuHelper.MenuInput();
            }
            else
            {
                MessageBox.Show("Unable to create new family record.", "New Family Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // reload view
                new ResidentPresenter().GetAddFamily();
            }
        }
        /// <summary>
        /// Handles the change of the a certain family record's family size
        /// </summary>
        /// <param name="familyId"></param>
        /// <param name="newFamilySize"></param>
        public void PostChangeFamilySize(int familyId, int newFamilySize)
        {
            List <Family> families = dbEnt.Family.Families();
            Family        family   = families.Where(m => m.FamilyId == familyId).FirstOrDefault();

            // remove old record from the list
            families.Remove(family);
            // update family members
            family.FamilyMembers = newFamilySize;
            // reinsert
            families.Add(family);
            // upload to text file

            bool status = dbEnt.Family.SaveFamilies(families);

            if (status)
            {
                MessageBox.Show("Family record's family size update with primary parent " + family.ParentOne.FirstName + " " + family.ParentOne.LastName, "Change Family Size", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewContext.Dispose();
                // go back to landing page
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("Family record's family size change with primary parent " + family.ParentOne.FirstName + " " + family.ParentOne.LastName);
                MenuHelper.MenuInput();
            }
            else
            {
                MessageBox.Show("Unable update family size.", "Family Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // reload view
                new ResidentPresenter().GetDisplayFamilies();
            }
        }
        /// <summary>
        /// Recieves the data from the view that contains the resident information that were changed, and saves it
        /// to the text file
        /// </summary>
        /// <param name="view">Contains the updated resident model</param>
        public void PostUpdateResident(IResident view)
        {
            List <Resident> residents = dbEnt.Resident.Residents();

            // remove the old version resident from residents
            residents.Remove(residents.Where(m => m.ResidentId == view.Resident.ResidentId).FirstOrDefault());
            // re-insert the new version of resident to list
            residents.Add(view.Resident);
            // update text file

            bool status = dbEnt.Resident.SaveResidents(residents);

            if (status)
            {
                MessageBox.Show("Resident " + view.Resident.FirstName + " " + view.Resident.LastName + "'s record was updated successfully.", "Update Resident", MessageBoxButtons.OK, MessageBoxIcon.Information);
                // go back to landing page
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("Resident information updated with name: " + view.Resident.FirstName + " " + view.Resident.LastName);
                ViewContext.Dispose();
                MenuHelper.MenuInput();
            }
            else
            {
                MessageBox.Show("Resident " + view.Resident.FirstName + " " + view.Resident.LastName + "'s record was not updated.", "Update Resident", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // reload view
                ViewContext.Dispose();
                new ResidentPresenter().GetDisplayResidents();
            }
        }
Пример #6
0
        /// <summary>
        /// Registers the resident information into a user account
        /// </summary>
        /// <param name="selectedResident">Obtains the Resident model which contains the selected resident to be registered</param>
        public void PostRegisterAccount(IResident selectedResident)
        {
            Cryptography ceaser = new Cryptography();

            Account newAccount = new Account();

            newAccount.AccountId      = dbEnt.Account.Accounts().Max(m => m.AccountId) + 1; // only gets the highest Id number for increment
            newAccount.Username       = selectedResident.Resident.FirstName.ToLower() + "_" + selectedResident.Resident.LastName.ToLower();
            newAccount.Password       = ceaser.Encrypt(SystemConstants.ACCOUNT_DEFAULT_PASSWORD);
            newAccount.ResidentId     = selectedResident.Resident.ResidentId;
            newAccount.RegisteredDate = DateTime.Now;
            newAccount.AccountStatus  = SystemConstants.ACCOUNT_STATUS_ACTIVE;

            bool status = dbEnt.Account.InsertAccount(newAccount);

            if (status)
            {
                MessageBox.Show("Account for " + selectedResident.Resident.FirstName + " " + selectedResident.Resident.LastName + " was registered successfully.", "Register Account", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewContext.Dispose();
                // go back to landing page
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("Registered new account with username: "******"Account for " + selectedResident.Resident.FirstName + " " + selectedResident.Resident.LastName + " was not registered. Please try again", "Register Account", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ViewContext.Dispose();
                // reload resident selection for register
                new AccountPresenter().GetRegisterAccount();
            }
        }
Пример #7
0
        /// <summary>
        /// Action that handles the login, accepts the login credentials
        /// </summary>
        /// <param name="loginCredentials">The values from the login view</param>
        public void PostLogin(IAccount loginCredentials)
        {
            LoginHelper.LoginUser
            (
                loginCredentials,
                dbEnt.Account.Accounts().Where(m => m.AccountStatus == SystemConstants.ACCOUNT_STATUS_ACTIVE).ToList() // filter accounts, only active accounts
            );

            // uses the session to determine if there is a logged in user
            if (UserSession.LoggedIn == false)
            {
                // load view again
                MessageBox.Show("Invalid Login credentials.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ViewContext.Dispose();
                new AccountPresenter().GetLogin();
            }
            else
            {
                // load landing page, dashboard
                MessageBox.Show("Login Success.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewContext.Dispose();
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("User logged in.");
                MenuHelper.MenuInput();
            }
        }
Пример #8
0
        /// <summary>
        /// Sets the accounts record with the accountId, and set its status as ARCHIVED
        /// </summary>
        /// <param name="accountId">The account Id of the user that will be archived</param>
        public void DeleteAccount(int accountId)
        {
            Account        toDelete = dbEnt.Account.Accounts().Where(m => m.AccountId == accountId).FirstOrDefault();
            List <Account> accounts = dbEnt.Account.Accounts();

            // removes the old record
            accounts.Remove(accounts.Where(m => m.AccountId == toDelete.AccountId).FirstOrDefault());
            // re-insert the modified account
            toDelete.AccountStatus = SystemConstants.ACCOUNT_STATUS_ARCHIVED;
            accounts.Add(toDelete);

            // updates the account
            bool status = dbEnt.Account.SaveAccounts(accounts);

            if (status)
            {
                MessageBox.Show("Account was deleted successfully.", "Delete Account", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewContext.Dispose();
                /* Audit TRAIL RECORD and System PROMPT */
                AuditTrailHelper.RecordAction("Account was deleted with username: "******"Account was not able to be archived.", "Delete Account", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ViewContext.Dispose();
                // reload resident selection for register
                new AccountPresenter().GetDisplayAccounts();
            }
        }
        /// <summary>
        /// Receives the residentId of the resident that status' will be set to deceased
        /// </summary>
        /// <param name="residentId">The id of the resident that is deceased</param>
        public void PostToResidentDeceased(int residentId)
        {
            List <Resident> residents  = dbEnt.Resident.Residents();
            Resident        toDeceased = residents.Where(m => m.ResidentId == residentId).FirstOrDefault();

            if (toDeceased != null)
            {
                // remove from list
                residents.Remove(toDeceased);
                // re-insert
                toDeceased.Status = SystemConstants.RESIDENT_STATUS_DECEASED;
                residents.Add(toDeceased);
                // update text file
                bool status = dbEnt.Resident.SaveResidents(residents);

                if (status)
                {
                    MessageBox.Show("Resident " + toDeceased.FirstName + " " + toDeceased.LastName + "'s status is set to as deceased.", "Deceased Resident", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // go back to landing page
                    ViewContext.Dispose();
                    /* Audit TRAIL RECORD and System PROMPT */
                    AuditTrailHelper.RecordAction("Resident " + toDeceased.FirstName + " " + toDeceased.LastName + " is set to deceased.");
                    MenuHelper.MenuInput();
                }
                else
                {
                    MessageBox.Show("Resident " + toDeceased.FirstName + " " + toDeceased.LastName + "'s status was not able to be set to deceased.", "Deceased Resident", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ViewContext.Dispose();
                    // reload view
                    new ResidentPresenter().GetViewResident(toDeceased.ResidentId);
                }
            }
            else
            {
                MessageBox.Show("Resident cannot be found.", "Deceased Resident", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ViewContext.Dispose();
                // reload view
                new ResidentPresenter().GetDisplayResidents();
            }
        }