Exemplo n.º 1
0
        /// <summary>
        /// Approve an intervention
        /// </summary>
        /// <param name="interventionId">The guid of an intervention</param>
        /// <returns>True if successfully approved an intervention, false if fail</returns>
        public bool ApproveAnIntervention(Guid interventionId)
        {
            //create instance of intervention from guid
            var intervention = GetInterventionById(interventionId);
            //create instance of intervention type from intervention type id using interventionType
            var interventionType = InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value);

            //create instance of client from intervention's client id
            var client = Clients.fetchClientById(intervention.ClientId.Value);

            //create instance of the current user
            var user = GetDetail();

            //if the criteria of approve an intervention meets then update the state of an intervention
            if (client.DistrictId == user.DistrictId && user.AuthorisedHours >= intervention.Hours &&
                user.AuthorisedCosts >= intervention.Costs && user.AuthorisedCosts >= interventionType.Costs &&
                user.AuthorisedHours >= interventionType.Hours)
            {
                return(interventionService.updateInterventionState(interventionId, InterventionState.Approved, user.Id));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Approve an intervention
        /// </summary>
        /// <param name="interventionId">The guid of an intervention</param>
        /// <returns>True if success, false if fail</returns>
        public bool approveAnIntervention(Guid interventionId)
        {
            var intervention     = getInterventionById(interventionId);
            var interventionType = InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value);
            var client           = getClientById(intervention.ClientId.Value);
            var user             = getDetail();

            //if meets approve criteria,approve it by engineer self and update approve by
            if (client.DistrictId == user.DistrictId && user.AuthorisedHours >= intervention.Hours && user.AuthorisedCosts >= intervention.Costs && user.AuthorisedCosts >= interventionType.Costs && user.AuthorisedHours >= interventionType.Hours)
            {
                if (interventionService.updateInterventionState(interventionId, InterventionState.Approved, user.Id))
                {
                    return(Interventions.ApproveIntervention(intervention));
                }
                else
                {
                    return(false);
                }
                //return Interventions.ApproveIntervention(intervention);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns an icon dictionary of the enumeration.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static Dictionary <int, string> Icons(this InterventionTypes item)
        {
            Dictionary <int, string> icons = new Dictionary <int, string>();

            switch (item)
            {
            case InterventionTypes.AskForHelp:
                icons.Add(1, "alert");
                icons.Add(2, "comment");
                break;

            case InterventionTypes.AvailableDetails:
                icons.Add(1, "user");
                icons.Add(2, "flag");
                break;

            case InterventionTypes.ClassmatesAvailable:
                icons.Add(1, "user");
                icons.Add(2, "flag");
                break;

            case InterventionTypes.MakeAPost:
                icons.Add(1, "comment");
                icons.Add(2, "thumbs-up");
                break;

            case InterventionTypes.MakeAPostAssignmentSubmit:
                icons.Add(1, "comment");
                icons.Add(2, "thumbs-up");
                break;

            case InterventionTypes.OfferHelp:
                icons.Add(1, "education");
                icons.Add(2, "thumbs-up");
                break;

            case InterventionTypes.UnansweredQuestions:
                icons.Add(1, "sunglasses");
                icons.Add(2, "thumbs-up");
                break;

            case InterventionTypes.UnansweredQuestionsAlternate:
                icons.Add(1, "sunglasses");
                icons.Add(2, "thumbs-up");
                break;

            case InterventionTypes.BuildFailure:
                icons.Add(1, "alert");
                icons.Add(2, "comment");
                break;

            default:
                icons.Add(1, "alert");
                icons.Add(2, "comment");
                break;
            }
            return(icons);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create an intervention
        /// </summary>
        /// <param name="intervention">An intervention instance</param>
        /// <returns>An instance of Intervention created</returns>
        public bool createIntervention(Intervention intervention)
        {
            var newIntervention = new Intervention(Interventions.create(intervention));

            newIntervention.InterventionType = new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
            newIntervention.Client           = new Client(Clients.fetchClientById((Guid)newIntervention.ClientId));          ///new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
            newIntervention.District         = new District(Districts.fetchDistrictById(newIntervention.Client.DistrictId)); //new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));

            return(approveAnIntervention(newIntervention.Id));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get an non-guid intervention form it's id
        /// </summary>
        /// <param name="interventionId">The guid of an intervention</param>
        /// <returns>The intervention instance</returns>
        public Intervention getNonGuidInterventionById(Guid interventionId)
        {
            Intervention intervention = new Intervention(Interventions.fetchInterventionsById(interventionId));

            // intervention.LifeRemaining=
            intervention.InterventionType = new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
            intervention.Client           = new Client(Clients.fetchClientById(intervention.ClientId.Value));
            intervention.District         = new District(Districts.fetchDistrictById(intervention.Client.DistrictId));


            return(intervention);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get all the interventions for a client
        /// </summary>
        /// <param name="clientId">The guid of a client</param>
        /// <returns>A list of interventions</returns>
        public IEnumerable <Intervention> getInterventionsByClient(Guid clientId)
        {
            var interventions = Interventions.fetchInterventionsByClientId(clientId).Select(c => new Intervention(c)).ToList();

            foreach (var intervention in interventions)
            {
                intervention.InterventionType = new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
                intervention.Client           = new Client(Clients.fetchClientById(intervention.ClientId.Value));
                intervention.District         = new District(Districts.fetchDistrictById(intervention.Client.DistrictId));
            }

            interventions.RemoveAll(i => i.InterventionState == InterventionState.Cancelled);
            return(interventions);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns a bool corresponding to whether the content of the suggestion comes before or after the link text of the enumeration.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static bool ContentFirst(this InterventionTypes item)
        {
            bool contentFirst = false;

            switch (item)
            {
            case InterventionTypes.AskForHelp:
                contentFirst = false;
                break;

            case InterventionTypes.AvailableDetails:
                contentFirst = true;
                break;

            case InterventionTypes.ClassmatesAvailable:
                contentFirst = true;
                break;

            case InterventionTypes.MakeAPost:
                contentFirst = true;
                break;

            case InterventionTypes.MakeAPostAssignmentSubmit:
                contentFirst = true;
                break;

            case InterventionTypes.OfferHelp:
                contentFirst = true;
                break;

            case InterventionTypes.UnansweredQuestions:
                contentFirst = true;
                break;

            case InterventionTypes.BuildFailure:
                contentFirst = false;
                break;

            case InterventionTypes.UnansweredQuestionsAlternate:
                contentFirst = true;
                break;

            default:
                contentFirst = false;
                break;
            }
            return(contentFirst);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns a long-form description of the enumeration.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static string TemplateText(this InterventionTypes item)
        {
            string template = "";

            switch (item)
            {
            case InterventionTypes.AskForHelp:
                template = "Hey all, I recently got a run-time error: |||[... describe run-time error here ...]||| Does anyone have any tips on how I could resolve this? \n\nI have tried [... describe what you've tried so far...].\n";
                break;

            case InterventionTypes.AvailableDetails:
                template = "Find out what people are talking about. Ask these classmates or the entire class a question!\n";
                break;

            case InterventionTypes.ClassmatesAvailable:
                template = "Hey all, I having difficulty with my program. I am running into [... describe the {error message / runtime-error / build error} here ...]. Does anyone have any tips on how I could resolve this? \n\nI have tried [... describe what you've tried so far...]\n";
                break;

            case InterventionTypes.MakeAPost:
                template = "Type your post here! Use '#' to create a new topic!\n";
                break;

            case InterventionTypes.MakeAPostAssignmentSubmit:
                template = "Hey all, I'm done with |||[assignment # here]||| and am available if anyone wants to talk about it! \n\nI found [... aspect of assignment ...] especially [interesting/fun/tricky/etc.]. \n\n I overcame these issues by [... describe how you resolved these issues ...]\n\n One thing I learned that that might help you is: [... describe what you learned while completing this assignment ...].\n";
                break;

            case InterventionTypes.OfferHelp:
                template = "Hey all, I'm done with |||[assignment # here]||| and am available if anyone wants to talk about it! \n\nI found [... aspect of assignment ...] especially [interesting/fun/tricky/etc.].\n";
                break;

            case InterventionTypes.UnansweredQuestions:
                template = "";
                break;

            case InterventionTypes.BuildFailure:
                template = "Hey all, I recently got build errors: ||| [... describe build errors here ...] ||| Does anyone have any tips on how I could resolve this? \n\nI have tried [... describe what you've tried so far...].\n";
                break;

            case InterventionTypes.UnansweredQuestionsAlternate:
                template = "";
                break;

            default:
                template = "This message does not yet have a template. You should not see this message!.\n";
                break;
            }
            return(template);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns a string listItemContent of the enumeration.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static string ListItemContent(this InterventionTypes item)
        {
            string listItemContent = "";

            switch (item)
            {
            case InterventionTypes.AskForHelp:
                listItemContent = "about these run-time errors.";
                break;

            case InterventionTypes.AvailableDetails:
                listItemContent = "You have said you're available to help your classmates. ";
                break;

            case InterventionTypes.ClassmatesAvailable:
                listItemContent = "Some of your classmates are offering help. ";
                break;

            case InterventionTypes.MakeAPost:
                listItemContent = "What's going on right now?";
                break;

            case InterventionTypes.MakeAPostAssignmentSubmit:
                listItemContent = "You've submitted your assignment.";
                break;

            case InterventionTypes.OfferHelp:
                listItemContent = "You've submitted your assignment early! ";
                break;

            case InterventionTypes.UnansweredQuestions:
                listItemContent = "Other students have encountered issues you may have recently resolved. ";
                break;

            case InterventionTypes.UnansweredQuestionsAlternate:
                listItemContent = "Other students have unanswered questions. ";
                break;

            case InterventionTypes.BuildFailure:
                listItemContent = "about these build errors.";
                break;

            default:
                listItemContent = "";
                break;
            }
            return(listItemContent);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a string link text of the enumeration.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static string LinkText(this InterventionTypes item)
        {
            string linkText = "";

            switch (item)
            {
            case InterventionTypes.AskForHelp:
                linkText = "Ask a question ";
                break;

            case InterventionTypes.AvailableDetails:
                linkText = "View/Change your status. ";
                break;

            case InterventionTypes.ClassmatesAvailable:
                linkText = "Ask for assistance!";
                break;

            case InterventionTypes.MakeAPost:
                linkText = "Tell others what you're doing!";
                break;

            case InterventionTypes.MakeAPostAssignmentSubmit:
                linkText = "Make a post about it!";
                break;

            case InterventionTypes.OfferHelp:
                linkText = "Let your classmates know you can help them!";
                break;

            case InterventionTypes.UnansweredQuestions:
                linkText = "Help your classmates out!";
                break;

            case InterventionTypes.UnansweredQuestionsAlternate:
                linkText = "Take a look at their questions!";
                break;

            case InterventionTypes.BuildFailure:
                linkText = "Ask a question ";
                break;

            default:
                linkText = "";
                break;
            }
            return(linkText);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Returns a string title of the enumeration.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static string Title(this InterventionTypes item)
        {
            string title = "";

            switch (item)
            {
            case InterventionTypes.AskForHelp:
                title = "Runtime Errors: Get Help!";
                break;

            case InterventionTypes.AvailableDetails:
                title = "You Are Available!";
                break;

            case InterventionTypes.ClassmatesAvailable:
                title = "Others Available to Help!";
                break;

            case InterventionTypes.MakeAPost:
                title = "Make A Post!";
                break;

            case InterventionTypes.MakeAPostAssignmentSubmit:
                title = "Make a Post!";
                break;

            case InterventionTypes.OfferHelp:
                title = "Help Your Classmates!";
                break;

            case InterventionTypes.UnansweredQuestions:
                title = "Help other Students!";
                break;

            case InterventionTypes.UnansweredQuestionsAlternate:
                title = "Help Another Student!";
                break;

            case InterventionTypes.BuildFailure:
                title = "Build Errors: Get Help!";
                break;

            default:
                title = "";
                break;
            }
            return(title);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get a list of interventions from the state they are in
        /// </summary>
        /// <param name="state">The state of an intervention</param>
        /// <returns>A list of intervention</returns>
        public IEnumerable <Intervention> GetInterventionsByState(InterventionState state)
        {
            var interventions = Interventions.fetchInterventionsByState((int)state).Select(c => new Intervention(c)).ToList();
            List <Intervention> managerInterventions = new List <Intervention>();
            User manager = GetDetail();

            foreach (var intervention in interventions)
            {
                intervention.Client           = new Client(Clients.fetchClientById(intervention.ClientId.Value));
                intervention.InterventionType = new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
                intervention.District         = new District(Districts.fetchDistrictById(intervention.Client.DistrictId));
                if (manager.DistrictId == intervention.District.Id)
                {
                    managerInterventions.Add(intervention);
                }
            }
            return(managerInterventions);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get approved Interventions of the current Manager
        /// </summary>
        /// <returns>A list of Intervention with interventionType, client, district property</returns>
        public IEnumerable <Intervention> GetApprovedInterventions()
        {
            //get intervention by state approved and complete
            var interventions = Interventions.fetchInterventionsByState((int)InterventionState.Approved).Select(c => new Intervention(c)).ToList();

            interventions.AddRange(Interventions.fetchInterventionsByState((int)InterventionState.Completed).Select(c => new Intervention(c)).ToList());

            //only select interventions approved by this manager
            interventions = interventions.Where(x => x.ApprovedBy == managerId).ToList();

            foreach (var intervention in interventions)
            {
                intervention.InterventionType = new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
                intervention.Client           = new Client(Clients.fetchClientById(intervention.ClientId.Value));
                intervention.District         = new District(Districts.fetchDistrictById(intervention.Client.DistrictId));
            }
            return(interventions);
        }
Exemplo n.º 14
0
        //public IEnumerable<Intervention> GetNonGuidIntervention(Guid interventionId)
        //{
        //    IEnumerable<Intervention> inters=Interventions.fetchInterventionsListById(interventionId).ToList();



        //    // interventionList.RemoveAll(i => i.InterventionState == InterventionState.Cancelled);


        //    foreach (var intervention in interventionList)
        //    {
        //        intervention.InterventionType = new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
        //        intervention.Client = new Client(Clients.fetchClientById(intervention.ClientId.Value));
        //        intervention.District = new District(Districts.fetchDistrictById(intervention.Client.DistrictId));

        //    }
        //    return interventionList;
        //}


        /// <summary>
        /// Get a list of interventions created by this user
        /// </summary>
        /// <param name="userId">The guid of an user</param>
        /// <returns>A list of interventions</returns>
        public IEnumerable <Intervention> GetAllInterventions(Guid userId)
        {
            var interventionList = new List <Intervention>();

            interventionList.AddRange(Interventions.fetchInterventionsByCreator(userId).Select(c => new Intervention(c)).ToList());


            interventionList.RemoveAll(i => i.InterventionState == InterventionState.Cancelled);


            foreach (var intervention in interventionList)
            {
                intervention.InterventionType = new InterventionType(InterventionTypes.fetchInterventionTypesById(intervention.InterventionTypeId.Value));
                intervention.Client           = new Client(Clients.fetchClientById(intervention.ClientId.Value));
                intervention.District         = new District(Districts.fetchDistrictById(intervention.Client.DistrictId));
            }
            return(interventionList);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Returns the string name of the InterventionType.
 /// EX: SomeEnum will get returned as "SomeEnum".
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public static string Explode(this InterventionTypes item)
 {
     return(item.ToString());
 }