/// <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> /// 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); } }
/// <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)); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
//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); }