public static ErrorResult MapToErrorResponse(this FeatureException featureException) { var errorResponse = new ErrorResponse { Errors = new List <ErrorModel> { new ErrorModel { Status = (int)featureException.HttpStatusCode, Message = featureException.Message, Description = featureException.Description } } }; return(new ErrorResult((int)featureException.HttpStatusCode, errorResponse)); }
/// <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] }); }
/// <summary> /// this method is used to remove exception from database /// </summary> /// <param name="exception">exception table object</param> public void RemoveException(FeatureException exception) { _dbContext.FeatureException.Remove(exception); }
/// <summary> /// this method is used to add new exception in database /// </summary> /// <param name="exception">exception table object</param> public void AddException(FeatureException exception) { _dbContext.FeatureException.Add(exception); }