/// <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); } }
/// <summary> /// Update the state property of an intervention /// </summary> /// <param name="interventionId">The guid of an intervention</param> /// <param name="state">The state of an intervention</param> /// <returns>True if success, false if fail</returns> public bool updateInterventionState(Guid interventionId, InterventionState state) { Intervention intervention = getInterventionById(interventionId); if (intervention.CreatedBy == getDetail().Id) { if (state == InterventionState.Approved) { return(approveAnIntervention(interventionId)); } else { return(interventionService.updateInterventionState(interventionId, state)); } } else { return(false); } }