public async Task <CategorySchemaServiceModel> GetCategorySchemaAsync(GetCategorySchemaServiceModel model) { var categorySchemas = from c in this.context.Categories join cs in this.context.CategorySchemas on c.Id equals cs.CategoryId into csx from x in csx.DefaultIfEmpty() where x != null && c.Id == model.CategoryId && (x.Language == model.Language || x.Language == null) && c.IsActive select new CategorySchemaServiceModel { Id = x.Id, CategoryId = c.Id, Schema = x.Schema, UiSchema = x.UiSchema, LastModifiedDate = x.LastModifiedDate, CreatedDate = x.CreatedDate }; return(await categorySchemas.FirstOrDefaultAsync()); }
public async Task <IActionResult> GetCategorySchemaByCategoryId(Guid?categoryId) { var serviceModel = new GetCategorySchemaServiceModel { CategoryId = categoryId, Language = CultureInfo.CurrentCulture.Name }; var validator = new GetCategorySchemaModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var categorySchema = await this.categoryService.GetCategorySchemaAsync(serviceModel); if (categorySchema != null) { var response = new CategorySchemaResponseModel { Id = categorySchema.Id, CategoryId = categorySchema.CategoryId, Schema = categorySchema.Schema, UiSchema = categorySchema.UiSchema, LastModifiedDate = categorySchema.LastModifiedDate, CreatedDate = categorySchema.CreatedDate }; return(this.StatusCode((int)HttpStatusCode.OK, response)); } else { return(this.StatusCode((int)HttpStatusCode.NotFound)); } } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); }