add auuthor

subProduct
Amir Hossein Khademi 2024-09-11 19:59:27 +03:30
parent fda7088abb
commit 8e5003028d
28 changed files with 3131 additions and 780 deletions

View File

@ -1 +1 @@
1.3.12.16
1.4.12.17

View File

@ -1,6 +1,8 @@
using Microsoft.Extensions.Options;
using Netina.Api.Services;
using Netina.Domain.Entities.Blogs;
using System.Web;
using Netina.Repository.Abstracts;
namespace Netina.Api.Controllers;
@ -77,9 +79,13 @@ public class BlogController : ICarterModule
}
// POST:Create Entity
public async Task<IResult> Post([FromBody] BlogLDto dto, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
public async Task<IResult> Post([FromBody] BlogLDto dto, IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService, CancellationToken cancellationToken)
{
var ent = Blog.Create(dto.Title, dto.Content, dto.Tags, dto.ReadingTime, dto.Summery, dto.IsSuggested,dto.CategoryId);
if (currentUserService.UserId == null)
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
var ent = Blog.Create(dto.Title, dto.Content, dto.Tags, dto.ReadingTime, dto.Summery, dto.IsSuggested,dto.CategoryId, userId);
foreach (var file in dto.Files)
{
ent.AddFile(file.Name, file.FileLocation, file.FileName, file.IsHeader, file.IsPrimary, file.FileType);
@ -91,13 +97,17 @@ public class BlogController : ICarterModule
}
// PUT:Update Entity
public async Task<IResult> Put([FromBody] BlogLDto dto, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
public async Task<IResult> Put([FromBody] BlogLDto dto, IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService, CancellationToken cancellationToken)
{
var ent = await repositoryWrapper.SetRepository<Blog>().TableNoTracking
.FirstOrDefaultAsync(b => b.Id == dto.Id, cancellationToken);
if (ent == null)
throw new AppException("Blog not found");
var newEnt = Blog.Create(dto.Title, dto.Content, dto.Tags, dto.ReadingTime, dto.Summery, dto.IsSuggested, dto.CategoryId);
if (currentUserService.UserId == null)
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
var newEnt = Blog.Create(dto.Title, dto.Content, dto.Tags, dto.ReadingTime, dto.Summery, dto.IsSuggested, dto.CategoryId, userId);
newEnt.Id = ent.Id;
newEnt.CreatedAt = ent.CreatedAt;
newEnt.CreatedBy = ent.CreatedBy;

View File

@ -126,7 +126,7 @@ public class SeedController(IWebHostEnvironment environment) : ICarterModule
seedBlogRequestDto.CategoryId = noCategory.Id;
}
var ent = Blog.Create(seedBlogRequestDto.Title, seedBlogRequestDto.Slug, seedBlogRequestDto.Content, seedBlogRequestDto.Tags, seedBlogRequestDto.ReadingTime,
seedBlogRequestDto.Summery, seedBlogRequestDto.IsSuggested, seedBlogRequestDto.CategoryId);
seedBlogRequestDto.Summery, seedBlogRequestDto.IsSuggested, seedBlogRequestDto.CategoryId,default);
foreach (var storageFileSDto in seedBlogRequestDto.Files)
{

View File

@ -6,8 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssemblyVersion>1.3.12.16</AssemblyVersion>
<FileVersion>1.3.12.16</FileVersion>
<AssemblyVersion>1.4.12.17</AssemblyVersion>
<FileVersion>1.4.12.17do</FileVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -1,16 +1,24 @@
namespace Netina.Common.Models.Entity
{
[AttributeUsage(AttributeTargets.Class)]
public class PageClassDisplay(string name, string description) : Attribute
public class PageClassDisplay : Attribute
{
private readonly string _name;
private readonly string _description;
public PageClassDisplay(string name, string description)
{
_name = name;
_description = description;
}
public string GetName()
{
return name;
return _name;
}
public string GetDescription()
{
return description;
return _description;
}
}
}

View File

@ -12,5 +12,7 @@ public class BlogLDto : BaseDto<BlogLDto , Blog>
public bool IsSuggested { get; set; }
public Guid CategoryId { get; set; }
public string CategoryName { get; set; } = string.Empty;
public Guid AuthorId { get; set; }
public string AuthorFullName { get; set; } = string.Empty;
public List<StorageFileSDto> Files { get; set; } = new();
}

View File

@ -31,4 +31,6 @@ public class ProductLDto : BaseDto<ProductLDto,Product>
public List<StorageFileSDto> Files { get; set; } = new();
public DiscountSDto? SpecialOffer { get; set; }
public Guid AuthorId { get; set; }
public string AuthorFullName { get; set; } = string.Empty;
}

View File

@ -12,4 +12,6 @@ public class BlogSDto : BaseDto<BlogSDto , Blog>
public string CategoryName { get; set; } = string.Empty;
public string MainImage { get; set; } = string.Empty;
public DateTime ModifiedAt { get; set; }
public Guid AuthorId { get; set; }
public string AuthorFullName { get; set; } = string.Empty;
}

View File

@ -30,4 +30,6 @@ public class ProductSDto : BaseDto<ProductSDto, Product>
public string BrandName { get; set; } = string.Empty;
public string CategoryName { get; set; } = string.Empty;
public DateTime ModifiedAt { get; set; }
public Guid AuthorId { get; set; }
public string AuthorFullName { get; set; } = string.Empty;
}

View File

@ -2,17 +2,17 @@
public partial class Blog
{
public static Blog Create(string title, string content, string tags, int readingTime, string summery, bool isSuggested, Guid categoryId)
public static Blog Create(string title, string content, string tags, int readingTime, string summery, bool isSuggested, Guid categoryId, Guid authorId)
{
var slug = StringExtensions.GetSlug(title);
return new Blog(title, slug, content, tags, readingTime, summery, isSuggested, categoryId);
return new Blog(title, slug, content, tags, readingTime, summery, isSuggested, categoryId,authorId);
}
public static Blog Create(string title, string slug, string content, string tags, int readingTime, string summery, bool isSuggested, Guid categoryId)
public static Blog Create(string title, string slug, string content, string tags, int readingTime, string summery, bool isSuggested, Guid categoryId, Guid authorId)
{
if (slug.IsNullOrEmpty())
slug = StringExtensions.GetSlug(title);
return new Blog(title, slug, content, tags, readingTime, summery, isSuggested, categoryId);
return new Blog(title, slug, content, tags, readingTime, summery, isSuggested, categoryId, authorId);
}
public BlogStorageFile AddFile(string name, string fileLocation, string fileName, bool isHeader, bool isPrimary, StorageFileType fileType)
{

View File

@ -11,7 +11,7 @@ public partial class Blog : ApiEntity
{
}
public Blog(string title,string slug,string content,string tags, int readingTime,string summery, bool isSuggested, Guid categoryId)
public Blog(string title,string slug,string content,string tags, int readingTime,string summery, bool isSuggested, Guid categoryId,Guid authorId)
{
Title = title;
Content = content;
@ -20,6 +20,7 @@ public partial class Blog : ApiEntity
Summery = summery;
IsSuggested = isSuggested;
CategoryId = categoryId;
AuthorId = authorId;
Slug = slug;
}
public string Title { get; internal set; } = string.Empty;
@ -32,5 +33,7 @@ public partial class Blog : ApiEntity
public Guid CategoryId { get; internal set; }
public BlogCategory? Category { get; internal set; }
public List<BlogStorageFile> Files { get; internal set; } = new();
public Guid AuthorId { get; internal set; }
public ApplicationUser? Author { get; internal set; }
}

View File

@ -5,7 +5,7 @@
[AdaptTo("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Projection)]
[GenerateMapper]
[Index(nameof(Slug), IsUnique = true)]
//[Index(nameof(Slug), IsUnique = true)]
public partial class Brand : ApiEntity
{
public Brand()

View File

@ -10,7 +10,7 @@ public partial class Product
int stock,
int maxOrderCount,
Guid brandId,
Guid categoryId)
Guid categoryId, Guid authorId)
{
var slug = StringExtensions.GetSlug(persianName);
return new Product(
@ -29,7 +29,7 @@ public partial class Product
maxOrderCount,
stock > 0,
brandId,
categoryId);
categoryId,authorId);
}
public void AddRate(float rate)

View File

@ -8,7 +8,7 @@
[GenerateMapper]
[Index(nameof(Slug), IsUnique = true)]
//[Index(nameof(Slug), IsUnique = true)]
public partial class Product : ApiEntity
{
public Product()
@ -32,7 +32,8 @@ public partial class Product : ApiEntity
int maxOrderCount,
bool isEnable,
Guid brandId,
Guid categoryId)
Guid categoryId,
Guid authorId)
{
PersianName = persianName;
EnglishName = englishName;
@ -50,6 +51,7 @@ public partial class Product : ApiEntity
IsEnable = isEnable;
BrandId = brandId;
CategoryId = categoryId;
AuthorId = authorId;
}
public string PersianName { get; internal set; } = string.Empty;
public string EnglishName { get; internal set; } = string.Empty;
@ -73,6 +75,8 @@ public partial class Product : ApiEntity
public Brand? Brand { get; internal set; }
public Guid CategoryId { get; internal set; }
public Guid AuthorId { get; internal set; }
public ApplicationUser? Author { get; internal set; }
public ProductCategory? Category { get; internal set; }
public List<Specification> Specifications { get; internal set; } = new();

View File

@ -2,9 +2,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Mapster.Models;
using Netina.Domain.Dtos.LargDtos;
using Netina.Domain.Dtos.SmallDtos;
using Netina.Domain.Entities.Blogs;
using Netina.Domain.Entities.Users;
namespace Netina.Domain.Mappers
{
@ -55,6 +57,8 @@ namespace Netina.Domain.Mappers
Name = p8.CategoryName,
Id = p8.CategoryId
},
AuthorId = p8.AuthorId,
Author = new ApplicationUser() {Id = p8.AuthorId},
Id = p8.Id,
CreatedAt = p8.CreatedAt,
ModifiedAt = p8.ModifiedAt
@ -105,6 +109,7 @@ namespace Netina.Domain.Mappers
CategoryName = p16.Category.Name,
MainImage = p16.Files.Count > 0 && p16.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p16.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
ModifiedAt = p16.ModifiedAt,
AuthorId = p16.AuthorId,
Id = p16.Id,
CreatedAt = p16.CreatedAt
}).ToList<BlogSDto>(),
@ -118,6 +123,9 @@ namespace Netina.Domain.Mappers
Name = p17.Name,
Slug = p17.Slug,
Description = p17.Description,
IsMain = p17.IsMain,
ParentId = (Guid?)p17.ParentId,
Parent = new BlogCategory() {Id = p17.ParentId},
Id = p17.Id,
CreatedAt = p17.CreatedAt
};
@ -133,48 +141,57 @@ namespace Netina.Domain.Mappers
result.Name = p18.Name;
result.Slug = p18.Slug;
result.Description = p18.Description;
result.IsMain = p18.IsMain;
result.ParentId = (Guid?)p18.ParentId;
result.Parent = funcMain7(new Never(), result.Parent, p18);
result.Id = p18.Id;
result.CreatedAt = p18.CreatedAt;
return result;
}
public static BlogCategorySDto AdaptToSDto(this BlogCategory p20)
public static BlogCategorySDto AdaptToSDto(this BlogCategory p22)
{
return p20 == null ? null : new BlogCategorySDto()
return p22 == null ? null : new BlogCategorySDto()
{
Name = p20.Name,
BlogCount = funcMain7(p20.Blogs == null ? null : (int?)p20.Blogs.Count),
Description = p20.Description,
Slug = p20.Slug,
Id = p20.Id,
CreatedAt = p20.CreatedAt
Name = p22.Name,
BlogCount = funcMain8(p22.Blogs == null ? null : (int?)p22.Blogs.Count),
Description = p22.Description,
Slug = p22.Slug,
IsMain = p22.IsMain,
ParentId = p22.ParentId == null ? default(Guid) : (Guid)p22.ParentId,
Id = p22.Id,
CreatedAt = p22.CreatedAt
};
}
public static BlogCategorySDto AdaptTo(this BlogCategory p22, BlogCategorySDto p23)
public static BlogCategorySDto AdaptTo(this BlogCategory p24, BlogCategorySDto p25)
{
if (p22 == null)
if (p24 == null)
{
return null;
}
BlogCategorySDto result = p23 ?? new BlogCategorySDto();
BlogCategorySDto result = p25 ?? new BlogCategorySDto();
result.Name = p22.Name;
result.BlogCount = funcMain8(p22.Blogs == null ? null : (int?)p22.Blogs.Count, result.BlogCount);
result.Description = p22.Description;
result.Slug = p22.Slug;
result.Id = p22.Id;
result.CreatedAt = p22.CreatedAt;
result.Name = p24.Name;
result.BlogCount = funcMain9(p24.Blogs == null ? null : (int?)p24.Blogs.Count, result.BlogCount);
result.Description = p24.Description;
result.Slug = p24.Slug;
result.IsMain = p24.IsMain;
result.ParentId = p24.ParentId == null ? default(Guid) : (Guid)p24.ParentId;
result.Id = p24.Id;
result.CreatedAt = p24.CreatedAt;
return result;
}
public static Expression<Func<BlogCategory, BlogCategorySDto>> ProjectToSDto => p26 => new BlogCategorySDto()
public static Expression<Func<BlogCategory, BlogCategorySDto>> ProjectToSDto => p28 => new BlogCategorySDto()
{
Name = p26.Name,
BlogCount = p26.Blogs.Count,
Description = p26.Description,
Slug = p26.Slug,
Id = p26.Id,
CreatedAt = p26.CreatedAt
Name = p28.Name,
BlogCount = p28.Blogs.Count,
Description = p28.Description,
Slug = p28.Slug,
IsMain = p28.IsMain,
ParentId = p28.ParentId == null ? default(Guid) : (Guid)p28.ParentId,
Id = p28.Id,
CreatedAt = p28.CreatedAt
};
private static List<Blog> funcMain1(List<BlogSDto> p2)
@ -205,6 +222,8 @@ namespace Netina.Domain.Mappers
Name = item.CategoryName,
Id = item.CategoryId
},
AuthorId = item.AuthorId,
Author = new ApplicationUser() {Id = item.AuthorId},
Id = item.Id,
CreatedAt = item.CreatedAt,
ModifiedAt = item.ModifiedAt
@ -243,6 +262,8 @@ namespace Netina.Domain.Mappers
Name = item.CategoryName,
Id = item.CategoryId
},
AuthorId = item.AuthorId,
Author = new ApplicationUser() {Id = item.AuthorId},
Id = item.Id,
CreatedAt = item.CreatedAt,
ModifiedAt = item.ModifiedAt
@ -279,6 +300,7 @@ namespace Netina.Domain.Mappers
CategoryName = item.Category == null ? null : item.Category.Name,
MainImage = item.Files.Count > 0 && item.Files.Any<BlogStorageFile>(funcMain4) ? item.Files.FirstOrDefault<BlogStorageFile>(funcMain5).FileName : string.Empty,
ModifiedAt = item.ModifiedAt,
AuthorId = item.AuthorId,
Id = item.Id,
CreatedAt = item.CreatedAt
});
@ -314,6 +336,7 @@ namespace Netina.Domain.Mappers
CategoryName = item.Category == null ? null : item.Category.Name,
MainImage = item.Files.Count > 0 && item.Files.Any<BlogStorageFile>(funcMain4) ? item.Files.FirstOrDefault<BlogStorageFile>(funcMain5).FileName : string.Empty,
ModifiedAt = item.ModifiedAt,
AuthorId = item.AuthorId,
Id = item.Id,
CreatedAt = item.CreatedAt
});
@ -323,14 +346,23 @@ namespace Netina.Domain.Mappers
}
private static int funcMain7(int? p21)
private static BlogCategory funcMain7(Never p20, BlogCategory p21, BlogCategorySDto p18)
{
return p21 == null ? 0 : (int)p21;
BlogCategory result = p21 ?? new BlogCategory();
result.Id = p18.ParentId;
return result;
}
private static int funcMain8(int? p24, int p25)
private static int funcMain8(int? p23)
{
return p24 == null ? 0 : (int)p24;
return p23 == null ? 0 : (int)p23;
}
private static int funcMain9(int? p26, int p27)
{
return p26 == null ? 0 : (int)p26;
}
private static bool funcMain4(BlogStorageFile f)

View File

@ -6,6 +6,7 @@ using Mapster.Models;
using Netina.Domain.Dtos.LargDtos;
using Netina.Domain.Dtos.SmallDtos;
using Netina.Domain.Entities.Blogs;
using Netina.Domain.Entities.Users;
namespace Netina.Domain.Mappers
{
@ -29,6 +30,8 @@ namespace Netina.Domain.Mappers
Id = p1.CategoryId
},
Files = funcMain1(p1.Files),
AuthorId = p1.AuthorId,
Author = new ApplicationUser() {Id = p1.AuthorId},
Id = p1.Id,
CreatedAt = p1.CreatedAt
};
@ -51,206 +54,223 @@ namespace Netina.Domain.Mappers
result.CategoryId = p3.CategoryId;
result.Category = funcMain2(new Never(), result.Category, p3);
result.Files = funcMain3(p3.Files, result.Files);
result.AuthorId = p3.AuthorId;
result.Author = funcMain4(new Never(), result.Author, p3);
result.Id = p3.Id;
result.CreatedAt = p3.CreatedAt;
return result;
}
public static Expression<Func<BlogLDto, Blog>> ProjectToBlog => p9 => new Blog()
{
Title = p9.Title,
Content = p9.Content,
Slug = p9.Slug,
Tags = p9.Tags,
ReadingTime = p9.ReadingTime,
Summery = p9.Summery,
IsSuggested = p9.IsSuggested,
CategoryId = p9.CategoryId,
Category = new BlogCategory()
{
Name = p9.CategoryName,
Id = p9.CategoryId
},
Files = p9.Files.Select<StorageFileSDto, BlogStorageFile>(p10 => new BlogStorageFile()
{
Name = p10.Name,
FileLocation = p10.FileLocation,
FileName = p10.FileName,
IsHeader = p10.IsHeader,
IsPrimary = p10.IsPrimary,
FileType = p10.FileType,
Id = p10.Id,
CreatedAt = p10.CreatedAt
}).ToList<BlogStorageFile>(),
Id = p9.Id,
CreatedAt = p9.CreatedAt
};
public static BlogLDto AdaptToLDto(this Blog p11)
{
return p11 == null ? null : new BlogLDto()
public static Expression<Func<BlogLDto, Blog>> ProjectToBlog => p11 => new Blog()
{
Title = p11.Title,
Content = p11.Content,
Tags = p11.Tags,
Slug = p11.Slug,
Tags = p11.Tags,
ReadingTime = p11.ReadingTime,
Summery = p11.Summery,
MainImage = p11.Files.Count > 0 && p11.Files.Any<BlogStorageFile>(funcMain4) ? p11.Files.FirstOrDefault<BlogStorageFile>(funcMain5).FileName : string.Empty,
IsSuggested = p11.IsSuggested,
CategoryId = p11.CategoryId,
CategoryName = p11.Category == null ? null : p11.Category.Name,
Files = funcMain6(p11.Files),
Category = new BlogCategory()
{
Name = p11.CategoryName,
Id = p11.CategoryId
},
Files = p11.Files.Select<StorageFileSDto, BlogStorageFile>(p12 => new BlogStorageFile()
{
Name = p12.Name,
FileLocation = p12.FileLocation,
FileName = p12.FileName,
IsHeader = p12.IsHeader,
IsPrimary = p12.IsPrimary,
FileType = p12.FileType,
Id = p12.Id,
CreatedAt = p12.CreatedAt
}).ToList<BlogStorageFile>(),
AuthorId = p11.AuthorId,
Author = new ApplicationUser() {Id = p11.AuthorId},
Id = p11.Id,
CreatedAt = p11.CreatedAt
};
}
public static BlogLDto AdaptTo(this Blog p13, BlogLDto p14)
public static BlogLDto AdaptToLDto(this Blog p13)
{
if (p13 == null)
return p13 == null ? null : new BlogLDto()
{
Title = p13.Title,
Content = p13.Content,
Tags = p13.Tags,
Slug = p13.Slug,
ReadingTime = p13.ReadingTime,
Summery = p13.Summery,
MainImage = p13.Files.Count > 0 && p13.Files.Any<BlogStorageFile>(funcMain5) ? p13.Files.FirstOrDefault<BlogStorageFile>(funcMain6).FileName : string.Empty,
IsSuggested = p13.IsSuggested,
CategoryId = p13.CategoryId,
CategoryName = p13.Category == null ? null : p13.Category.Name,
AuthorId = p13.AuthorId,
AuthorFullName = p13.Author != null ? p13.Author.FirstName + " " + p13.Author.LastName : string.Empty,
Files = funcMain7(p13.Files),
Id = p13.Id,
CreatedAt = p13.CreatedAt
};
}
public static BlogLDto AdaptTo(this Blog p15, BlogLDto p16)
{
if (p15 == null)
{
return null;
}
BlogLDto result = p14 ?? new BlogLDto();
BlogLDto result = p16 ?? new BlogLDto();
result.Title = p13.Title;
result.Content = p13.Content;
result.Tags = p13.Tags;
result.Slug = p13.Slug;
result.ReadingTime = p13.ReadingTime;
result.Summery = p13.Summery;
result.MainImage = p13.Files.Count > 0 && p13.Files.Any<BlogStorageFile>(funcMain4) ? p13.Files.FirstOrDefault<BlogStorageFile>(funcMain5).FileName : string.Empty;
result.IsSuggested = p13.IsSuggested;
result.CategoryId = p13.CategoryId;
result.CategoryName = p13.Category == null ? null : p13.Category.Name;
result.Files = funcMain7(p13.Files, result.Files);
result.Id = p13.Id;
result.CreatedAt = p13.CreatedAt;
result.Title = p15.Title;
result.Content = p15.Content;
result.Tags = p15.Tags;
result.Slug = p15.Slug;
result.ReadingTime = p15.ReadingTime;
result.Summery = p15.Summery;
result.MainImage = p15.Files.Count > 0 && p15.Files.Any<BlogStorageFile>(funcMain5) ? p15.Files.FirstOrDefault<BlogStorageFile>(funcMain6).FileName : string.Empty;
result.IsSuggested = p15.IsSuggested;
result.CategoryId = p15.CategoryId;
result.CategoryName = p15.Category == null ? null : p15.Category.Name;
result.AuthorId = p15.AuthorId;
result.AuthorFullName = p15.Author != null ? p15.Author.FirstName + " " + p15.Author.LastName : string.Empty;
result.Files = funcMain8(p15.Files, result.Files);
result.Id = p15.Id;
result.CreatedAt = p15.CreatedAt;
return result;
}
public static Expression<Func<Blog, BlogLDto>> ProjectToLDto => p17 => new BlogLDto()
{
Title = p17.Title,
Content = p17.Content,
Tags = p17.Tags,
Slug = p17.Slug,
ReadingTime = p17.ReadingTime,
Summery = p17.Summery,
MainImage = p17.Files.Count > 0 && p17.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p17.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
IsSuggested = p17.IsSuggested,
CategoryId = p17.CategoryId,
CategoryName = p17.Category.Name,
Files = p17.Files.Select<BlogStorageFile, StorageFileSDto>(p18 => new StorageFileSDto()
{
Name = p18.Name,
FileLocation = p18.FileLocation,
FileName = p18.FileName,
IsHeader = p18.IsHeader,
IsPrimary = p18.IsPrimary,
FileType = p18.FileType,
Id = p18.Id
}).ToList<StorageFileSDto>(),
Id = p17.Id,
CreatedAt = p17.CreatedAt
};
public static Blog AdaptToBlog(this BlogSDto p19)
{
return p19 == null ? null : new Blog()
public static Expression<Func<Blog, BlogLDto>> ProjectToLDto => p19 => new BlogLDto()
{
Title = p19.Title,
Slug = p19.Slug,
Content = p19.Content,
Tags = p19.Tags,
Slug = p19.Slug,
ReadingTime = p19.ReadingTime,
Summery = p19.Summery,
MainImage = p19.Files.Count > 0 && p19.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p19.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
IsSuggested = p19.IsSuggested,
CategoryId = p19.CategoryId,
CategoryName = p19.Category.Name,
AuthorId = p19.AuthorId,
AuthorFullName = p19.Author != null ? p19.Author.FirstName + " " + p19.Author.LastName : string.Empty,
Files = p19.Files.Select<BlogStorageFile, StorageFileSDto>(p20 => new StorageFileSDto()
{
Name = p20.Name,
FileLocation = p20.FileLocation,
FileName = p20.FileName,
IsHeader = p20.IsHeader,
IsPrimary = p20.IsPrimary,
FileType = p20.FileType,
Id = p20.Id
}).ToList<StorageFileSDto>(),
Id = p19.Id,
CreatedAt = p19.CreatedAt
};
public static Blog AdaptToBlog(this BlogSDto p21)
{
return p21 == null ? null : new Blog()
{
Title = p21.Title,
Slug = p21.Slug,
Tags = p21.Tags,
ReadingTime = p21.ReadingTime,
Summery = p21.Summery,
IsSuggested = p21.IsSuggested,
CategoryId = p21.CategoryId,
Category = new BlogCategory()
{
Name = p19.CategoryName,
Id = p19.CategoryId
Name = p21.CategoryName,
Id = p21.CategoryId
},
Id = p19.Id,
CreatedAt = p19.CreatedAt,
ModifiedAt = p19.ModifiedAt
AuthorId = p21.AuthorId,
Author = new ApplicationUser() {Id = p21.AuthorId},
Id = p21.Id,
CreatedAt = p21.CreatedAt,
ModifiedAt = p21.ModifiedAt
};
}
public static Blog AdaptTo(this BlogSDto p20, Blog p21)
public static Blog AdaptTo(this BlogSDto p22, Blog p23)
{
if (p20 == null)
if (p22 == null)
{
return null;
}
Blog result = p21 ?? new Blog();
Blog result = p23 ?? new Blog();
result.Title = p20.Title;
result.Slug = p20.Slug;
result.Tags = p20.Tags;
result.ReadingTime = p20.ReadingTime;
result.Summery = p20.Summery;
result.IsSuggested = p20.IsSuggested;
result.CategoryId = p20.CategoryId;
result.Category = funcMain8(new Never(), result.Category, p20);
result.Id = p20.Id;
result.CreatedAt = p20.CreatedAt;
result.ModifiedAt = p20.ModifiedAt;
result.Title = p22.Title;
result.Slug = p22.Slug;
result.Tags = p22.Tags;
result.ReadingTime = p22.ReadingTime;
result.Summery = p22.Summery;
result.IsSuggested = p22.IsSuggested;
result.CategoryId = p22.CategoryId;
result.Category = funcMain9(new Never(), result.Category, p22);
result.AuthorId = p22.AuthorId;
result.Author = funcMain10(new Never(), result.Author, p22);
result.Id = p22.Id;
result.CreatedAt = p22.CreatedAt;
result.ModifiedAt = p22.ModifiedAt;
return result;
}
public static BlogSDto AdaptToSDto(this Blog p24)
public static BlogSDto AdaptToSDto(this Blog p28)
{
return p24 == null ? null : new BlogSDto()
return p28 == null ? null : new BlogSDto()
{
Title = p24.Title,
Slug = p24.Slug,
Tags = p24.Tags,
ReadingTime = p24.ReadingTime,
Summery = p24.Summery,
IsSuggested = p24.IsSuggested,
CategoryId = p24.CategoryId,
CategoryName = p24.Category == null ? null : p24.Category.Name,
MainImage = p24.Files.Count > 0 && p24.Files.Any<BlogStorageFile>(funcMain9) ? p24.Files.FirstOrDefault<BlogStorageFile>(funcMain10).FileName : string.Empty,
ModifiedAt = p24.ModifiedAt,
Id = p24.Id,
CreatedAt = p24.CreatedAt
Title = p28.Title,
Slug = p28.Slug,
Tags = p28.Tags,
ReadingTime = p28.ReadingTime,
Summery = p28.Summery,
IsSuggested = p28.IsSuggested,
CategoryId = p28.CategoryId,
CategoryName = p28.Category == null ? null : p28.Category.Name,
MainImage = p28.Files.Count > 0 && p28.Files.Any<BlogStorageFile>(funcMain11) ? p28.Files.FirstOrDefault<BlogStorageFile>(funcMain12).FileName : string.Empty,
ModifiedAt = p28.ModifiedAt,
AuthorId = p28.AuthorId,
Id = p28.Id,
CreatedAt = p28.CreatedAt
};
}
public static BlogSDto AdaptTo(this Blog p25, BlogSDto p26)
public static BlogSDto AdaptTo(this Blog p29, BlogSDto p30)
{
if (p25 == null)
if (p29 == null)
{
return null;
}
BlogSDto result = p26 ?? new BlogSDto();
BlogSDto result = p30 ?? new BlogSDto();
result.Title = p25.Title;
result.Slug = p25.Slug;
result.Tags = p25.Tags;
result.ReadingTime = p25.ReadingTime;
result.Summery = p25.Summery;
result.IsSuggested = p25.IsSuggested;
result.CategoryId = p25.CategoryId;
result.CategoryName = p25.Category == null ? null : p25.Category.Name;
result.MainImage = p25.Files.Count > 0 && p25.Files.Any<BlogStorageFile>(funcMain9) ? p25.Files.FirstOrDefault<BlogStorageFile>(funcMain10).FileName : string.Empty;
result.ModifiedAt = p25.ModifiedAt;
result.Id = p25.Id;
result.CreatedAt = p25.CreatedAt;
result.Title = p29.Title;
result.Slug = p29.Slug;
result.Tags = p29.Tags;
result.ReadingTime = p29.ReadingTime;
result.Summery = p29.Summery;
result.IsSuggested = p29.IsSuggested;
result.CategoryId = p29.CategoryId;
result.CategoryName = p29.Category == null ? null : p29.Category.Name;
result.MainImage = p29.Files.Count > 0 && p29.Files.Any<BlogStorageFile>(funcMain11) ? p29.Files.FirstOrDefault<BlogStorageFile>(funcMain12).FileName : string.Empty;
result.ModifiedAt = p29.ModifiedAt;
result.AuthorId = p29.AuthorId;
result.Id = p29.Id;
result.CreatedAt = p29.CreatedAt;
return result;
}
public static Expression<Func<Blog, BlogSDto>> ProjectToSDto => p27 => new BlogSDto()
public static Expression<Func<Blog, BlogSDto>> ProjectToSDto => p31 => new BlogSDto()
{
Title = p27.Title,
Slug = p27.Slug,
Tags = p27.Tags,
ReadingTime = p27.ReadingTime,
Summery = p27.Summery,
IsSuggested = p27.IsSuggested,
CategoryId = p27.CategoryId,
CategoryName = p27.Category.Name,
MainImage = p27.Files.Count > 0 && p27.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p27.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
ModifiedAt = p27.ModifiedAt,
Id = p27.Id,
CreatedAt = p27.CreatedAt
Title = p31.Title,
Slug = p31.Slug,
Tags = p31.Tags,
ReadingTime = p31.ReadingTime,
Summery = p31.Summery,
IsSuggested = p31.IsSuggested,
CategoryId = p31.CategoryId,
CategoryName = p31.Category.Name,
MainImage = p31.Files.Count > 0 && p31.Files.Any<BlogStorageFile>(f => f.IsPrimary) ? p31.Files.FirstOrDefault<BlogStorageFile>(f => f.IsPrimary).FileName : string.Empty,
ModifiedAt = p31.ModifiedAt,
AuthorId = p31.AuthorId,
Id = p31.Id,
CreatedAt = p31.CreatedAt
};
private static List<BlogStorageFile> funcMain1(List<StorageFileSDto> p2)
@ -325,9 +345,13 @@ namespace Netina.Domain.Mappers
}
private static bool funcMain4(BlogStorageFile f)
private static ApplicationUser funcMain4(Never p9, ApplicationUser p10, BlogLDto p3)
{
return f.IsPrimary;
ApplicationUser result = p10 ?? new ApplicationUser();
result.Id = p3.AuthorId;
return result;
}
private static bool funcMain5(BlogStorageFile f)
@ -335,82 +359,96 @@ namespace Netina.Domain.Mappers
return f.IsPrimary;
}
private static List<StorageFileSDto> funcMain6(List<BlogStorageFile> p12)
{
if (p12 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p12.Count);
int i = 0;
int len = p12.Count;
while (i < len)
{
BlogStorageFile item = p12[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static List<StorageFileSDto> funcMain7(List<BlogStorageFile> p15, List<StorageFileSDto> p16)
{
if (p15 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p15.Count);
int i = 0;
int len = p15.Count;
while (i < len)
{
BlogStorageFile item = p15[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static BlogCategory funcMain8(Never p22, BlogCategory p23, BlogSDto p20)
{
BlogCategory result = p23 ?? new BlogCategory();
result.Name = p20.CategoryName;
result.Id = p20.CategoryId;
return result;
}
private static bool funcMain9(BlogStorageFile f)
private static bool funcMain6(BlogStorageFile f)
{
return f.IsPrimary;
}
private static bool funcMain10(BlogStorageFile f)
private static List<StorageFileSDto> funcMain7(List<BlogStorageFile> p14)
{
if (p14 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p14.Count);
int i = 0;
int len = p14.Count;
while (i < len)
{
BlogStorageFile item = p14[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static List<StorageFileSDto> funcMain8(List<BlogStorageFile> p17, List<StorageFileSDto> p18)
{
if (p17 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p17.Count);
int i = 0;
int len = p17.Count;
while (i < len)
{
BlogStorageFile item = p17[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static BlogCategory funcMain9(Never p24, BlogCategory p25, BlogSDto p22)
{
BlogCategory result = p25 ?? new BlogCategory();
result.Name = p22.CategoryName;
result.Id = p22.CategoryId;
return result;
}
private static ApplicationUser funcMain10(Never p26, ApplicationUser p27, BlogSDto p22)
{
ApplicationUser result = p27 ?? new ApplicationUser();
result.Id = p22.AuthorId;
return result;
}
private static bool funcMain11(BlogStorageFile f)
{
return f.IsPrimary;
}
private static bool funcMain12(BlogStorageFile f)
{
return f.IsPrimary;
}

View File

@ -16,6 +16,7 @@ namespace Netina.Domain.Mappers
{
PersianName = p1.PersianName,
EnglishName = p1.EnglishName,
Slug = p1.Slug,
Description = p1.Description,
HasSpecialPage = p1.HasSpecialPage,
PageUrl = p1.PageUrl,
@ -34,6 +35,7 @@ namespace Netina.Domain.Mappers
result.PersianName = p3.PersianName;
result.EnglishName = p3.EnglishName;
result.Slug = p3.Slug;
result.Description = p3.Description;
result.HasSpecialPage = p3.HasSpecialPage;
result.PageUrl = p3.PageUrl;
@ -47,6 +49,7 @@ namespace Netina.Domain.Mappers
{
PersianName = p7.PersianName,
EnglishName = p7.EnglishName,
Slug = p7.Slug,
Description = p7.Description,
HasSpecialPage = p7.HasSpecialPage,
PageUrl = p7.PageUrl,
@ -72,6 +75,7 @@ namespace Netina.Domain.Mappers
EnglishName = p9.EnglishName,
Description = p9.Description,
HasSpecialPage = p9.HasSpecialPage,
Slug = p9.Slug,
PageUrl = p9.PageUrl,
Files = funcMain3(p9.Files),
Id = p9.Id,
@ -90,6 +94,7 @@ namespace Netina.Domain.Mappers
result.EnglishName = p11.EnglishName;
result.Description = p11.Description;
result.HasSpecialPage = p11.HasSpecialPage;
result.Slug = p11.Slug;
result.PageUrl = p11.PageUrl;
result.Files = funcMain4(p11.Files, result.Files);
result.Id = p11.Id;
@ -103,6 +108,7 @@ namespace Netina.Domain.Mappers
EnglishName = p15.EnglishName,
Description = p15.Description,
HasSpecialPage = p15.HasSpecialPage,
Slug = p15.Slug,
PageUrl = p15.PageUrl,
Files = p15.Files.Select<BrandStorageFile, StorageFileSDto>(p16 => new StorageFileSDto()
{
@ -123,6 +129,7 @@ namespace Netina.Domain.Mappers
{
PersianName = p17.PersianName,
EnglishName = p17.EnglishName,
Slug = p17.Slug,
Description = p17.Description,
HasSpecialPage = p17.HasSpecialPage,
PageUrl = p17.PageUrl,
@ -140,6 +147,7 @@ namespace Netina.Domain.Mappers
result.PersianName = p18.PersianName;
result.EnglishName = p18.EnglishName;
result.Slug = p18.Slug;
result.Description = p18.Description;
result.HasSpecialPage = p18.HasSpecialPage;
result.PageUrl = p18.PageUrl;
@ -155,6 +163,7 @@ namespace Netina.Domain.Mappers
PersianName = p20.PersianName,
EnglishName = p20.EnglishName,
Description = p20.Description,
Slug = p20.Slug,
HasSpecialPage = p20.HasSpecialPage,
PageUrl = p20.PageUrl,
Id = p20.Id,
@ -172,6 +181,7 @@ namespace Netina.Domain.Mappers
result.PersianName = p21.PersianName;
result.EnglishName = p21.EnglishName;
result.Description = p21.Description;
result.Slug = p21.Slug;
result.HasSpecialPage = p21.HasSpecialPage;
result.PageUrl = p21.PageUrl;
result.Id = p21.Id;
@ -184,6 +194,7 @@ namespace Netina.Domain.Mappers
PersianName = p23.PersianName,
EnglishName = p23.EnglishName,
Description = p23.Description,
Slug = p23.Slug,
HasSpecialPage = p23.HasSpecialPage,
PageUrl = p23.PageUrl,
Id = p23.Id,

View File

@ -16,6 +16,7 @@ namespace Netina.Domain.Mappers
return p1 == null ? null : new ProductCategory()
{
Name = p1.Name,
Slug = p1.Slug,
Description = p1.Description,
IsMain = p1.IsMain,
ParentId = (Guid?)p1.ParentId,
@ -38,6 +39,7 @@ namespace Netina.Domain.Mappers
ProductCategory result = p4 ?? new ProductCategory();
result.Name = p3.Name;
result.Slug = p3.Slug;
result.Description = p3.Description;
result.IsMain = p3.IsMain;
result.ParentId = (Guid?)p3.ParentId;
@ -51,6 +53,7 @@ namespace Netina.Domain.Mappers
public static Expression<Func<ProductCategoryLDto, ProductCategory>> ProjectToProductCategory => p9 => new ProductCategory()
{
Name = p9.Name,
Slug = p9.Slug,
Description = p9.Description,
IsMain = p9.IsMain,
ParentId = (Guid?)p9.ParentId,
@ -81,6 +84,7 @@ namespace Netina.Domain.Mappers
Description = p11.Description,
ParentId = p11.ParentId == null ? default(Guid) : (Guid)p11.ParentId,
ParentName = p11.Parent != null ? p11.Parent.Name : string.Empty,
Slug = p11.Slug,
IsMain = p11.IsMain,
Files = funcMain4(p11.Files),
Id = p11.Id,
@ -99,6 +103,7 @@ namespace Netina.Domain.Mappers
result.Description = p13.Description;
result.ParentId = p13.ParentId == null ? default(Guid) : (Guid)p13.ParentId;
result.ParentName = p13.Parent != null ? p13.Parent.Name : string.Empty;
result.Slug = p13.Slug;
result.IsMain = p13.IsMain;
result.Files = funcMain5(p13.Files, result.Files);
result.Id = p13.Id;
@ -112,6 +117,7 @@ namespace Netina.Domain.Mappers
Description = p17.Description,
ParentId = p17.ParentId == null ? default(Guid) : (Guid)p17.ParentId,
ParentName = p17.Parent != null ? p17.Parent.Name : string.Empty,
Slug = p17.Slug,
IsMain = p17.IsMain,
Files = p17.Files.Select<ProductCategoryStorageFile, StorageFileSDto>(p18 => new StorageFileSDto()
{

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,7 @@ using System;
using System.Linq.Expressions;
using Netina.Domain.Dtos.LargDtos;
using Netina.Domain.Dtos.SmallDtos;
using Netina.Domain.Entities.Products;
using Review = Netina.Domain.Entities.Reviews.Review;
using Netina.Domain.Entities.Reviews;
namespace Netina.Domain.Mappers
{

View File

@ -12,6 +12,7 @@ public class MapsterRegister : IRegister
.TwoWays();
config.NewConfig<Blog, BlogLDto>()
.Map(o=>o.AuthorFullName , d=>d.Author!=null ? d.Author.FirstName + " " + d.Author.LastName : string.Empty)
.Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f => f.IsPrimary) ? o.Files.FirstOrDefault(f => f.IsPrimary)!.FileName : string.Empty)
.TwoWays();
@ -37,6 +38,7 @@ public class MapsterRegister : IRegister
.TwoWays();
config.NewConfig<Product, ProductSDto>()
.Map(o => o.AuthorFullName, d => d.Author != null ? d.Author.FirstName + " " + d.Author.LastName : string.Empty)
.Map("MainImage", o => o.Files.FirstOrDefault(f => f.IsPrimary) != null ? o.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : o.Files.Count > 0 ? o.Files.FirstOrDefault().FileLocation : string.Empty)
.Map("CategoryName", o => o.Category == null ? null : o.Category.Name)
.Map("BrandName", o => o.Brand == null ? null : o.Brand.PersianName)
@ -53,14 +55,12 @@ public class MapsterRegister : IRegister
config.NewConfig<Product, ProductLDto>()
.Map(o => o.AuthorFullName, d => d.Author != null ? d.Author.FirstName + " " + d.Author.LastName : string.Empty)
.Map("CategoryName", o => o.Category == null ? null : o.Category.Name)
.Map("BrandName", o => o.Brand == null ? null : o.Brand.PersianName)
.IgnoreNullValues(false)
.TwoWays();
config.NewConfig<Product, ProductSDto>()
.Map("MainImage", o => o.Files.FirstOrDefault(f => f.IsPrimary) != null ? o.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : o.Files.Count > 0 ? o.Files.FirstOrDefault().FileLocation : string.Empty)
.IgnoreNullValues(false)
.TwoWays();
config.NewConfig<Product, TorobProductResponseDto>()
.Map(s=>s.availibility,o=>o.IsEnable)
.Map(s=>s.price , o=>o.Cost)

View File

@ -15,7 +15,8 @@ public class ChangeProductCostCommandHandler(IRepositoryWrapper repositoryWrappe
ent.Warranty,
ent.BeDisplayed, request.Cost, ent.PackingCost, ent.HasExpressDelivery, ent.Stock, ent.MaxOrderCount,
ent.BrandId,
ent.CategoryId);
ent.CategoryId,
ent.AuthorId);
newEnt.CreatedAt = ent.CreatedAt;
newEnt.CreatedBy = ent.CreatedBy;
newEnt.Id = ent.Id;

View File

@ -14,7 +14,8 @@ public class ChangeProductDisplayedCommandHandler(IRepositoryWrapper repositoryW
ent.Warranty,
request.BeDisplayed, ent.Cost, ent.PackingCost, ent.HasExpressDelivery, ent.Stock, ent.MaxOrderCount,
ent.BrandId,
ent.CategoryId);
ent.CategoryId,
ent.AuthorId);
newEnt.CreatedAt = ent.CreatedAt;
newEnt.CreatedBy = ent.CreatedBy;
newEnt.Id = ent.Id;

View File

@ -1,17 +1,22 @@
namespace Netina.Repository.Handlers.Products;
public class CreateProductCommandHandler(IRepositoryWrapper repositoryWrapper,IMartenRepositoryWrapper martenRepositoryWrapper, IMediator mediator)
public class CreateProductCommandHandler(IRepositoryWrapper repositoryWrapper,IMartenRepositoryWrapper martenRepositoryWrapper, IMediator mediator,ICurrentUserService currentUserService)
: IRequestHandler<CreateProductCommand, ProductLDto>
{
public async Task<ProductLDto> Handle(CreateProductCommand request, CancellationToken cancellationToken)
{
if (currentUserService.UserId == null)
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
var ent = Product.Create(request.PersianName, request.EnglishName, request.Summery, request.ExpertCheck,
request.Tags, request.Warranty,request.BeDisplayed,request.Cost,request.PackingCost,
request.HasExpressDelivery,
request.Stock,
request.MaxOrderCount,
request.BrandId,request.CategoryId);
request.BrandId,request.CategoryId, userId);
foreach (var specification in request.Specifications)
{

View File

@ -1,6 +1,6 @@
namespace Netina.Repository.Handlers.Products;
public class UpdateProductCommandHandler(IRepositoryWrapper repositoryWrapper,IMartenRepositoryWrapper martenRepositoryWrapper, IMediator mediator)
public class UpdateProductCommandHandler(IRepositoryWrapper repositoryWrapper,IMartenRepositoryWrapper martenRepositoryWrapper, IMediator mediator,ICurrentUserService currentUserService)
: IRequestHandler<UpdateProductCommand, bool>
{
public async Task<bool> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
@ -9,7 +9,10 @@ public class UpdateProductCommandHandler(IRepositoryWrapper repositoryWrapper,IM
.FirstOrDefaultAsync(e => e.Id == request.Id, cancellationToken);
if (ent == null)
throw new AppException("Product not found", ApiResultStatusCode.NotFound);
if (currentUserService.UserId == null)
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
if(!Guid.TryParse(currentUserService.UserId,out Guid userId))
throw new BaseApiException(ApiResultStatusCode.UnAuthorized, "User id is wrong");
var newEnt = Product.Create(request.PersianName, request.EnglishName, request.Summery, request.ExpertCheck,
request.Tags,
request.Warranty,
@ -20,7 +23,8 @@ public class UpdateProductCommandHandler(IRepositoryWrapper repositoryWrapper,IM
request.Stock,
request.MaxOrderCount,
request.BrandId,
request.CategoryId);
request.CategoryId,
userId);
newEnt.Id = ent.Id;
newEnt.CreatedAt = ent.CreatedAt;
newEnt.CreatedBy = ent.CreatedBy;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,97 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NetinaShop.Repository.Migrations
{
/// <inheritdoc />
public partial class AddAuthor : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "AuthorId",
schema: "public",
table: "Products",
type: "uuid",
nullable: false,
defaultValue: new Guid("8723f1d2-e091-4812-9110-5161c9e23586"));
migrationBuilder.AddColumn<Guid>(
name: "AuthorId",
schema: "public",
table: "Blogs",
type: "uuid",
nullable: false,
defaultValue: new Guid("8723f1d2-e091-4812-9110-5161c9e23586"));
migrationBuilder.CreateIndex(
name: "IX_Products_AuthorId",
schema: "public",
table: "Products",
column: "AuthorId");
migrationBuilder.CreateIndex(
name: "IX_Blogs_AuthorId",
schema: "public",
table: "Blogs",
column: "AuthorId");
migrationBuilder.AddForeignKey(
name: "FK_Blogs_Users_AuthorId",
schema: "public",
table: "Blogs",
column: "AuthorId",
principalSchema: "public",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Products_Users_AuthorId",
schema: "public",
table: "Products",
column: "AuthorId",
principalSchema: "public",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Blogs_Users_AuthorId",
schema: "public",
table: "Blogs");
migrationBuilder.DropForeignKey(
name: "FK_Products_Users_AuthorId",
schema: "public",
table: "Products");
migrationBuilder.DropIndex(
name: "IX_Products_AuthorId",
schema: "public",
table: "Products");
migrationBuilder.DropIndex(
name: "IX_Blogs_AuthorId",
schema: "public",
table: "Blogs");
migrationBuilder.DropColumn(
name: "AuthorId",
schema: "public",
table: "Products");
migrationBuilder.DropColumn(
name: "AuthorId",
schema: "public",
table: "Blogs");
}
}
}

View File

@ -18,7 +18,7 @@ namespace NetinaShop.Repository.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("public")
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "fuzzystrmatch");
@ -208,6 +208,9 @@ namespace NetinaShop.Repository.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AuthorId")
.HasColumnType("uuid");
b.Property<Guid>("CategoryId")
.HasColumnType("uuid");
@ -263,6 +266,8 @@ namespace NetinaShop.Repository.Migrations
b.HasKey("Id");
b.HasIndex("AuthorId");
b.HasIndex("CategoryId");
b.ToTable("Blogs", "public");
@ -491,7 +496,7 @@ namespace NetinaShop.Repository.Migrations
b.ToTable("Discounts", "public");
b.HasDiscriminator<string>("Discriminator").HasValue("Discount");
b.HasDiscriminator().HasValue("Discount");
b.UseTphMappingStrategy();
});
@ -791,6 +796,9 @@ namespace NetinaShop.Repository.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AuthorId")
.HasColumnType("uuid");
b.Property<bool>("BeDisplayed")
.HasColumnType("boolean");
@ -881,6 +889,8 @@ namespace NetinaShop.Repository.Migrations
b.HasKey("Id");
b.HasIndex("AuthorId");
b.HasIndex("BrandId");
b.HasIndex("CategoryId");
@ -888,68 +898,6 @@ namespace NetinaShop.Repository.Migrations
b.ToTable("Products", "public");
});
modelBuilder.Entity("Netina.Domain.Entities.Products.Review", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Comment")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsBuyer")
.HasColumnType("boolean");
b.Property<bool>("IsConfirmed")
.HasColumnType("boolean");
b.Property<bool>("IsRemoved")
.HasColumnType("boolean");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("ModifiedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<float>("Rate")
.HasColumnType("real");
b.Property<DateTime>("RemovedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("RemovedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Reviews", "public");
});
modelBuilder.Entity("Netina.Domain.Entities.Products.Specification", b =>
{
b.Property<Guid>("Id")
@ -1010,6 +958,68 @@ namespace NetinaShop.Repository.Migrations
b.ToTable("Specifications", "public");
});
modelBuilder.Entity("Netina.Domain.Entities.Reviews.Review", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Comment")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsBuyer")
.HasColumnType("boolean");
b.Property<bool>("IsConfirmed")
.HasColumnType("boolean");
b.Property<bool>("IsRemoved")
.HasColumnType("boolean");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("ModifiedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<float>("Rate")
.HasColumnType("real");
b.Property<DateTime>("RemovedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("RemovedBy")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Reviews", "public");
});
modelBuilder.Entity("Netina.Domain.Entities.StorageFiles.StorageFile", b =>
{
b.Property<Guid>("Id")
@ -1070,7 +1080,7 @@ namespace NetinaShop.Repository.Migrations
b.ToTable("StorageFiles", "public");
b.HasDiscriminator<string>("Discriminator").HasValue("StorageFile");
b.HasDiscriminator().HasValue("StorageFile");
b.UseTphMappingStrategy();
});
@ -1697,11 +1707,18 @@ namespace NetinaShop.Repository.Migrations
modelBuilder.Entity("Netina.Domain.Entities.Blogs.Blog", b =>
{
b.HasOne("Netina.Domain.Entities.Users.ApplicationUser", "Author")
.WithMany()
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Netina.Domain.Entities.Blogs.BlogCategory", "Category")
.WithMany("Blogs")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Author");
b.Navigation("Category");
});
@ -1789,6 +1806,11 @@ namespace NetinaShop.Repository.Migrations
modelBuilder.Entity("Netina.Domain.Entities.Products.Product", b =>
{
b.HasOne("Netina.Domain.Entities.Users.ApplicationUser", "Author")
.WithMany()
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Netina.Domain.Entities.Brands.Brand", "Brand")
.WithMany("Products")
.HasForeignKey("BrandId")
@ -1799,28 +1821,13 @@ namespace NetinaShop.Repository.Migrations
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Author");
b.Navigation("Brand");
b.Navigation("Category");
});
modelBuilder.Entity("Netina.Domain.Entities.Products.Review", b =>
{
b.HasOne("Netina.Domain.Entities.Products.Product", "Product")
.WithMany("Reviews")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Netina.Domain.Entities.Users.ApplicationUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Product");
b.Navigation("User");
});
modelBuilder.Entity("Netina.Domain.Entities.Products.Specification", b =>
{
b.HasOne("Netina.Domain.Entities.Products.Specification", "Parent")
@ -1837,6 +1844,23 @@ namespace NetinaShop.Repository.Migrations
b.Navigation("Product");
});
modelBuilder.Entity("Netina.Domain.Entities.Reviews.Review", b =>
{
b.HasOne("Netina.Domain.Entities.Products.Product", "Product")
.WithMany("Reviews")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Netina.Domain.Entities.Users.ApplicationUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Product");
b.Navigation("User");
});
modelBuilder.Entity("Netina.Domain.Entities.Users.Customer", b =>
{
b.HasOne("Netina.Domain.Entities.Users.ApplicationUser", "User")