Skip to content

Commit

Permalink
Netcore2preview2 (#216)
Browse files Browse the repository at this point in the history
* upgraded to netcore2preview2

* changed in ef core preview2

* ef core changed dotnet/efcore#8584

* correct user/role model
remove Microsoft.VisualStudio.Web.CodeGeneration.Design from WebHost because of warnings

* corret the type of select expression Expression<Func<TModel, TResult>>

* remove redundant Includes

* Remove PackageTargetFallback(deprecated)

* update readme, dockerfile
  • Loading branch information
auroravirtuoso committed Jul 6, 2017
1 parent 1be04cf commit 9a8a98e
Show file tree
Hide file tree
Showing 32 changed files with 72 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG source=.
WORKDIR /app
COPY $source .

RUN sed -i 's#<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0-preview1-final" />#<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-preview1" />#' src/SimplCommerce.WebHost/SimplCommerce.WebHost.csproj
RUN sed -i 's#<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0-preview2-final" />#<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-preview2" />#' src/SimplCommerce.WebHost/SimplCommerce.WebHost.csproj

RUN sed -i 's/UseSqlServer/UseNpgsql/' src/SimplCommerce.WebHost/Startup.cs
RUN sed -i 's/UseSqlServer/UseNpgsql/' src/SimplCommerce.WebHost/Extensions/ServiceCollectionExtensions.cs
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ http://demo.simplcommerce.com
#### Prerequisites

- SQL Server
- [Visual Studio 2017 version 15.3 Preview with .NET Core Tools 2.0 Preview 1](https://www.microsoft.com/net/core/preview)
- [Visual Studio 2017 version 15.3 preview3 with .NET Core SDK 2.0 preview2](https://www.microsoft.com/net/core/preview)

#### Steps to run

Expand All @@ -40,7 +40,7 @@ http://demo.simplcommerce.com

- PostgreSQL
- NodeJS
- [.NET Core SDK 2.0 Preview 1](https://www.microsoft.com/net/core/preview)
- [.NET Core SDK 2.0 Preview 2](https://www.microsoft.com/net/core/preview)

#### Steps to run

Expand All @@ -52,9 +52,9 @@ http://demo.simplcommerce.com
- Open browser, open http://localhost:5000. The back-office can access via /Admin using the pre-created account: admin@simplcommerce.com, 1qazZAQ!

## Technologies and frameworks used:
- ASP.NET MVC Core 2.0.0 Preview 1 on .NET Core 2.0.0 Preview 1
- Entity Framework Core 2.0.0 Preview 1
- ASP.NET Identity Core 2.0.0 Preview 1
- ASP.NET MVC Core 2.0.0 Preview 2 on .NET Core 2.0.0 Preview 2
- Entity Framework Core 2.0.0 Preview 2
- ASP.NET Identity Core 2.0.0 Preview 2
- Autofac 4.1.0
- Angular 1.6.3
- MediatR for domain event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void SaveCategoryImage(Category category, CategoryForm model)

private string SaveFile(IFormFile file)
{
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Value.Trim('"');
var fileName = $"{Guid.NewGuid()}{Path.GetExtension(originalFileName)}";
_mediaService.SaveMedia(file.OpenReadStream(), fileName, file.ContentType);
return fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ private void SaveProductMedias(ProductForm model, Product product)

private string SaveFile(IFormFile file)
{
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Value.Trim('"');
var fileName = $"{Guid.NewGuid()}{Path.GetExtension(originalFileName)}";
_mediaService.SaveMedia(file.OpenReadStream(), fileName, file.ContentType);
return fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public IActionResult List()
{
var attributes = _productAttrRepository
.Query()
.Include(x => x.Group)
.Select(x => new
{
Id = x.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private CarouselWidgetForm ToCarouselWidgetFormModel(IFormCollection formCollect

private string SaveFile(IFormFile file)
{
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Value.Trim('"');
var fileName = $"{Guid.NewGuid()}{Path.GetExtension(originalFileName)}";
_mediaService.SaveMedia(file.OpenReadStream(), fileName, file.ContentType);
return fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public ContactApiController(IRepository<Contact> contactRepository, IMediaServic
public IActionResult Get([FromBody] SmartTableParam param)
{
var query = _contactRepository.Query()
.Include(x => x.ContactArea)
.Where(x => !x.IsDeleted);

if (param.Search.PredicateObject != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CommonApiController(IMediaService mediaService)
[HttpPost("upload")]
public IActionResult UploadFile(IFormFile file)
{
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Value.Trim('"');
var fileName = $"{Guid.NewGuid()}{Path.GetExtension(originalFileName)}";
mediaService.SaveMedia(file.OpenReadStream(), fileName, file.ContentType);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SimplCommerce.Infrastructure.Data;
using SimplCommerce.Module.Core.Models;

Expand All @@ -20,7 +19,7 @@ public EntityApiController(IRepository<Entity> entityRepository)

public IActionResult Get(long? entityTypeId, string name)
{
var query = _entityRepository.Query().Include(x => x.EntityType).Where(x => x.EntityType.IsMenuable);
var query = _entityRepository.Query().Where(x => x.EntityType.IsMenuable);
if (entityTypeId.HasValue)
{
query = query.Where(x => x.EntityTypeId == entityTypeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public UserApiController(IRepository<User> userRepository, UserManager<User> use
public IActionResult List([FromBody] SmartTableParam param)
{
var query = _userRepository.Query()
.Include(x => x.Roles).ThenInclude(r => r.Role)
.Where(x => !x.IsDeleted);

if (param.Search.PredicateObject != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public WidgetInstanceApiController(IRepository<WidgetInstance> widgetInstanceRep
public IActionResult Get()
{
var widgetInstances = _widgetInstanceRepository.Query()
.Include(x => x.Widget)
.Include(x => x.WidgetZone)
.Select(x => new
{
Id = x.Id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using SimplCommerce.Infrastructure.Data;
using SimplCommerce.Module.Core.Models;

Expand Down Expand Up @@ -31,8 +30,8 @@ public void Build(ModelBuilder modelBuilder)
modelBuilder.Entity<UserRole>(b =>
{
b.HasKey(ur => new { ur.UserId, ur.RoleId });
b.HasOne(ur => ur.Role).WithMany(r => r.Users).HasForeignKey(r => r.RoleId);
b.HasOne(ur => ur.User).WithMany(u => u.Roles).HasForeignKey(u => u.UserId);
b.HasOne(ur => ur.Role).WithMany(x => x.Users).HasForeignKey(r => r.RoleId);
b.HasOne(ur => ur.User).WithMany(x => x.Roles).HasForeignKey(u => u.UserId);
b.ToTable("Core_UserRole");
});

Expand All @@ -55,17 +54,14 @@ public void Build(ModelBuilder modelBuilder)
modelBuilder.Entity<User>(u =>
{
u.HasOne(x => x.DefaultShippingAddress)
.WithMany()
.HasForeignKey(x => x.DefaultShippingAddressId)
.OnDelete(DeleteBehavior.Restrict);
});
.WithMany()
.HasForeignKey(x => x.DefaultShippingAddressId)
.OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity<User>(u =>
{
u.HasOne(x => x.DefaultBillingAddress)
.WithMany()
.HasForeignKey(x => x.DefaultBillingAddressId)
.OnDelete(DeleteBehavior.Restrict);
.WithMany()
.HasForeignKey(x => x.DefaultBillingAddressId)
.OnDelete(DeleteBehavior.Restrict);
});

modelBuilder.Entity<UserAddress>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using SimplCommerce.Infrastructure;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using SimplCommerce.Module.Core.Data;
using SimplCommerce.Module.Core.Models;
Expand All @@ -10,10 +10,5 @@ public class SimplRoleStore: RoleStore<Role, SimplDbContext, long, UserRole, Ide
public SimplRoleStore(SimplDbContext context) : base(context)
{
}

protected override IdentityRoleClaim<long> CreateRoleClaim(Role role, Claim claim)
{
return new IdentityRoleClaim<long> { RoleId = role.Id, ClaimType = claim.Type, ClaimValue = claim.Value };
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public SimplSignInManager(UserManager<TUser> userManager,
_mediator = mediator;
}

public override async Task SignInAsync(TUser user, bool isPersistent, string authenticationMethod = null)
public override async Task SignInAsync(TUser user, bool isPersistent, string authenticationMethod = null, bool updateLastSignIn = true)
{
var userId = await UserManager.GetUserIdAsync(user);
await _mediator.Publish(new UserSignedIn {UserId = long.Parse(userId)});
await base.SignInAsync(user, isPersistent, authenticationMethod);
await base.SignInAsync(user, isPersistent, authenticationMethod, updateLastSignIn);
}
}
}
43 changes: 2 additions & 41 deletions src/Modules/SimplCommerce.Module.Core/Extensions/SimplUserStore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using SimplCommerce.Module.Core.Data;
using SimplCommerce.Module.Core.Models;
Expand All @@ -9,46 +8,8 @@ namespace SimplCommerce.Module.Core.Extensions
public class SimplUserStore : UserStore<User, Role, SimplDbContext, long, IdentityUserClaim<long>, UserRole,
IdentityUserLogin<long>,IdentityUserToken<long>, IdentityRoleClaim<long>>
{
public SimplUserStore(SimplDbContext context) : base(context)
public SimplUserStore(SimplDbContext context, IdentityErrorDescriber describer) : base(context, describer)
{
}

protected override UserRole CreateUserRole(User user, Role role)
{
return new UserRole()
{
UserId = user.Id,
RoleId = role.Id
};
}

protected override IdentityUserClaim<long> CreateUserClaim(User user, Claim claim)
{
var userClaim = new IdentityUserClaim<long> { UserId = user.Id };
userClaim.InitializeFromClaim(claim);
return userClaim;
}

protected override IdentityUserLogin<long> CreateUserLogin(User user, UserLoginInfo login)
{
return new IdentityUserLogin<long>
{
UserId = user.Id,
ProviderKey = login.ProviderKey,
LoginProvider = login.LoginProvider,
ProviderDisplayName = login.ProviderDisplayName
};
}

protected override IdentityUserToken<long> CreateUserToken(User user, string loginProvider, string name, string value)
{
return new IdentityUserToken<long>
{
UserId = user.Id,
LoginProvider = loginProvider,
Name = name,
Value = value
};
}
}
}
4 changes: 3 additions & 1 deletion src/Modules/SimplCommerce.Module.Core/Models/Role.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using SimplCommerce.Infrastructure.Models;
using System.Collections.Generic;

namespace SimplCommerce.Module.Core.Models
{
public class Role : IdentityRole<long, UserRole, IdentityRoleClaim<long>>, IEntityWithTypedId<long>
{
public IList<UserRole> Users { get; set; } = new List<UserRole>();
}
}
4 changes: 3 additions & 1 deletion src/Modules/SimplCommerce.Module.Core/Models/User.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using SimplCommerce.Infrastructure.Models;

namespace SimplCommerce.Module.Core.Models
Expand Down Expand Up @@ -34,5 +34,7 @@ public User()
public UserAddress DefaultBillingAddress { get; set; }

public long? DefaultBillingAddressId { get; set; }

public IList<UserRole> Roles { get; set; } = new List<UserRole>();
}
}
2 changes: 1 addition & 1 deletion src/Modules/SimplCommerce.Module.Core/Models/UserRole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;

namespace SimplCommerce.Module.Core.Models
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using SimplCommerce.Infrastructure.Data;
using SimplCommerce.Module.Core.Models;

Expand All @@ -17,7 +16,7 @@ public WidgetInstanceService(IRepository<WidgetInstance> widgetInstanceRepositor

public IQueryable<WidgetInstance> GetPublished()
{
return _widgetInstanceRepository.Query().Include(x => x.Widget).Where(x =>
return _widgetInstanceRepository.Query().Where(x =>
x.PublishStart.HasValue && x.PublishStart.Value < DateTimeOffset.Now
&& (!x.PublishEnd.HasValue || x.PublishEnd.Value > DateTimeOffset.Now));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0-preview2-final" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public IStringLocalizer Create(string baseName, string location)

private void LoadResources()
{
_resourceStrings = _resourceRepository.Query().Include(x => x.Culture).Select(x => new ResourceString
_resourceStrings = _resourceRepository.Query().Select(x => new ResourceString
{
Culture = x.Culture.Name,
Key = x.Key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public async Task<IActionResult> Delete(long id)

private string SaveFile(IFormFile file)
{
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Value.Trim('"');
var fileName = $"{Guid.NewGuid()}{Path.GetExtension(originalFileName)}";
_mediaService.SaveMedia(file.OpenReadStream(), fileName, file.ContentType);
return fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public async Task<ActionResult> Get(int status, int numRecords)

var query = _orderRepository
.Query()
.Include(x => x.CreatedBy)
.Where(x => x.OrderStatus == orderStatus);

var currentUser = await _workContext.GetCurrentUser();
Expand All @@ -65,8 +64,7 @@ public async Task<ActionResult> Get(int status, int numRecords)
public async Task<ActionResult> List([FromBody] SmartTableParam param)
{
IQueryable<Order> query = _orderRepository
.Query()
.Include(x => x.CreatedBy);
.Query();

var currentUser = await _workContext.GetCurrentUser();
if (!User.IsInRole("admin"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<ItemGroup>
<PackageReference Include="MediatR" Version="3.0.1" />
<PackageReference Include="cloudscribe.Web.Pagination" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0-preview1-final" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0-preview2-final" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.0-preview2-25405-01" />
<PackageReference Include="System.Globalization.Extensions" Version="4.3.0" />
<PackageReference Include="System.Linq.Queryable" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0-preview2-25405-01" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Linq;
using System.Linq.Expressions;

namespace SimplCommerce.Infrastructure.Web.SmartTable
{
public static class SmartTableExtension
{
public static SmartTableResult<TResult> ToSmartTableResult<TModel, TResult>(this IQueryable<TModel> query, SmartTableParam param, Func<TModel, TResult> selector)
public static SmartTableResult<TResult> ToSmartTableResult<TModel, TResult>(this IQueryable<TModel> query, SmartTableParam param, Expression<Func<TModel, TResult>> selector)
{
if (param.Pagination.Number <= 0)
{
Expand Down
Loading

0 comments on commit 9a8a98e

Please sign in to comment.