-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
12 changed files
with
1,577 additions
and
0 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
29 changes: 29 additions & 0 deletions
29
source/OptimaJet.DWKit.StarterApplication/Controllers/ProductUserChangeController.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,29 @@ | ||
| ||
using System.Threading.Tasks; | ||
using JsonApiDotNetCore.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using OptimaJet.DWKit.StarterApplication.Models; | ||
using OptimaJet.DWKit.StarterApplication.Services; | ||
|
||
namespace OptimaJet.DWKit.StarterApplication.Controllers | ||
{ | ||
public class ProductUserChangeController : BaseController<ProductUserChange> | ||
{ | ||
public ProductUserChangeController( | ||
IJsonApiContext jsonApiContext, | ||
IResourceService<ProductUserChange> resourceService, | ||
ICurrentUserContext currentUserContext, | ||
OrganizationService organizationService, | ||
UserService userService) | ||
: base(jsonApiContext, resourceService, currentUserContext, organizationService, userService) | ||
|
||
{ | ||
} | ||
|
||
public override Task<IActionResult> PostAsync([FromBody] ProductUserChange entity) | ||
{ | ||
|
||
return base.PostAsync(entity); | ||
} | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
source/OptimaJet.DWKit.StarterApplication/Forms/ProductUserChangeForm.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,40 @@ | ||
using System; | ||
using System.Linq; | ||
using JsonApiDotNetCore.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
using OptimaJet.DWKit.StarterApplication.Models; | ||
using OptimaJet.DWKit.StarterApplication.Repositories; | ||
using OptimaJet.DWKit.StarterApplication.Services; | ||
namespace OptimaJet.DWKit.StarterApplication.Forms | ||
{ | ||
public class ProductUserChangeForm : BaseForm | ||
{ | ||
public IEntityRepository<Product, Guid> ProductRepository { get; } | ||
public ProductUserChangeForm( | ||
UserRepository userRepository, | ||
IEntityRepository<UserRole> userRolesRepository, | ||
ICurrentUserContext currentUserContext, | ||
IEntityRepository<Product, Guid> productRepository) | ||
: base(userRepository, userRolesRepository, currentUserContext) | ||
{ | ||
ProductRepository = productRepository; | ||
} | ||
|
||
public bool IsValid(ProductUserChange productUserChange) | ||
{ | ||
if (productUserChange.ProductId != null) | ||
{ | ||
var product = ProductRepository.Get() | ||
.Where(p => p.Id.Equals(productUserChange.ProductId)) | ||
.FirstOrDefaultAsync().Result; | ||
if (product == null) | ||
{ | ||
var message = $"Product {productUserChange.ProductId} not found"; | ||
AddError(message); | ||
} | ||
} | ||
|
||
return base.IsValid(); | ||
} | ||
} | ||
} |
Oops, something went wrong.