-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d25d55
commit aff7256
Showing
12 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
API.Core/Spesicifications/ProductsWithProductTypeAndBrandSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using API.Core.DbModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
|
||
namespace API.Core.Spesicifications | ||
{ | ||
public class ProductsWithProductTypeAndBrandSpecification:BaseSpesification<Product> | ||
{ | ||
public ProductsWithProductTypeAndBrandSpecification() | ||
{ | ||
AddInlcude(x => x.ProductBrand); | ||
AddInlcude(x => x.ProductType); | ||
} | ||
public ProductsWithProductTypeAndBrandSpecification(int id) | ||
:base(x=>x.Id==id) | ||
{ | ||
AddInlcude(x => x.ProductBrand); | ||
AddInlcude(x => x.ProductType); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using API.Core.DbModels; | ||
using API.Core.Spesicifications; | ||
using Microsoft.EntityFrameworkCore; | ||
using System.Linq; | ||
|
||
namespace API.Infrastructure.Data | ||
{ | ||
public class SpesificationEveluator<TEntiy> | ||
where TEntiy:BaseEntity | ||
{ | ||
public static IQueryable<TEntiy> GetQuery(IQueryable<TEntiy> inputQuery,ISpesification<TEntiy> spec) | ||
{ | ||
var query = inputQuery; | ||
|
||
if (spec.Creteria !=null) | ||
{ | ||
query = query.Where(spec.Creteria); | ||
} | ||
|
||
query = spec.Includes.Aggregate(query, (current, include) => current.Include(include)); | ||
return query; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace API.Dtos | ||
{ | ||
public class ProductToReturnDto | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
public decimal? Price { get; set; } | ||
public string PictureUrl { get; set; } | ||
public string ProductType { get; set; } | ||
public string ProductBrand { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using API.Core.DbModels; | ||
using API.Dtos; | ||
using AutoMapper; | ||
|
||
namespace API.Helpers | ||
{ | ||
public class MappingProfiles : Profile | ||
{ | ||
public MappingProfiles() | ||
{ | ||
CreateMap<Product, ProductToReturnDto>() | ||
.ForMember(x => x.ProductBrand, o => o.MapFrom(s => s.ProductBrand.Name)) | ||
.ForMember(x => x.ProductType, o => o.MapFrom(s => s.ProductType.Name)) | ||
.ForMember(x=>x.PictureUrl,o=>o.MapFrom<ProductUrlResolver>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using API.Core.DbModels; | ||
using API.Dtos; | ||
using AutoMapper; | ||
using AutoMapper.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace API.Helpers | ||
{ | ||
public class ProductUrlResolver : IValueResolver<Product, ProductToReturnDto, string> | ||
{ | ||
private readonly Microsoft.Extensions.Configuration.IConfiguration _config; | ||
|
||
public ProductUrlResolver(Microsoft.Extensions.Configuration.IConfiguration config) | ||
{ | ||
_config = config; | ||
} | ||
public string Resolve(Product source, ProductToReturnDto destination, string destMember, ResolutionContext context) | ||
{ | ||
if (!string.IsNullOrEmpty(source.PictureUrl)) | ||
{ | ||
return _config["ApiUrl"] + source.PictureUrl; | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters