public async Task <ActionResult <EmployeeFeatureUpdationDetailDto> > RemoveEmployeeFeatureException( GetEmployeeFeatureUpdateDto getEmployeeFeatureUpdateDto) { var result = await _featureService.RemoveFeatureFromEmployeeAsync(getEmployeeFeatureUpdateDto); if (result == null) { return(BadRequest("Employee already does not have this feature.")); } return(Ok(result)); }
/// <summary> /// this method is used to add new feature to given employee /// </summary> /// <param name="getEmployeeFeatureUpdate">employee and feature id</param> /// <returns>returns given feature permission details for given employee </returns> public async Task <EmployeeFeatureUpdationDetailDto> AddFeatureFromEmployeeAsync(GetEmployeeFeatureUpdateDto getEmployeeFeatureUpdate) { var baseFeatures = await GetEmployeeBaseFeaturesAsync(getEmployeeFeatureUpdate.EmployeeId); if (baseFeatures.Count > 0 && baseFeatures.Contains(getEmployeeFeatureUpdate.FeatureName)) { var exceptionFeature = await _featureRepository.GetEmployeeExceptionAsync(getEmployeeFeatureUpdate.EmployeeId, getEmployeeFeatureUpdate.FeatureName); if (exceptionFeature?.AdditionalFeatureIsDeleted == true) { _featureRepository.RemoveException(exceptionFeature); await _featureRepository.SaveChangesAsync(); } else { return(null); //TODO excptionHandeling var response = CreateResponseService.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request!", "Employee already have this feature."); throw new HttpResponseException(response); } } else { var exceptionFeature = new FeatureException { ExceptionFeature = getEmployeeFeatureUpdate.FeatureName, AdditionalFeatureIsDeleted = false, EmployeeId = getEmployeeFeatureUpdate.EmployeeId }; _featureRepository.AddException(exceptionFeature); await _featureRepository.SaveChangesAsync(); } return(new EmployeeFeatureUpdationDetailDto() { EmployeeId = getEmployeeFeatureUpdate.EmployeeId, FeatureName = getEmployeeFeatureUpdate.FeatureName, FeatureModification = modification[0] }); }