/// <summary> /// Get the current User instance /// </summary> /// <returns>The current user</returns> public User GetDetail() { var user = new User(Users.fetchUserByIdentityId(managerIdentityId)); user.District = new District(Districts.fetchDistrictById(user.DistrictId.Value)); return(user); }
/// <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> /// Update the quality information of the intervention, comments, remainlife, recentvisit date /// </summary> /// <param name="interventionId">The guid of an intervention</param> /// <param name="comments">The comments of an intervention</param> /// <param name="remainLife">The remaining life of an intervention</param> /// <param name="lastVisitDate">The recent visit date of an intervention</param> /// <returns>True if success, false if fail</returns> public bool updateInterventionDetail(Guid interventionId, string comments, int remainLife, DateTime lastVisitDate) { var intervention = getInterventionById(interventionId); var interventionDistrict = Districts.fetchDistrictById(Clients.fetchClientById(intervention.ClientId.Value).DistrictId); var district = Districts.fetchDistrictById(getDetail().DistrictId.Value); if (interventionDistrict.Name == district.Name) { return(interventionService.updateInterventionDetail(interventionId, comments, remainLife, lastVisitDate)); } else { return(false); } }
/// <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); }
/// <summary> /// Update the state of an intervention /// </summary> /// <param name="interventionId">The guid of an intervention</param> /// <param name="state">The enum intervention state to update to</param> /// <returns>True if successfully updated, false if fail</returns> public bool UpdateInterventionState(Guid interventionId, InterventionState state) { //create intervention instance from guid var intervention = GetInterventionById(interventionId); //create an instance of district object with the intervention's client's district id var interventionDistrict = Districts.fetchDistrictById(Clients.fetchClientById(intervention.ClientId.Value).DistrictId); //create an instance of district from the current user's district id var district = Districts.fetchDistrictById(GetDetail().DistrictId.Value); //if district is same, then update the state of the intervention if (interventionDistrict.Name == district.Name) { return(interventionService.updateInterventionState(interventionId, state)); } else { return(false); } }
/// <summary> /// Update Approved by property of the intervention /// </summary> /// <param name="interventionId">The guid of an intervention</param> /// <param name="userId">The current user id</param> /// <returns>True if success, false if fail</returns> public bool UpdateInterventionApproveBy(Guid interventionId, Guid userId) { //create intervention instance with guid Intervention intervention = GetInterventionById(interventionId); //create an instance of district object with the intervention's client's district id var interventionDistrict = Districts.fetchDistrictById(Clients.fetchClientById(intervention.ClientId.Value).DistrictId); //get district from the current user district var district = Districts.fetchDistrictById(GetDetail().DistrictId.Value); //if the district is the same approve it and update approve by //return true is success, else false if (interventionDistrict.Name == district.Name) { User user = new User(Users.fetchUserById(userId)); return(interventionService.updateIntervetionApprovedBy(interventionId, user)); } else { return(false); } }
/// <summary> /// Get a district from it's id /// </summary> /// <param name="Id">The guid of a district</param> /// <returns>A district instance</returns> public District GetDistrictById(Guid Id) { return(new District(Districts.fetchDistrictById(Id))); }
/// <summary> /// Get the district for the user /// </summary> /// <param name="userId">the user id</param> /// <returns></returns> public District getDistrictForUser(Guid userId) { return(new District(Districts.fetchDistrictById(getUserById(userId).DistrictId.Value))); }