Esempio n. 1
0
        public void OnGet()
        {
            AdminDataService IfaceAdmin = new AdminDataService();

            PrizeNameList  = IfaceAdmin.GetAllPrizesName();
            PrizeValueList = IfaceAdmin.GetAllPrizesValue();
        }
Esempio n. 2
0
        public IActionResult OnPostDeletePrize()
        {
            TempData.Remove("Action");
            TempData.Remove("Actiontype");
            AdminDataService IfaceAdmin = new AdminDataService();

            PrizeIdList    = IfaceAdmin.GetPrizesId();
            PrizeNameList  = IfaceAdmin.GetAllPrizesName();
            PrizeValueList = IfaceAdmin.GetAllPrizesValue();
            if (PrizeIdList == null || PrizeNameList == null || PrizeValueList == null)
            {
                DisplayMessage = "Error Retrieving Prize List from Database. Connection" +
                                 " to database failed or no prizes exist yet.";
            }
            TempData["Action"]     = "DeletePrize";
            TempData["Actiontype"] = "Prize";
            return(Page());
        }
Esempio n. 3
0
        // Activates when Submit button on admin page is clicked.
        public IActionResult OnPostSubmit()
        {
            AdminDataService IfaceAdmin  = new AdminDataService();
            bool             success     = true;
            bool             defaultCase = false;

            TempData.Keep("Action");
            TempData.Keep("Actiontype");

            // Basic error checking, Need to reset TempData as well
            if (UID == "" || UID == null)
            {
                DisplayMessage = $"Error Occurred due to ID/Prize Field Empty.";
                return(Page());
            }
            if (Action == "" || Action == null)
            {
                DisplayMessage = $"Error Occurred due to Action not specified.";
                return(Page());
            }
            if ((ChangeValue <= 0) && !(Action == "AddAccount" || Action == "CheckBalance" || Action == "DeletePrize" || Action == "DeleteAccount"))
            {
                DisplayMessage = $"Error Occurred due Value <= 0. Please enter a valid number.";
                PointMessage   = $"Could not Complete Action, enter a positive number.";
                return(Page());
            }
            if (Actiontype == "User")
            {
                Student            student      = new Student();
                StudentDataService IfaceStudent = new StudentDataService();
                if ((student = IfaceStudent.GetStudentCampusId(UID)) != null)
                {
                    switch (Action)
                    {
                    case "AddAccount":
                        success      = IfaceAdmin.AddAccount(UID);
                        PointMessage = "Student account added successfully.";
                        break;

                    case "CheckBalance":
                        PointMessage = student.total_points.ToString();
                        break;

                    case "IncreasePoint":
                        success      = IfaceAdmin.IncrementPoints(UID, ChangeValue);
                        PointMessage = $" {student.first_name} {student.last_name} has {IfaceAdmin.CheckPoints(UID).ToString()} Points";
                        break;

                    case "DecreasePoint":
                        success = IfaceAdmin.DecrementPoints(UID, ChangeValue);
                        break;

                    case "SetPoint":
                        success = IfaceAdmin.SetPoints(UID, ChangeValue);
                        break;

                    case "DeleteAccount":
                        success = IfaceStudent.DeleteStudent(student.campus_id);
                        break;

                    default:
                        DisplayMessage = $"Error Occurred due to Action variable undefined.";
                        PointMessage   = $"Could not Complete Action";
                        defaultCase    = true;
                        success        = false;
                        break;
                    }

                    if (success)
                    {
                        if (Action != "DeleteAccount")
                        {
                            PointMessage = $" {student.first_name} {student.last_name} has {IfaceAdmin.CheckPoints(UID).ToString()} Points";
                        }
                        DisplayMessage = $"Transaction success with {student.first_name} {student.last_name}";
                    }
                    else if (defaultCase)
                    {
                        // do Nothing
                    }
                    else
                    {
                        DisplayMessage = $"Action Failed due to database operation issue!";
                        PointMessage   = $"Could not Complete Action";
                    }
                }
                else
                {
                    switch (Action)
                    {
                    case "AddAccount":
                        success      = IfaceAdmin.AddAccount(UID);
                        PointMessage = "Student account added successfully.";
                        break;

                    default:
                        DisplayMessage = $"Error Occurred due to Student not found.";
                        break;
                    }
                }
            }
            else if (Actiontype == "Prize")
            {
                switch (Action)
                {
                case "SetPrize":
                    success = IfaceAdmin.UpdatePrizePoints(UID, ChangeValue);
                    break;

                case "AddPrize":
                    success = IfaceAdmin.AddPrize(UID, ChangeValue);
                    break;

                case "DeletePrize":
                    success = IfaceAdmin.DeletePrize(UID);
                    break;

                default:
                    DisplayMessage = $"Error Occurred due to Action variable undefined.";
                    defaultCase    = true;
                    success        = false;
                    break;
                }
                PrizeIdList    = IfaceAdmin.GetPrizesId();
                PrizeNameList  = IfaceAdmin.GetAllPrizesName();
                PrizeValueList = IfaceAdmin.GetAllPrizesValue();
                if (success)
                {
                    PointMessage = $"Transaction Success with Prize {UID}";
                }
                else if (defaultCase)
                {
                    //Do Nothing
                }
                else
                {
                    DisplayMessage = $"Transaction Failed due to database operation issue! Check if Prize is valid.";
                }
            }
            else
            {
                DisplayMessage = $"Action Type Undefinied!";
            }

            return(Page());
        }