Skip to content

Commit

Permalink
Add ProductUserChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvire committed Nov 27, 2023
1 parent 56abf09 commit 17675a1
Show file tree
Hide file tree
Showing 12 changed files with 1,578 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services
});
});


services.AddHttpContextAccessor();

// Add service / repository overrides
Expand All @@ -66,6 +67,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services
services.AddScoped<IEntityRepository<Product,Guid>, ProductRepository>();
services.AddScoped<IEntityRepository<OrganizationStore>, OrganizationStoreRepository>();
services.AddScoped<IEntityRepository<ProjectImport>, ProjectImportRepository>();
services.AddScoped<IEntityRepository<ProductUserChange>, ProductUserChangeRepository>();

// for operations
services.AddScoped<IUpdateService<Project>, ProjectService>();
Expand All @@ -86,6 +88,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services
services.AddScoped<IResourceService<Project>, ProjectService>();
services.AddScoped<IResourceService<ProjectImport>, ProjectImportService>();
services.AddScoped<IResourceService<Product, Guid>, ProductService>();
services.AddScoped<IResourceService<ProductUserChange>, ProductUserChangeService>();
services.AddScoped<IResourceService<GroupMembership>, GroupMembershipService>();
services.AddScoped<IResourceService<OrganizationMembership>, OrganizationMembershipService>();
services.AddScoped<IResourceService<OrganizationMembershipInvite>, OrganizationMembershipInviteService>();
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
var workflowSchemeEntity = modelBuilder.Entity<WorkflowScheme>();
var projectImportEntity = modelBuilder.Entity<ProjectImport>();
var productPublicationEntity = modelBuilder.Entity<ProductPublication>();
var productUserChangeEntity = modelBuilder.Entity<ProductUserChange>();

userEntity
.HasMany(u => u.OrganizationMemberships)
Expand Down Expand Up @@ -243,6 +244,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
productPublicationEntity
.HasIndex(p => p.Package);

productUserChangeEntity
.HasOne(p => p.Product)
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.SetNull);


productWorkflowSchemeEntity.ToTable("WorkflowProcessScheme");

Expand Down Expand Up @@ -308,6 +315,7 @@ public override int SaveChanges()
public DbSet<ProductTransition> ProductTransitions { get; set; }
public DbSet<ProductBuild> ProductBuilds { get; set; }
public DbSet<ProductPublication> ProductPublications { get; set; }
public DbSet<ProductUserChange> ProductUserChanges { get; set; }
public DbSet<ProjectImport> ProjectImports { get; set; }
public DbSet<Author> Authors { get; set; }
}
Expand Down
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();
}
}
}
Loading

0 comments on commit 17675a1

Please sign in to comment.