From 05a83ddda810cc65d59d96e57d563e56a0cb3101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=ABl=20Mugnier?= Date: Fri, 27 Nov 2020 14:55:50 +0100 Subject: [PATCH] =?UTF-8?q?Update=20-=20Mise=20=C3=A0=20jour=20de=20l'app?= =?UTF-8?q?=20de=20manage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/AgreementCommandsHandler.cs | 6 +- .../Commands/DeclarationCommandsHandler.cs | 2 +- .../Commands/DeliveryModeCommandsHandler.cs | 9 +- .../Commands/PaymentCommandsHandler.cs | 1 - .../Commands/ProductCommandsHandler.cs | 163 +++++----- .../Commands/QuickOrderCommandsHandler.cs | 7 +- .../Commands/ReturnableCommandsHandler.cs | 12 +- .../Commands/RewardCommandsHandler.cs | 8 +- .../Commands/TagCommandsHandler.cs | 52 ++-- .../Controllers/AgreementsController.cs | 33 +- .../Controllers/BankAccountsController.cs | 118 +++++++ .../Controllers/BusinessController.cs | 55 ++++ .../Controllers/ConsumersController.cs | 131 +------- .../Controllers/DashboardController.cs | 6 +- .../Controllers/DeclarationsController.cs | 38 +-- .../Controllers/DeliveryModesController.cs | 93 +----- .../Controllers/DepartmentsController.cs | 12 +- .../Controllers/DocumentsController.cs | 53 ++-- .../Controllers/DonationsController.cs | 30 +- .../Controllers/JobsController.cs | 112 ++----- .../Controllers/LegalsController.cs | 292 ++++++++++++++++++ .../Controllers/LevelsController.cs | 40 +-- .../Controllers/ManageController.cs | 10 + .../Controllers/OrdersController.cs | 71 ++--- .../Controllers/PayinsController.cs | 58 +--- .../Controllers/PayoutsController.cs | 68 +--- .../Controllers/ProducersController.cs | 226 +------------- .../Controllers/ProductsController.cs | 40 +-- .../Controllers/PurchaseOrdersController.cs | 51 +-- .../Controllers/RegionsController.cs | 9 +- .../Controllers/ReturnablesController.cs | 53 +--- .../Controllers/RewardsController.cs | 48 +-- .../Controllers/StoresController.cs | 142 +-------- .../Controllers/TagsController.cs | 50 +-- .../Controllers/TransfersController.cs | 9 +- .../Controllers/UsersController.cs | 2 +- Sheaft.Web.Manage/Startup.cs | 8 +- .../Views/Agreements/Index.cshtml | 40 --- .../Create.cshtml} | 0 .../Update.cshtml} | 0 Sheaft.Web.Manage/Views/Consumers/Edit.cshtml | 24 +- .../Views/Consumers/Index.cshtml | 114 +++---- .../Views/Dashboard/Index.cshtml | 62 ++-- .../Views/Declarations/AddUbo.cshtml | 2 +- .../{Details.cshtml => Edit.cshtml} | 2 +- .../Views/Declarations/EditUbo.cshtml | 2 +- .../Views/Declarations/Index.cshtml | 2 +- .../Views/DeliveryModes/Add.cshtml | 72 ----- .../Views/DeliveryModes/Index.cshtml | 38 --- .../Views/Departments/Index.cshtml | 98 +++--- .../Views/Documents/Create.cshtml | 16 +- Sheaft.Web.Manage/Views/Documents/Edit.cshtml | 2 +- .../Donations/{Details.cshtml => Edit.cshtml} | 2 +- .../Views/Donations/Index.cshtml | 143 ++++----- Sheaft.Web.Manage/Views/Jobs/Index.cshtml | 38 --- .../CreateLegalBusiness.cshtml} | 8 +- .../CreateLegalConsumer.cshtml} | 14 +- .../EditLegalBusiness.cshtml} | 10 +- .../EditLegalConsumer.cshtml} | 14 +- Sheaft.Web.Manage/Views/Levels/Index.cshtml | 109 +++---- .../Orders/{Details.cshtml => Edit.cshtml} | 4 +- Sheaft.Web.Manage/Views/Orders/Index.cshtml | 15 +- .../Payins/{Details.cshtml => Edit.cshtml} | 2 +- Sheaft.Web.Manage/Views/Payins/Index.cshtml | 137 ++++---- Sheaft.Web.Manage/Views/Payins/Todo.cshtml | 77 ----- .../Payouts/{Details.cshtml => Edit.cshtml} | 4 +- Sheaft.Web.Manage/Views/Payouts/Index.cshtml | 143 ++++----- Sheaft.Web.Manage/Views/Payouts/Todo.cshtml | 76 ----- Sheaft.Web.Manage/Views/Producers/Edit.cshtml | 8 +- .../Views/Producers/Index.cshtml | 38 --- Sheaft.Web.Manage/Views/Products/Index.cshtml | 38 --- .../{Details.cshtml => Edit.cshtml} | 2 +- .../Views/PurchaseOrders/Index.cshtml | 40 +-- Sheaft.Web.Manage/Views/Regions/Index.cshtml | 96 +++--- .../Views/Returnables/Index.cshtml | 38 --- Sheaft.Web.Manage/Views/Rewards/Index.cshtml | 105 +++---- Sheaft.Web.Manage/Views/Stores/Edit.cshtml | 16 +- Sheaft.Web.Manage/Views/Stores/Index.cshtml | 38 --- Sheaft.Web.Manage/Views/Tags/Index.cshtml | 124 +++----- .../Transfers/{Details.cshtml => Edit.cshtml} | 2 +- .../Views/Transfers/Index.cshtml | 145 ++++----- 81 files changed, 1439 insertions(+), 2639 deletions(-) create mode 100644 Sheaft.Web.Manage/Controllers/BankAccountsController.cs create mode 100644 Sheaft.Web.Manage/Controllers/BusinessController.cs create mode 100644 Sheaft.Web.Manage/Controllers/LegalsController.cs rename Sheaft.Web.Manage/Views/{Producers/CreateBankAccount.cshtml => BankAccounts/Create.cshtml} (100%) rename Sheaft.Web.Manage/Views/{Producers/UpdateBankAccount.cshtml => BankAccounts/Update.cshtml} (100%) rename Sheaft.Web.Manage/Views/Declarations/{Details.cshtml => Edit.cshtml} (95%) delete mode 100644 Sheaft.Web.Manage/Views/DeliveryModes/Add.cshtml rename Sheaft.Web.Manage/Views/Donations/{Details.cshtml => Edit.cshtml} (94%) rename Sheaft.Web.Manage/Views/{Producers/CreateLegal.cshtml => Legals/CreateLegalBusiness.cshtml} (93%) rename Sheaft.Web.Manage/Views/{Consumers/CreateLegal.cshtml => Legals/CreateLegalConsumer.cshtml} (86%) rename Sheaft.Web.Manage/Views/{Producers/UpdateLegal.cshtml => Legals/EditLegalBusiness.cshtml} (94%) rename Sheaft.Web.Manage/Views/{Consumers/UpdateLegal.cshtml => Legals/EditLegalConsumer.cshtml} (88%) rename Sheaft.Web.Manage/Views/Orders/{Details.cshtml => Edit.cshtml} (94%) rename Sheaft.Web.Manage/Views/Payins/{Details.cshtml => Edit.cshtml} (93%) delete mode 100644 Sheaft.Web.Manage/Views/Payins/Todo.cshtml rename Sheaft.Web.Manage/Views/Payouts/{Details.cshtml => Edit.cshtml} (94%) delete mode 100644 Sheaft.Web.Manage/Views/Payouts/Todo.cshtml rename Sheaft.Web.Manage/Views/PurchaseOrders/{Details.cshtml => Edit.cshtml} (96%) rename Sheaft.Web.Manage/Views/Transfers/{Details.cshtml => Edit.cshtml} (94%) diff --git a/Sheaft.Application.Handlers/Commands/AgreementCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/AgreementCommandsHandler.cs index 9d94cbc54..c515389fb 100644 --- a/Sheaft.Application.Handlers/Commands/AgreementCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/AgreementCommandsHandler.cs @@ -143,8 +143,8 @@ public async Task> Handle(RefuseAgreementCommand request, Cancellat return await ExecuteAsync(request, async () => { var entity = await _context.GetByIdAsync(request.Id, token); - entity.RefuseAgreement(request.Reason); + entity.RefuseAgreement(request.Reason); await _context.SaveChangesAsync(token); _mediatr.Post(new AgreementRefusedEvent(request.RequestUser) { AgreementId = entity.Id }); @@ -169,9 +169,9 @@ public async Task> Handle(ResetAgreementStatusToCommand request, Ca { return await ExecuteAsync(request, async () => { - var entity = await _context.Agreements.SingleOrDefaultAsync(a => a.Id == request.Id && a.RemovedOn.HasValue, token); - entity.Reset(); + var entity = await _context.Agreements.SingleOrDefaultAsync(a => a.Id == request.Id, token); + entity.Reset(); await _context.SaveChangesAsync(token); return Ok(true); diff --git a/Sheaft.Application.Handlers/Commands/DeclarationCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/DeclarationCommandsHandler.cs index fa12ac9c7..e25ce46cf 100644 --- a/Sheaft.Application.Handlers/Commands/DeclarationCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/DeclarationCommandsHandler.cs @@ -118,7 +118,7 @@ public async Task> Handle(RefreshDeclarationStatusComm legal.Declaration.SetResult(pspResult.Data.ResultCode, pspResult.Data.ResultMessage); legal.Declaration.SetProcessedOn(pspResult.Data.ProcessedOn); - var success = await _context.SaveChangesAsync(token) > 0; + await _context.SaveChangesAsync(token); switch (legal.Declaration.Status) { diff --git a/Sheaft.Application.Handlers/Commands/DeliveryModeCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/DeliveryModeCommandsHandler.cs index 5112ac9e0..e6db6dac6 100644 --- a/Sheaft.Application.Handlers/Commands/DeliveryModeCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/DeliveryModeCommandsHandler.cs @@ -95,7 +95,7 @@ public async Task> Handle(UpdateDeliveryModeCommand request, Cancel producer.CanDirectSell = true; else { - producer.CanDirectSell = await _context.DeliveryModes.AnyAsync(c => c.Producer.Id == request.RequestUser.Id && (c.Kind == DeliveryKind.Collective || c.Kind == DeliveryKind.Farm || c.Kind == DeliveryKind.Market), token); + producer.CanDirectSell = await _context.DeliveryModes.AnyAsync(c => !c.RemovedOn.HasValue && c.Producer.Id == request.RequestUser.Id && (c.Kind == DeliveryKind.Collective || c.Kind == DeliveryKind.Farm || c.Kind == DeliveryKind.Market), token); } await _context.SaveChangesAsync(token); @@ -113,10 +113,9 @@ public async Task> Handle(DeleteDeliveryModeCommand request, Cancel return BadRequest(MessageKind.DeliveryMode_CannotRemove_With_Active_Agreements, entity.Name, activeAgreements); _context.Remove(entity); - entity.Producer.CanDirectSell = await _context.DeliveryModes.AnyAsync(c => c.Producer.Id == request.RequestUser.Id && (c.Kind == DeliveryKind.Collective || c.Kind == DeliveryKind.Farm || c.Kind == DeliveryKind.Market), token); + entity.Producer.CanDirectSell = await _context.DeliveryModes.AnyAsync(c => !c.RemovedOn.HasValue && c.Producer.Id == request.RequestUser.Id && (c.Kind == DeliveryKind.Collective || c.Kind == DeliveryKind.Farm || c.Kind == DeliveryKind.Market), token); await _context.SaveChangesAsync(token); - return Ok(true); }); } @@ -126,9 +125,11 @@ public async Task> Handle(RestoreDeliveryModeCommand request, Cance return await ExecuteAsync(request, async () => { var entity = await _context.DeliveryModes.SingleOrDefaultAsync(a => a.Id == request.Id && a.RemovedOn.HasValue, token); + _context.Restore(entity); - await _context.SaveChangesAsync(token); + entity.Producer.CanDirectSell = await _context.DeliveryModes.AnyAsync(c => !c.RemovedOn.HasValue && c.Producer.Id == request.RequestUser.Id && (c.Kind == DeliveryKind.Collective || c.Kind == DeliveryKind.Farm || c.Kind == DeliveryKind.Market), token); + await _context.SaveChangesAsync(token); return Ok(true); }); } diff --git a/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs index c8b103e76..fe5c37db8 100644 --- a/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs @@ -71,7 +71,6 @@ public async Task> Handle(UpdateBankAccountCommand request, Cancell request.Address.Country) : null; - if (!string.IsNullOrWhiteSpace(bankAccount.Identifier)) { var resetResult = await _pspService.UpdateBankIbanAsync(bankAccount, false, token); diff --git a/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs index a97c2d32e..b1a02da5b 100644 --- a/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs @@ -49,51 +49,57 @@ public async Task> Handle(CreateProductCommand request, Cancellatio { return await ExecuteAsync(request, async () => { - if (!string.IsNullOrWhiteSpace(request.Reference)) - { - var existingEntity = await _context.FindSingleAsync(p => p.Reference == request.Reference && p.Producer.Id == request.RequestUser.Id, token); - if (existingEntity != null) - return ValidationError(MessageKind.CreateProduct_Reference_AlreadyExists, request.Reference); - } - else + using (var transaction = await _context.BeginTransactionAsync(token)) { - var resultIdentifier = await _mediatr.Process(new CreateProductIdentifierCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }, token); - if (!resultIdentifier.Success) - return Failed(resultIdentifier.Exception); + var reference = request.Reference; + if (!string.IsNullOrWhiteSpace(reference)) + { + var existingEntity = await _context.FindSingleAsync(p => p.Reference == reference && p.Producer.Id == request.RequestUser.Id, token); + if (existingEntity != null) + return ValidationError(MessageKind.CreateProduct_Reference_AlreadyExists, reference); + } + else + { + var resultIdentifier = await _mediatr.Process(new CreateProductIdentifierCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }, token); + if (!resultIdentifier.Success) + return Failed(resultIdentifier.Exception); - request.Reference = resultIdentifier.Data; - } + reference = resultIdentifier.Data; + } - var producer = await _context.GetByIdAsync(request.RequestUser.Id, token); - var entity = new Product(Guid.NewGuid(), request.Reference, request.Name, request.WholeSalePricePerUnit, request.Conditioning, request.Unit, request.QuantityPerUnit, producer); + var producer = await _context.GetByIdAsync(request.RequestUser.Id, token); + var entity = new Product(Guid.NewGuid(), reference, request.Name, request.WholeSalePricePerUnit, request.Conditioning, request.Unit, request.QuantityPerUnit, producer); - entity.SetVat(request.Vat); - entity.SetDescription(request.Description); - entity.SetAvailable(request.Available ?? true); - entity.SetStoreVisibility(request.VisibleToStores ?? false); - entity.SetConsumerVisibility(request.VisibleToConsumers ?? false); - entity.SetWeight(request.Weight); + entity.SetVat(request.Vat); + entity.SetDescription(request.Description); + entity.SetAvailable(request.Available ?? true); + entity.SetStoreVisibility(request.VisibleToStores ?? false); + entity.SetConsumerVisibility(request.VisibleToConsumers ?? false); + entity.SetWeight(request.Weight); - if (request.ReturnableId.HasValue) - { - var returnable = await _context.GetByIdAsync(request.ReturnableId.Value, token); - entity.SetReturnable(returnable); - } + if (request.ReturnableId.HasValue) + { + var returnable = await _context.GetByIdAsync(request.ReturnableId.Value, token); + entity.SetReturnable(returnable); + } - var tags = await _context.FindAsync(t => request.Tags.Contains(t.Id), token); - entity.SetTags(tags); + var tags = await _context.FindAsync(t => request.Tags.Contains(t.Id), token); + entity.SetTags(tags); - await _context.AddAsync(entity, token); - await _context.SaveChangesAsync(token); + await _context.AddAsync(entity, token); + await _context.SaveChangesAsync(token); - if (!request.SkipUpdateProducerTags) - _mediatr.Post(new UpdateProducerTagsCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }); + var imageResult = await _mediatr.Process(new UpdateProductPictureCommand(request.RequestUser) { ProductId = entity.Id, Picture = request.Picture }, token); + if (!imageResult.Success) + return Failed(imageResult.Exception); - var imageResult = await _mediatr.Process(new UpdateProductPictureCommand(request.RequestUser) { ProductId = entity.Id, Picture = request.Picture }, token); - if (!imageResult.Success) - return Failed(imageResult.Exception); + await transaction.CommitAsync(token); - return Created(entity.Id); + if (!request.SkipUpdateProducerTags) + _mediatr.Post(new UpdateProducerTagsCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }); + + return Created(entity.Id); + } }); } @@ -101,57 +107,62 @@ public async Task> Handle(UpdateProductCommand request, Cancellatio { return await ExecuteAsync(request, async () => { - var entity = await _context.GetByIdAsync(request.Id, token); - - if (!string.IsNullOrWhiteSpace(request.Reference) && request.Reference != entity.Reference) + using (var transaction = await _context.BeginTransactionAsync(token)) { - var existingEntity = await _context.FindSingleAsync(p => p.Reference == request.Reference && p.Producer.Id == request.RequestUser.Id, token); - if (existingEntity != null) - return ValidationError(MessageKind.CreateProduct_Reference_AlreadyExists, request.Reference); - } + var entity = await _context.GetByIdAsync(request.Id, token); - if(string.IsNullOrWhiteSpace(request.Reference)) - { - var resultIdentifier = await _mediatr.Process(new CreateProductIdentifierCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }, token); - if (!resultIdentifier.Success) - return Failed(resultIdentifier.Exception); + var reference = request.Reference; + if (!string.IsNullOrWhiteSpace(reference) && reference != entity.Reference) + { + var existingEntity = await _context.FindSingleAsync(p => p.Reference == reference && p.Producer.Id == request.RequestUser.Id, token); + if (existingEntity != null) + return ValidationError(MessageKind.CreateProduct_Reference_AlreadyExists, reference); + } - request.Reference = resultIdentifier.Data; - } + if (string.IsNullOrWhiteSpace(reference)) + { + var resultIdentifier = await _mediatr.Process(new CreateProductIdentifierCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }, token); + if (!resultIdentifier.Success) + return Failed(resultIdentifier.Exception); - entity.SetVat(request.Vat); - entity.SetName(request.Name); - entity.SetDescription(request.Description); - entity.SetWholeSalePricePerUnit(request.WholeSalePricePerUnit); - entity.SetReference(request.Reference); - entity.SetWeight(request.Weight); - entity.SetAvailable(request.Available); - entity.SetStoreVisibility(request.VisibleToStores); - entity.SetConsumerVisibility(request.VisibleToConsumers); - entity.SetConditioning(request.Conditioning, request.QuantityPerUnit, request.Unit); + reference = resultIdentifier.Data; + } - if (request.ReturnableId.HasValue) - { - var returnable = await _context.GetByIdAsync(request.ReturnableId.Value, token); - entity.SetReturnable(returnable); - } - else - { - entity.SetReturnable(null); - } + entity.SetVat(request.Vat); + entity.SetName(request.Name); + entity.SetDescription(request.Description); + entity.SetWholeSalePricePerUnit(request.WholeSalePricePerUnit); + entity.SetReference(reference); + entity.SetWeight(request.Weight); + entity.SetAvailable(request.Available); + entity.SetStoreVisibility(request.VisibleToStores); + entity.SetConsumerVisibility(request.VisibleToConsumers); + entity.SetConditioning(request.Conditioning, request.QuantityPerUnit, request.Unit); + + if (request.ReturnableId.HasValue) + { + var returnable = await _context.GetByIdAsync(request.ReturnableId.Value, token); + entity.SetReturnable(returnable); + } + else + { + entity.SetReturnable(null); + } - var tags = await _context.FindAsync(t => request.Tags.Contains(t.Id), token); - entity.SetTags(tags); + var tags = await _context.FindAsync(t => request.Tags.Contains(t.Id), token); + entity.SetTags(tags); - await _context.SaveChangesAsync(token); + await _context.SaveChangesAsync(token); - _mediatr.Post(new UpdateProducerTagsCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }); + var imageResult = await _mediatr.Process(new UpdateProductPictureCommand(request.RequestUser) { ProductId = entity.Id, Picture = request.Picture }, token); + if (!imageResult.Success) + return Failed(imageResult.Exception); - var imageResult = await _mediatr.Process(new UpdateProductPictureCommand(request.RequestUser) { ProductId = entity.Id, Picture = request.Picture }, token); - if (!imageResult.Success) - return Failed(imageResult.Exception); + await transaction.CommitAsync(token); - return Ok(true); + _mediatr.Post(new UpdateProducerTagsCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }); + return Ok(true); + } }); } diff --git a/Sheaft.Application.Handlers/Commands/QuickOrderCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/QuickOrderCommandsHandler.cs index 50fae2c92..0954c61dd 100644 --- a/Sheaft.Application.Handlers/Commands/QuickOrderCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/QuickOrderCommandsHandler.cs @@ -110,8 +110,9 @@ public async Task> Handle(SetDefaultQuickOrderCommand request, Canc } _context.UpdateRange(quickOrders); + await _context.SaveChangesAsync(token); - return Ok(await _context.SaveChangesAsync(token) > 0); + return Ok(true); }); } @@ -135,9 +136,11 @@ public async Task> Handle(DeleteQuickOrderCommand request, Cancella return await ExecuteAsync(request, async () => { var entity = await _context.GetByIdAsync(request.Id, token); + _context.Remove(entity); + await _context.SaveChangesAsync(token); - return Ok(await _context.SaveChangesAsync(token) > 0); + return Ok(true); }); } } diff --git a/Sheaft.Application.Handlers/Commands/ReturnableCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/ReturnableCommandsHandler.cs index 0eb62cafa..b1d68a539 100644 --- a/Sheaft.Application.Handlers/Commands/ReturnableCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/ReturnableCommandsHandler.cs @@ -60,11 +60,11 @@ public async Task> Handle(DeleteReturnableCommand request, Cancella return await ExecuteAsync(request, async () => { var entity = await _context.GetByIdAsync(request.Id, token); - _context.Remove(entity); - var results = await _context.SaveChangesAsync(token); + _context.Remove(entity); + await _context.SaveChangesAsync(token); - return Ok(results > 0); + return Ok(true); }); } @@ -72,10 +72,12 @@ public async Task> Handle(RestoreReturnableCommand request, Cancell { return await ExecuteAsync(request, async () => { - var entity = await _context.Returnables.SingleOrDefaultAsync(a => a.Id == request.Id && a.RemovedOn.HasValue, token); + var entity = await _context.Returnables.SingleOrDefaultAsync(a => a.Id == request.Id && a.RemovedOn.HasValue, token); + _context.Restore(entity); + await _context.SaveChangesAsync(token); - return Ok(await _context.SaveChangesAsync(token) > 0); + return Ok(true); }); } } diff --git a/Sheaft.Application.Handlers/Commands/RewardCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/RewardCommandsHandler.cs index ce47b3d48..3dfab0f30 100644 --- a/Sheaft.Application.Handlers/Commands/RewardCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/RewardCommandsHandler.cs @@ -89,9 +89,11 @@ public async Task> Handle(DeleteRewardCommand request, Cancellation return await ExecuteAsync(request, async () => { var entity = await _context.GetByIdAsync(request.Id, token); + _context.Remove(entity); + await _context.SaveChangesAsync(token); - return Ok(await _context.SaveChangesAsync(token) > 0); + return Ok(true); }); } @@ -100,9 +102,11 @@ public async Task> Handle(RestoreRewardCommand request, Cancellatio return await ExecuteAsync(request, async () => { var entity = await _context.Rewards.SingleOrDefaultAsync(r => r.Id == request.Id, token); + _context.Restore(entity); + await _context.SaveChangesAsync(token); - return Ok(await _context.SaveChangesAsync(token) > 0); + return Ok(true); }); } } diff --git a/Sheaft.Application.Handlers/Commands/TagCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/TagCommandsHandler.cs index bb422de92..bd280fa45 100644 --- a/Sheaft.Application.Handlers/Commands/TagCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/TagCommandsHandler.cs @@ -29,13 +29,25 @@ public async Task> Handle(CreateTagCommand request, CancellationTok { return await ExecuteAsync(request, async () => { - var entity = new Tag(Guid.NewGuid(), request.Kind, request.Name, request.Description, request.Picture); - entity.SetAvailable(request.Available); + using (var transaction = await _context.BeginTransactionAsync(token)) + { + var entity = new Tag(Guid.NewGuid(), request.Kind, request.Name, request.Description, request.Picture); + entity.SetAvailable(request.Available); - await _context.AddAsync(entity, token); - await _context.SaveChangesAsync(token); + await _context.AddAsync(entity, token); + await _context.SaveChangesAsync(token); + + var imageResult = await _mediatr.Process(new UpdateTagPictureCommand(request.RequestUser) { TagId = entity.Id, Picture = request.Picture }, token); + if (!imageResult.Success) + return Failed(imageResult.Exception); + + var iconResult = await _mediatr.Process(new UpdateTagIconCommand(request.RequestUser) { TagId = entity.Id, Icon = request.Icon }, token); + if (!iconResult.Success) + return Failed(iconResult.Exception); - return Created(entity.Id); + await transaction.CommitAsync(token); + return Created(entity.Id); + } }); } @@ -43,24 +55,28 @@ public async Task> Handle(UpdateTagCommand request, CancellationTok { return await ExecuteAsync(request, async () => { - var entity = await _context.GetByIdAsync(request.Id, token); + using (var transaction = await _context.BeginTransactionAsync(token)) + { + var entity = await _context.GetByIdAsync(request.Id, token); - entity.SetName(request.Name); - entity.SetDescription(request.Description); - entity.SetKind(request.Kind); - entity.SetAvailable(request.Available); + entity.SetName(request.Name); + entity.SetDescription(request.Description); + entity.SetKind(request.Kind); + entity.SetAvailable(request.Available); - await _context.SaveChangesAsync(token); + await _context.SaveChangesAsync(token); - var imageResult = await _mediatr.Process(new UpdateTagPictureCommand(request.RequestUser) { TagId = entity.Id, Picture = request.Picture }, token); - if (!imageResult.Success) - return Failed(imageResult.Exception); + var imageResult = await _mediatr.Process(new UpdateTagPictureCommand(request.RequestUser) { TagId = entity.Id, Picture = request.Picture }, token); + if (!imageResult.Success) + return Failed(imageResult.Exception); - var iconResult = await _mediatr.Process(new UpdateTagIconCommand(request.RequestUser) { TagId = entity.Id, Icon = request.Icon }, token); - if (!iconResult.Success) - return Failed(iconResult.Exception); + var iconResult = await _mediatr.Process(new UpdateTagIconCommand(request.RequestUser) { TagId = entity.Id, Icon = request.Icon }, token); + if (!iconResult.Success) + return Failed(iconResult.Exception); - return Ok(true); + await transaction.CommitAsync(token); + return Ok(true); + } }); } diff --git a/Sheaft.Web.Manage/Controllers/AgreementsController.cs b/Sheaft.Web.Manage/Controllers/AgreementsController.cs index 332cc8222..9115a13d5 100644 --- a/Sheaft.Web.Manage/Controllers/AgreementsController.cs +++ b/Sheaft.Web.Manage/Controllers/AgreementsController.cs @@ -1,16 +1,13 @@ using AutoMapper; using AutoMapper.QueryableExtensions; -using MediatR; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Core.Extensions; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -66,17 +63,9 @@ public async Task Index(CancellationToken token, AgreementStatus? .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; - return View(entities); } @@ -105,13 +94,9 @@ public async Task Reset(AgreementViewModel model, CancellationTok }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } + throw result.Exception; - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Id.ToString("N") }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] @@ -124,12 +109,8 @@ public async Task Delete(Guid id, CancellationToken token) }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = id.ToString("N"); return RedirectToAction("Index"); } @@ -143,13 +124,9 @@ public async Task Restore(Guid id, CancellationToken token) }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = id, Name = id.ToString("N") }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } } } diff --git a/Sheaft.Web.Manage/Controllers/BankAccountsController.cs b/Sheaft.Web.Manage/Controllers/BankAccountsController.cs new file mode 100644 index 000000000..7c05c343e --- /dev/null +++ b/Sheaft.Web.Manage/Controllers/BankAccountsController.cs @@ -0,0 +1,118 @@ +using AutoMapper; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Sheaft.Application.Interop; +using Sheaft.Options; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Sheaft.Application.Models; +using AutoMapper.QueryableExtensions; +using Sheaft.Application.Commands; +using Sheaft.Domain.Models; +using System.Collections.Generic; +using Sheaft.Exceptions; + +namespace Sheaft.Web.Manage.Controllers +{ + public class BankAccountsController : ManageController + { + private readonly ILogger _logger; + + public BankAccountsController( + IAppDbContext context, + IMapper mapper, + ISheaftMediatr mediatr, + IOptionsSnapshot roleOptions, + IConfigurationProvider configurationProvider, + ILogger logger) : base(context, mapper, roleOptions, mediatr, configurationProvider) + { + _logger = logger; + } + + + [HttpGet] + public async Task CreateBankAccount(Guid userId, CancellationToken token) + { + var entity = await _context.Users.OfType() + .AsNoTracking() + .Where(c => c.Id == userId) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + ViewBag.Countries = await GetCountries(token); + return View(new BankAccountViewModel + { + OwnerId = entity.Id, + IsActive = true + }); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task CreateBankAccount(BankAccountViewModel model, CancellationToken token) + { + var result = await _mediatr.Process(new CreateBankAccountCommand(await GetRequestUser(token)) + { + UserId = model.OwnerId, + Address = _mapper.Map(model.Address), + BIC = model.BIC, + IBAN = model.IBAN, + Name = model.Name, + Owner = model.Owner + }, token); + + if (!result.Success) + { + ViewBag.Countries = await GetCountries(token); + ModelState.AddModelError("", result.Exception.Message); + return View(model); + } + + return RedirectToAction("Edit", new { id = model.OwnerId }); + } + + [HttpGet] + public async Task UpdateBankAccount(Guid bankAccountId, CancellationToken token) + { + var entity = await _context.BankAccounts.Get(c => c.Id == bankAccountId) + .ProjectTo(_configurationProvider) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + ViewBag.Countries = await GetCountries(token); + return View(entity); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task UpdateBankAccount(BankAccountViewModel model, CancellationToken token) + { + var result = await _mediatr.Process(new UpdateBankAccountCommand(await GetRequestUser(token)) + { + Id = model.Id, + Address = _mapper.Map(model.Address), + BIC = model.BIC, + IBAN = model.IBAN, + Name = model.Name, + Owner = model.Owner + }, token); + + if (!result.Success) + { + ViewBag.Countries = await GetCountries(token); + ModelState.AddModelError("", result.Exception.Message); + return View(model); + } + + return RedirectToAction("Edit", new { id = model.OwnerId }); + } + } +} diff --git a/Sheaft.Web.Manage/Controllers/BusinessController.cs b/Sheaft.Web.Manage/Controllers/BusinessController.cs new file mode 100644 index 000000000..ebff99226 --- /dev/null +++ b/Sheaft.Web.Manage/Controllers/BusinessController.cs @@ -0,0 +1,55 @@ +using AutoMapper; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Sheaft.Application.Interop; +using Sheaft.Options; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Sheaft.Domain.Enums; +using Sheaft.Exceptions; + +namespace Sheaft.Web.Manage.Controllers +{ + public class BusinessController : ManageController + { + private readonly ILogger _logger; + + public BusinessController( + IAppDbContext context, + IMapper mapper, + ISheaftMediatr mediatr, + IOptionsSnapshot roleOptions, + IConfigurationProvider configurationProvider, + ILogger logger) : base(context, mapper, roleOptions, mediatr, configurationProvider) + { + _logger = logger; + } + + [HttpGet] + public async Task Edit(Guid id, CancellationToken token) + { + var entity = await _context.Users + .AsNoTracking() + .Where(c => c.Id == id) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + if (entity.Kind == ProfileKind.Consumer) + return RedirectToAction("Edit", "Consumers", new { id }); + + if (entity.Kind == ProfileKind.Producer) + return RedirectToAction("Edit", "Producers", new { id }); + + if (entity.Kind == ProfileKind.Store) + return RedirectToAction("Edit", "Stores", new { id }); + + return RedirectToAction("Index", "Dashboard"); + } + } +} diff --git a/Sheaft.Web.Manage/Controllers/ConsumersController.cs b/Sheaft.Web.Manage/Controllers/ConsumersController.cs index 032d1de68..b38163554 100644 --- a/Sheaft.Web.Manage/Controllers/ConsumersController.cs +++ b/Sheaft.Web.Manage/Controllers/ConsumersController.cs @@ -5,16 +5,13 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Domain.Models; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; @@ -59,13 +56,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; @@ -83,6 +73,7 @@ public async Task Edit(Guid id, CancellationToken token) if (entity == null) throw new NotFoundException(); + ViewBag.LegalsId = (await _context.FindSingleAsync(c => c.User.Id == id, token))?.Id; return View(entity); } @@ -90,7 +81,6 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(ConsumerViewModel model, IFormFile picture, CancellationToken token) { - var requestUser = await GetRequestUser(token); if (picture != null) { using (var ms = new MemoryStream()) @@ -100,7 +90,7 @@ public async Task Edit(ConsumerViewModel model, IFormFile picture } } - var result = await _mediatr.Process(new UpdateConsumerCommand(requestUser) + var result = await _mediatr.Process(new UpdateConsumerCommand(await GetRequestUser(token)) { Id = model.Id, Email = model.Email, @@ -116,103 +106,7 @@ public async Task Edit(ConsumerViewModel model, IFormFile picture return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = $"{model.FirstName} {model.LastName}" }); - return RedirectToAction("Index"); - } - - [HttpGet] - public async Task CreateLegal(Guid userId, CancellationToken token) - { - var entity = await _context.Users.OfType() - .AsNoTracking() - .Where(c => c.Id == userId) - .ProjectTo(_configurationProvider) - .SingleOrDefaultAsync(token); - - if (entity == null) - throw new NotFoundException(); - - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - - return View(new ConsumerLegalViewModel - { - Owner = new OwnerViewModel { Id = userId } - }); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task CreateLegal(ConsumerLegalViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new CreateConsumerLegalCommand(requestUser) - { - UserId = model.Owner.Id, - Email = model.Owner.Email, - FirstName = model.Owner.FirstName, - LastName = model.Owner.LastName, - Address = _mapper.Map(model.Owner.Address), - BirthDate = model.Owner.BirthDate, - CountryOfResidence = model.Owner.CountryOfResidence, - Nationality = model.Owner.Nationality - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Created"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Owner.Id, Name = $"{model.Owner.FirstName} {model.Owner.LastName}" }); - return RedirectToAction("Edit", new { id = model.Owner.Id }); - } - - [HttpGet] - public async Task UpdateLegal(Guid userId, CancellationToken token) - { - var entity = await _context.Legals.OfType() - .Where(c => c.User.Id == userId) - .ProjectTo(_configurationProvider) - .SingleOrDefaultAsync(token); - - if (entity == null) - return RedirectToAction("CreateLegal", new { userId = userId }); - - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - return View(entity); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task UpdateLegal(ConsumerLegalViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new UpdateConsumerLegalCommand(requestUser) - { - Id = model.Id, - Email = model.Owner.Email, - FirstName = model.Owner.FirstName, - LastName = model.Owner.LastName, - Address = _mapper.Map(model.Owner.Address), - BirthDate = model.Owner.BirthDate, - CountryOfResidence = model.Owner.CountryOfResidence, - Nationality = model.Owner.Nationality - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Owner.Id, Name = $"{model.Owner.FirstName} {model.Owner.LastName}" }); - return RedirectToAction("Edit", new { id = model.Owner.Id }); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] @@ -222,30 +116,15 @@ public async Task Delete(Guid id, CancellationToken token) var entity = await _context.Users.OfType().SingleOrDefaultAsync(c => c.Id == id, token); var name = entity.Name; - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RemoveUserCommand(requestUser) + var result = await _mediatr.Process(new RemoveUserCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } - - private async Task> GetCountries(CancellationToken token) - { - return await _context.Countries.AsNoTracking().ProjectTo(_configurationProvider).ToListAsync(token); - } - - private async Task> GetNationalities(CancellationToken token) - { - return await _context.Nationalities.AsNoTracking().ProjectTo(_configurationProvider).ToListAsync(token); - } } } diff --git a/Sheaft.Web.Manage/Controllers/DashboardController.cs b/Sheaft.Web.Manage/Controllers/DashboardController.cs index ed5f7d50e..412be0287 100644 --- a/Sheaft.Web.Manage/Controllers/DashboardController.cs +++ b/Sheaft.Web.Manage/Controllers/DashboardController.cs @@ -32,9 +32,9 @@ public async Task Index(CancellationToken token) var requestUser = await GetRequestUser(token); ViewBag.Consumers = await _context.Users.OfType().CountAsync(c => !c.RemovedOn.HasValue, token); - //ViewBag.Tags = await _context.Tags.CountAsync(c => !c.RemovedOn.HasValue, token); - //ViewBag.Departments = await _context.Departments.CountAsync(token); - //ViewBag.Regions = await _context.Regions.CountAsync(token); + ViewBag.Tags = await _context.Tags.CountAsync(c => !c.RemovedOn.HasValue, token); + ViewBag.Departments = await _context.Departments.CountAsync(token); + ViewBag.Regions = await _context.Regions.CountAsync(token); //ViewBag.Levels = await _context.Levels.CountAsync(c => !c.RemovedOn.HasValue, token); //ViewBag.Rewards = await _context.Rewards.CountAsync(c => !c.RemovedOn.HasValue, token); diff --git a/Sheaft.Web.Manage/Controllers/DeclarationsController.cs b/Sheaft.Web.Manage/Controllers/DeclarationsController.cs index ea8957c57..22941171b 100644 --- a/Sheaft.Web.Manage/Controllers/DeclarationsController.cs +++ b/Sheaft.Web.Manage/Controllers/DeclarationsController.cs @@ -79,11 +79,11 @@ public async Task Index(CancellationToken token, int page = 0, in } [HttpGet] - public async Task Details(Guid declarationId, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var entity = await _context.Legals .OfType() - .Where(c => c.Declaration.Id == declarationId) + .Where(c => c.Declaration.Id == id) .ProjectTo(_configurationProvider) .SingleOrDefaultAsync(token); @@ -103,8 +103,8 @@ public async Task Create(Guid legalId, CancellationToken token) .OfType() .SingleOrDefaultAsync(c => c.Id == legalId, token); - if (entity.Declaration != null) - return RedirectToAction("Details", new { declarationId = entity.Declaration.Id }); + if (entity == null) + throw new NotFoundException(); var result = await _mediatr.Process(new CreateDeclarationCommand(await GetRequestUser(token)) { @@ -114,7 +114,7 @@ public async Task Create(Guid legalId, CancellationToken token) if (!result.Success) throw result.Exception; - return RedirectToAction("Details", new { declarationId = result.Data }); + return RedirectToAction("Edit", new { id = result.Data }); } [HttpGet] @@ -152,7 +152,7 @@ public async Task AddUbo(Guid declarationId, UboViewModel model, return View(model); } - return RedirectToAction("Details", new { declarationId = declarationId }); + return RedirectToAction("Edit", new { id = declarationId }); } [HttpGet] @@ -199,7 +199,7 @@ public async Task EditUbo(Guid declarationId, UboViewModel model, return View(model); } - return RedirectToAction("Details", new { declarationId = declarationId }); + return RedirectToAction("Edit", new { id = declarationId }); } [HttpPost] @@ -214,7 +214,7 @@ public async Task Lock(Guid declarationId, CancellationToken toke if (!result.Success) throw result.Exception; - return RedirectToAction("Details", new { declarationId = declarationId }); + return RedirectToAction("Edit", new { id = declarationId }); } [HttpPost] @@ -229,7 +229,7 @@ public async Task Unlock(Guid declarationId, CancellationToken to if (!result.Success) throw result.Exception; - return RedirectToAction("Details", new { declarationId = declarationId }); + return RedirectToAction("Edit", new { id = declarationId }); } [HttpPost] @@ -244,7 +244,7 @@ public async Task Validate(Guid declarationId, CancellationToken if (!result.Success) throw result.Exception; - return RedirectToAction("Details", new { declarationId = declarationId }); + return RedirectToAction("Edit", new { id = declarationId }); } [HttpPost] @@ -259,23 +259,7 @@ public async Task DeleteUbo(Guid declarationId, Guid uboId, Cance if (!result.Success) throw result.Exception; - return RedirectToAction("Details", new { declarationId = declarationId }); - } - - private async Task> GetCountries(CancellationToken token) - { - return await _context.Countries - .AsNoTracking() - .ProjectTo(_configurationProvider) - .ToListAsync(token); - } - - private async Task> GetNationalities(CancellationToken token) - { - return await _context.Nationalities - .AsNoTracking() - .ProjectTo(_configurationProvider) - .ToListAsync(token); + return RedirectToAction("Edit", new { id = declarationId }); } } } diff --git a/Sheaft.Web.Manage/Controllers/DeliveryModesController.cs b/Sheaft.Web.Manage/Controllers/DeliveryModesController.cs index ddd1a2c70..208ee33c4 100644 --- a/Sheaft.Web.Manage/Controllers/DeliveryModesController.cs +++ b/Sheaft.Web.Manage/Controllers/DeliveryModesController.cs @@ -1,15 +1,12 @@ using AutoMapper; using AutoMapper.QueryableExtensions; -using MediatR; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -58,67 +55,15 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; return View(entities); } - [HttpGet] - public async Task Add(CancellationToken token) - { - var requestUser = await GetRequestUser(token); - if (!requestUser.IsImpersonating) - return RedirectToAction("Impersonate", "Account"); - - return View(new DeliveryModeViewModel()); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Add(DeliveryModeViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - if (!requestUser.IsImpersonating) - { - ModelState.AddModelError("", "You must impersonate producer to create it."); - return View(model); - } - - var entity = await _context.DeliveryModes.SingleOrDefaultAsync(t => t.Id == model.Id, token); - var result = await _mediatr.Process(new CreateDeliveryModeCommand(requestUser) - { - Description = model.Description, - Name = model.Name, - Address = _mapper.Map(model.Address), - Kind = model.Kind, - LockOrderHoursBeforeDelivery = model.LockOrderHoursBeforeDelivery, - OpeningHours = entity.OpeningHours?.GroupBy(oh => new { oh.From, oh.To }).Select(c => new TimeSlotGroupInput { From = c.Key.From, To = c.Key.To, Days = c.Select(o => o.Day) }) - }, token); - - if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - return RedirectToAction("Edit", new { id = result.Data }); - } - [HttpGet] public async Task Edit(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - if (!requestUser.IsImpersonating) - return RedirectToAction("Impersonate", "Account"); - var entity = await _context.DeliveryModes .AsNoTracking() .Where(c => c.Id == id) @@ -135,14 +80,7 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(DeliveryModeViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - if (!requestUser.IsImpersonating) - { - ModelState.AddModelError("", "You must impersonate delivery's producer to edit it."); - return View(model); - } - - var result = await _mediatr.Process(new UpdateDeliveryModeCommand(requestUser) + var result = await _mediatr.Process(new UpdateDeliveryModeCommand(await GetRequestUser(token)) { Id = model.Id, Description = model.Description, @@ -158,30 +96,21 @@ public async Task Edit(DeliveryModeViewModel model, CancellationT return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.DeliveryModes.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteDeliveryModeCommand(requestUser) + var result = await _mediatr.Process(new DeleteDeliveryModeCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = name; return RedirectToAction("Index"); } @@ -189,23 +118,15 @@ public async Task Delete(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.DeliveryModes.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestoreDeliveryModeCommand(requestUser) + var result = await _mediatr.Process(new RestoreDeliveryModeCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } } } diff --git a/Sheaft.Web.Manage/Controllers/DepartmentsController.cs b/Sheaft.Web.Manage/Controllers/DepartmentsController.cs index 716f6d767..3f3b05d85 100644 --- a/Sheaft.Web.Manage/Controllers/DepartmentsController.cs +++ b/Sheaft.Web.Manage/Controllers/DepartmentsController.cs @@ -4,11 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -51,9 +49,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - ViewBag.Page = page; ViewBag.Take = take; @@ -63,7 +58,6 @@ public async Task Index(CancellationToken token, int page = 0, in [HttpGet] public async Task Edit(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); var entity = await _context.Departments .AsNoTracking() .Where(c => c.Id == id) @@ -80,8 +74,7 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(DepartmentViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new UpdateDepartmentCommand(requestUser) + var result = await _mediatr.Process(new UpdateDepartmentCommand(await GetRequestUser(token)) { Id = model.Id, Name = model.Name, @@ -94,8 +87,7 @@ public async Task Edit(DepartmentViewModel model, CancellationTok return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } } } diff --git a/Sheaft.Web.Manage/Controllers/DocumentsController.cs b/Sheaft.Web.Manage/Controllers/DocumentsController.cs index 3191a5908..7274ecad7 100644 --- a/Sheaft.Web.Manage/Controllers/DocumentsController.cs +++ b/Sheaft.Web.Manage/Controllers/DocumentsController.cs @@ -16,6 +16,7 @@ using System.Threading; using System.Threading.Tasks; using Sheaft.Application.Queries; +using Sheaft.Domain.Enums; namespace Sheaft.Web.Manage.Controllers { @@ -38,10 +39,10 @@ public DocumentsController( } [HttpGet] - public async Task Edit(Guid id, CancellationToken token) + public async Task Create(Guid legalId, CancellationToken token) { var entity = await _context.Legals - .Where(c => c.Documents.Any(d => d.Id == id)) + .Where(c => c.Id == legalId) .ProjectTo(_configurationProvider) .SingleOrDefaultAsync(token); @@ -52,32 +53,31 @@ public async Task Edit(Guid id, CancellationToken token) ViewBag.UserId = entity.Owner.Id; ViewBag.LegalId = entity.Id; - var document = entity.Documents.FirstOrDefault(d => d.Id == id); - return View(document); + return View(new DocumentViewModel()); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Edit(DocumentViewModel model, CancellationToken token) + public async Task Create(Guid legalId, DocumentViewModel model, CancellationToken token) { - var result = await _mediatr.Process(new UpdateDocumentCommand(await GetRequestUser(token)) + var result = await _mediatr.Process(new CreateDocumentCommand(await GetRequestUser(token)) { - Id = model.Id, Name = model.Name, Kind = model.Kind, + LegalId = legalId }, token); if (!result.Success) throw result.Exception; - return RedirectToAction("Edit", new { id = model.Id }); + return RedirectToAction("Edit", new { id = result.Data }); } [HttpGet] - public async Task Create(Guid legalId, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var entity = await _context.Legals - .Where(c => c.Id == legalId) + .Where(c => c.Documents.Any(d => d.Id == id)) .ProjectTo(_configurationProvider) .SingleOrDefaultAsync(token); @@ -88,24 +88,25 @@ public async Task Create(Guid legalId, CancellationToken token) ViewBag.UserId = entity.Owner.Id; ViewBag.LegalId = entity.Id; - return View(new DocumentViewModel()); + var document = entity.Documents.FirstOrDefault(d => d.Id == id); + return View(document); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Create(Guid legalId, DocumentViewModel model, CancellationToken token) + public async Task Edit(DocumentViewModel model, CancellationToken token) { - var result = await _mediatr.Process(new CreateDocumentCommand(await GetRequestUser(token)) + var result = await _mediatr.Process(new UpdateDocumentCommand(await GetRequestUser(token)) { + Id = model.Id, Name = model.Name, Kind = model.Kind, - LegalId = legalId }, token); if (!result.Success) throw result.Exception; - return RedirectToAction("Edit", new { id = result.Data }); + return RedirectToAction("Edit", new { model.Id }); } [HttpGet] @@ -154,7 +155,7 @@ public async Task AddPage(DocumentViewModel model, IFormFile page if (!result.Success) throw result.Exception; - return RedirectToAction("Edit", new { id = model.Id }); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] @@ -169,7 +170,7 @@ public async Task Lock(Guid id, CancellationToken token) if (!result.Success) throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] @@ -184,7 +185,7 @@ public async Task Unlock(Guid id, CancellationToken token) if (!result.Success) throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] @@ -199,7 +200,7 @@ public async Task Validate(Guid id, CancellationToken token) if (!result.Success) throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] @@ -256,11 +257,7 @@ public async Task DeletePage(Guid documentId, Guid pageId, Cancel [ValidateAntiForgeryToken] public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Legals - .SingleOrDefaultAsync(c => c.Documents.Any(d => d.Id == id), token); - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteDocumentCommand(requestUser) + var result = await _mediatr.Process(new DeleteDocumentCommand(await GetRequestUser(token)) { Id = id }, token); @@ -268,7 +265,13 @@ public async Task Delete(Guid id, CancellationToken token) if (!result.Success) throw result.Exception; - return RedirectToAction("Index", "Producers", new { userid = entity.User.Id }); + var entity = await _context.Legals + .SingleOrDefaultAsync(c => c.Documents.Any(d => d.Id == id), token); + + if (entity.Kind != LegalKind.Natural) + return RedirectToAction("EditLegalBusiness", "Legals", new { entity.Id }); + + return RedirectToAction("EditLegalConsumer", "Legals", new { entity.Id }); } } } diff --git a/Sheaft.Web.Manage/Controllers/DonationsController.cs b/Sheaft.Web.Manage/Controllers/DonationsController.cs index c4f1f159f..d0112401d 100644 --- a/Sheaft.Web.Manage/Controllers/DonationsController.cs +++ b/Sheaft.Web.Manage/Controllers/DonationsController.cs @@ -4,10 +4,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Options; using System; using System.Linq; @@ -44,11 +42,6 @@ public async Task Index(CancellationToken token, TransactionStatu take = 100; var query = _context.Donations.AsNoTracking(); - - var requestUser = await GetRequestUser(token); - if (requestUser.IsImpersonating) - query = query.Where(p => p.Author.Id == requestUser.Id); - if (status != null) query = query.Where(t => t.Status == status); @@ -59,22 +52,14 @@ public async Task Index(CancellationToken token, TransactionStatu .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; - return View(entities); } [HttpGet] - public async Task Details(Guid id, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var entity = await _context.Donations .AsNoTracking() @@ -92,15 +77,14 @@ public async Task Details(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Expire(DonationViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new ExpireDonationCommand(requestUser) { DonationId = model.Id }, token); - if (!result.Success) + var result = await _mediatr.Process(new ExpireDonationCommand(await GetRequestUser(token)) { - ModelState.AddModelError("", result.Exception.Message); - return View("Details", model); - } + DonationId = model.Id + }, token); + + if (!result.Success) + throw result.Exception; - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Identifier }); return RedirectToAction("Index"); } } diff --git a/Sheaft.Web.Manage/Controllers/JobsController.cs b/Sheaft.Web.Manage/Controllers/JobsController.cs index 55bfac4a8..01a3d28eb 100644 --- a/Sheaft.Web.Manage/Controllers/JobsController.cs +++ b/Sheaft.Web.Manage/Controllers/JobsController.cs @@ -4,11 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -59,13 +57,6 @@ public async Task Index(CancellationToken token, ProcessStatus? s .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; @@ -92,8 +83,7 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(JobViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new UpdateJobCommand(requestUser) + var result = await _mediatr.Process(new UpdateJobCommand(await GetRequestUser(token)) { Id = model.Id, Name = model.Name @@ -105,27 +95,22 @@ public async Task Edit(JobViewModel model, CancellationToken toke return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Archive(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new ArchiveJobCommand(requestUser) + var result = await _mediatr.Process(new ArchiveJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Edit", new { id = id }); - } + throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] @@ -139,152 +124,113 @@ public async Task Pause(Guid id, CancellationToken token) }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Edit", new { id = id }); - } + throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Resume(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new ResumeJobCommand(requestUser) + var result = await _mediatr.Process(new ResumeJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Edit", new { id = id }); - } + throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Cancel(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new CancelJobCommand(requestUser) + var result = await _mediatr.Process(new CancelJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Edit", new { id = id }); - } + throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Retry(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RetryJobCommand(requestUser) + var result = await _mediatr.Process(new RetryJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Edit", new { id = id }); - } + throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Unarchive(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new UnarchiveJobCommand(requestUser) + var result = await _mediatr.Process(new UnarchiveJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Edit", new { id = id }); - } + throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Reset(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new ResetJobCommand(requestUser) + var result = await _mediatr.Process(new ResetJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Edit", new { id = id }); - } + throw result.Exception; - return RedirectToAction("Edit", new { id = id }); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Delete(Guid id, CancellationToken token) + public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.Jobs.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteJobCommand(requestUser) + var result = await _mediatr.Process(new RestoreJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = name; - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Restore(Guid id, CancellationToken token) + public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Jobs.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestoreJobCommand(requestUser) + var result = await _mediatr.Process(new DeleteJobCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } } diff --git a/Sheaft.Web.Manage/Controllers/LegalsController.cs b/Sheaft.Web.Manage/Controllers/LegalsController.cs new file mode 100644 index 000000000..e3e71a5af --- /dev/null +++ b/Sheaft.Web.Manage/Controllers/LegalsController.cs @@ -0,0 +1,292 @@ +using AutoMapper; +using AutoMapper.QueryableExtensions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Sheaft.Application.Commands; +using Sheaft.Domain.Models; +using Sheaft.Exceptions; +using Sheaft.Application.Interop; +using Sheaft.Application.Models; +using Sheaft.Options; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Sheaft.Domain.Enums; + +namespace Sheaft.Web.Manage.Controllers +{ + public class LegalsController : ManageController + { + private readonly ILogger _logger; + + public LegalsController( + IAppDbContext context, + IMapper mapper, + ISheaftMediatr mediatr, + IOptionsSnapshot roleOptions, + IConfigurationProvider configurationProvider, + ILogger logger) : base(context, mapper, roleOptions, mediatr, configurationProvider) + { + _logger = logger; + } + + [HttpGet] + public async Task Index(CancellationToken token, LegalKind? kind = null, int page = 0, int take = 10) + { + if (page < 0) + page = 0; + + if (take > 100) + take = 100; + + var query = _context.Legals.AsNoTracking(); + if (kind != null) + query = query.Where(p => p.Kind == kind); + + var entities = await query + .OrderByDescending(c => c.CreatedOn) + .Skip(page * take) + .Take(take) + .ProjectTo(_configurationProvider) + .ToListAsync(token); + + ViewBag.Page = page; + ViewBag.Take = take; + ViewBag.Kind = kind; + + return View(entities); + } + + [HttpGet] + public async Task EditUserLegals(Guid userId, CancellationToken token) + { + var entity = await _context.Legals + .AsNoTracking() + .Where(c => c.User.Id == userId) + .SingleOrDefaultAsync(token); + + if (entity.Kind != LegalKind.Natural) + return RedirectToAction("EditLegalBusiness", new { entity.Id }); + + return RedirectToAction("EditLegalConsumer", new { entity.Id }); + } + + [HttpGet] + public async Task Edit(Guid id, CancellationToken token) + { + var entity = await _context.Legals + .AsNoTracking() + .Where(c => c.Id == id) + .SingleOrDefaultAsync(token); + + if (entity.Kind != LegalKind.Natural) + return RedirectToAction("EditLegalBusiness", new { entity.Id }); + + return RedirectToAction("EditLegalConsumer", new { entity.Id }); + } + + [HttpGet] + public async Task Create(Guid userId, CancellationToken token) + { + var entity = await _context.Users + .AsNoTracking() + .Where(c => c.Id == userId) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + if (entity.Kind != ProfileKind.Consumer) + return RedirectToAction("CreateLegalBusiness", new { userId }); + + return RedirectToAction("CreateLegalConsumer", new { userId }); + } + + [HttpGet] + public async Task CreateLegalBusiness(Guid userId, CancellationToken token) + { + var entity = await _context.Users + .AsNoTracking() + .Where(c => c.Id == userId) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + + return View(new BusinessLegalViewModel + { + Owner = new OwnerViewModel { Id = userId } + }); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task CreateLegalBusiness(BusinessLegalViewModel model, CancellationToken token) + { + var result = await _mediatr.Process(new CreateBusinessLegalCommand(await GetRequestUser(token)) + { + UserId = model.Owner.Id, + Name = model.Name, + Email = model.Email, + Address = _mapper.Map(model.Address), + Kind = model.Kind, + Owner = _mapper.Map(model.Owner), + Siret = model.Siret, + VatIdentifier = model.VatIdentifier + }, token); + + if (!result.Success) + { + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + ModelState.AddModelError("", result.Exception.Message); + return View(model); + } + + return RedirectToAction("EditLegalBusiness", new { id = result.Data }); + } + + [HttpGet] + public async Task CreateLegalConsumer(Guid userId, CancellationToken token) + { + var entity = await _context.Users + .AsNoTracking() + .Where(c => c.Id == userId) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + + return View(new ConsumerLegalViewModel + { + Kind = LegalKind.Natural, + Owner = new OwnerViewModel { Id = userId } + }); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task CreateLegalConsumer(ConsumerLegalViewModel model, CancellationToken token) + { + var result = await _mediatr.Process(new CreateConsumerLegalCommand(await GetRequestUser(token)) + { + UserId = model.Owner.Id, + Email = model.Owner.Email, + FirstName = model.Owner.FirstName, + LastName = model.Owner.LastName, + Address = _mapper.Map(model.Owner.Address), + BirthDate = model.Owner.BirthDate, + CountryOfResidence = model.Owner.CountryOfResidence, + Nationality = model.Owner.Nationality + }, token); + + if (!result.Success) + { + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + ModelState.AddModelError("", result.Exception.Message); + return View(model); + } + + return RedirectToAction("EditLegalConsumer", new { id = result.Data }); + } + + [HttpGet] + public async Task EditLegalBusiness(Guid id, CancellationToken token) + { + var entity = await _context.Legals.OfType() + .AsNoTracking() + .Where(c => c.Id == id) + .ProjectTo(_configurationProvider) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + return View(entity); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task EditLegalBusiness(BusinessLegalViewModel model, CancellationToken token) + { + var result = await _mediatr.Process(new UpdateBusinessLegalCommand(await GetRequestUser(token)) + { + Id = model.Id, + Name = model.Name, + Email = model.Email, + Address = _mapper.Map(model.Address), + Kind = model.Kind, + Owner = _mapper.Map(model.Owner), + Siret = model.Siret, + VatIdentifier = model.VatIdentifier + }, token); + + if (!result.Success) + { + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + ModelState.AddModelError("", result.Exception.Message); + return View(model); + } + + return RedirectToAction("EditLegalBusiness", new { model.Id }); + } + + [HttpGet] + public async Task EditLegalConsumer(Guid id, CancellationToken token) + { + var entity = await _context.Legals.OfType() + .AsNoTracking() + .Where(c => c.Id == id) + .ProjectTo(_configurationProvider) + .SingleOrDefaultAsync(token); + + if (entity == null) + throw new NotFoundException(); + + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + return View(entity); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task EditLegalConsumer(ConsumerLegalViewModel model, CancellationToken token) + { + var result = await _mediatr.Process(new UpdateConsumerLegalCommand(await GetRequestUser(token)) + { + Id = model.Id, + Email = model.Owner.Email, + FirstName = model.Owner.FirstName, + LastName = model.Owner.LastName, + Address = _mapper.Map(model.Owner.Address), + BirthDate = model.Owner.BirthDate, + CountryOfResidence = model.Owner.CountryOfResidence, + Nationality = model.Owner.Nationality + }, token); + + if (!result.Success) + { + ViewBag.Countries = await GetCountries(token); + ViewBag.Nationalities = await GetNationalities(token); + ModelState.AddModelError("", result.Exception.Message); + return View(model); + } + + return RedirectToAction("EditLegalConsumer", new { model.Id }); + } + } +} diff --git a/Sheaft.Web.Manage/Controllers/LevelsController.cs b/Sheaft.Web.Manage/Controllers/LevelsController.cs index 3500f9f47..26ba1fcee 100644 --- a/Sheaft.Web.Manage/Controllers/LevelsController.cs +++ b/Sheaft.Web.Manage/Controllers/LevelsController.cs @@ -4,11 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -51,10 +49,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; @@ -71,8 +65,7 @@ public IActionResult Add() [ValidateAntiForgeryToken] public async Task Add(LevelViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new CreateLevelCommand(requestUser) + var result = await _mediatr.Process(new CreateLevelCommand(await GetRequestUser(token)) { Name = model.Name, RequiredPoints = model.RequiredPoints, @@ -108,9 +101,7 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(LevelViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - - var result = await _mediatr.Process(new UpdateLevelCommand(requestUser) + var result = await _mediatr.Process(new UpdateLevelCommand(await GetRequestUser(token)) { Id = model.Id, Name = model.Name, @@ -123,7 +114,6 @@ public async Task Edit(LevelViewModel model, CancellationToken to return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); return RedirectToAction("Index"); } @@ -131,22 +121,14 @@ public async Task Edit(LevelViewModel model, CancellationToken to [ValidateAntiForgeryToken] public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Levels.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteLevelCommand(requestUser) + var result = await _mediatr.Process(new DeleteLevelCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = name; return RedirectToAction("Index"); } @@ -154,23 +136,15 @@ public async Task Delete(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.Levels.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestoreLevelCommand(requestUser) + var result = await _mediatr.Process(new RestoreLevelCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } } } diff --git a/Sheaft.Web.Manage/Controllers/ManageController.cs b/Sheaft.Web.Manage/Controllers/ManageController.cs index 630fbb979..4ef49134b 100644 --- a/Sheaft.Web.Manage/Controllers/ManageController.cs +++ b/Sheaft.Web.Manage/Controllers/ManageController.cs @@ -80,5 +80,15 @@ protected async Task GetRequestUser(CancellationToken token) return requestUser; } + protected async Task> GetCountries(CancellationToken token) + { + return await _context.Countries.AsNoTracking().ProjectTo(_configurationProvider).ToListAsync(token); + } + + protected async Task> GetNationalities(CancellationToken token) + { + return await _context.Nationalities.AsNoTracking().ProjectTo(_configurationProvider).ToListAsync(token); + } + } } diff --git a/Sheaft.Web.Manage/Controllers/OrdersController.cs b/Sheaft.Web.Manage/Controllers/OrdersController.cs index bcf9160f1..a112c0352 100644 --- a/Sheaft.Web.Manage/Controllers/OrdersController.cs +++ b/Sheaft.Web.Manage/Controllers/OrdersController.cs @@ -4,10 +4,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Options; using System; using System.Linq; @@ -59,13 +57,6 @@ public async Task Index(CancellationToken token, OrderStatus? sta .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; @@ -74,7 +65,7 @@ public async Task Index(CancellationToken token, OrderStatus? sta } [HttpGet] - public async Task Details(Guid id, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var entity = await _context.Orders .AsNoTracking() @@ -92,64 +83,60 @@ public async Task Details(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Expire(OrderViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new ExpireOrderCommand(requestUser) { OrderId = model.Id }, token); - if (!result.Success) + var result = await _mediatr.Process(new ExpireOrderCommand(await GetRequestUser(token)) { - ModelState.AddModelError("", result.Exception.Message); - return View("Details", model); - } + OrderId = model.Id + }, token); - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Payin?.Identifier }); - return RedirectToAction("Index"); + if (!result.Success) + throw result.Exception; + + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Confirm(OrderViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new ConfirmOrderCommand(requestUser) { OrderId = model.Id }, token); - if (!result.Success) + var result = await _mediatr.Process(new ConfirmOrderCommand(await GetRequestUser(token)) { - ModelState.AddModelError("", result.Exception.Message); - return View("Details", model); - } + OrderId = model.Id + }, token); + + if (!result.Success) + throw result.Exception; - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Payin?.Identifier }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Fail(OrderViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new FailOrderCommand(requestUser) { OrderId = model.Id }, token); - if (!result.Success) + var result = await _mediatr.Process(new FailOrderCommand(await GetRequestUser(token)) { - ModelState.AddModelError("", result.Exception.Message); - return View("Details", model); - } + OrderId = model.Id + }, token); + + if (!result.Success) + throw result.Exception; - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Payin?.Identifier }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Retry(OrderViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RetryOrderCommand(requestUser) { OrderId = model.Id }, token); - if (!result.Success) + var result = await _mediatr.Process(new RetryOrderCommand(await GetRequestUser(token)) { - ModelState.AddModelError("", result.Exception.Message); - return View("Details", model); - } + OrderId = model.Id + }, token); + + if (!result.Success) + throw result.Exception; - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Payin?.Identifier }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } } } diff --git a/Sheaft.Web.Manage/Controllers/PayinsController.cs b/Sheaft.Web.Manage/Controllers/PayinsController.cs index 338bdb590..f9d145d40 100644 --- a/Sheaft.Web.Manage/Controllers/PayinsController.cs +++ b/Sheaft.Web.Manage/Controllers/PayinsController.cs @@ -4,17 +4,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Options; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using Sheaft.Domain.Enums; -using Sheaft.Application.Commands; using Sheaft.Application.Models; namespace Sheaft.Web.Manage.Controllers @@ -62,13 +59,6 @@ public async Task Index(CancellationToken token, TransactionStatu .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; @@ -77,53 +67,7 @@ public async Task Index(CancellationToken token, TransactionStatu } [HttpGet] - public async Task Todo(CancellationToken token, int page = 0, int take = 10) - { - if (page < 0) - page = 0; - - if (take > 100) - take = 100; - - var expiredDate = DateTimeOffset.UtcNow.AddMinutes(-_routineOptions.CheckNewPayinRefundsFromMinutes); - var ordersToRefund = await _context.Orders - .Get(c => - c.Payin != null - && c.Payin.Status == TransactionStatus.Succeeded - && c.Payin.Refunds.All(c => c.Status != TransactionStatus.Failed) - && c.PurchaseOrders.All(po => po.Status >= PurchaseOrderStatus.Delivered) - && c.PurchaseOrders.Any(po => po.WithdrawnOn.HasValue - && (po.Transfer == null - || (po.Transfer.Status == TransactionStatus.Succeeded))) - && c.PurchaseOrders.Max(po => po.WithdrawnOn) < expiredDate, true) - .OrderBy(c => c.CreatedOn) - .Skip(page * take) - .Take(take) - .ProjectTo(_configurationProvider) - .ToListAsync(token); - - var submitted = (string)TempData["Submitted"]; - ViewBag.Submitted = !string.IsNullOrWhiteSpace(submitted) ? JsonConvert.DeserializeObject(submitted) : null; - - ViewBag.Page = page; - ViewBag.Take = take; - - return View(ordersToRefund); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task CreatePayinRefund(Guid id, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - //_mediatr.Post(new CreatePayinRefundCommand(requestUser) { PayinId = id }); - - TempData["Submitted"] = JsonConvert.SerializeObject(new EntityViewModel { Id = id, Name = id.ToString("N") }); - return RedirectToAction("Todo"); - } - - [HttpGet] - public async Task Details(Guid id, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var entity = await _context.Payins .AsNoTracking() diff --git a/Sheaft.Web.Manage/Controllers/PayoutsController.cs b/Sheaft.Web.Manage/Controllers/PayoutsController.cs index 35542f914..80c458a81 100644 --- a/Sheaft.Web.Manage/Controllers/PayoutsController.cs +++ b/Sheaft.Web.Manage/Controllers/PayoutsController.cs @@ -4,17 +4,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Options; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using Sheaft.Domain.Enums; -using Sheaft.Application.Commands; using Sheaft.Application.Models; namespace Sheaft.Web.Manage.Controllers @@ -46,7 +43,7 @@ public async Task Index(CancellationToken token, TransactionStatu if (take > 100) take = 100; - var query = _context.Payouts.Where(t => t.Status != TransactionStatus.Succeeded).AsNoTracking(); + var query = _context.Payouts.AsNoTracking(); var requestUser = await GetRequestUser(token); if (requestUser.IsImpersonating) @@ -62,13 +59,6 @@ public async Task Index(CancellationToken token, TransactionStatu .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; @@ -77,61 +67,7 @@ public async Task Index(CancellationToken token, TransactionStatu } [HttpGet] - public async Task Todo(CancellationToken token, int page = 0, int take = 10) - { - if (page < 0) - page = 0; - - if (take > 100) - take = 100; - - var producersTransfers = await _context.Transfers - .Get(t => t.Status == TransactionStatus.Succeeded - && (t.Payout == null || t.Payout.Status == TransactionStatus.Failed) - && t.PurchaseOrder.Status == PurchaseOrderStatus.Delivered - && t.PurchaseOrder.DeliveredOn.HasValue) - .Select(t => new ProducerPayoutViewModel { ProducerId = t.CreditedWallet.User.Id, Amount = t.Credited, TransferId = t.Id, Name = t.CreditedWallet.User.Name, Email = t.CreditedWallet.User.Email, Phone = t.CreditedWallet.User.Phone }) - .OrderBy(c => c.ProducerId) - .Skip(page * take) - .Take(take) - .ToListAsync(token); - - var groupedProducers = producersTransfers.GroupBy(t => t.ProducerId); - var entities = groupedProducers.Select(c => new ProducerPayoutsViewModel - { - Id = c.First().ProducerId, - Email = c.First().Email, - Name = c.First().Email, - Phone = c.First().Email, - Total = c.Sum(t => t.Amount), - Transfers = c.Select(t => new ProducerTransferViewModel { Id = t.TransferId, Amount = t.Amount }) - }); - - var submitted = (string)TempData["Submitted"]; - ViewBag.Submitted = !string.IsNullOrWhiteSpace(submitted) ? JsonConvert.DeserializeObject(submitted) : null; - - ViewBag.Page = page; - ViewBag.Take = take; - - return View(entities); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task CreatePayout(ProducerPayoutsViewModel model, CancellationToken token) - { - if (!model.Transfers.Any()) - return BadRequest(); - - var requestUser = await GetRequestUser(token); - _mediatr.Post(new CreatePayoutCommand(requestUser) { ProducerId = model.Id, TransferIds = model.Transfers.Select(t => t.Id) }); - - TempData["Submitted"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Todo"); - } - - [HttpGet] - public async Task Details(Guid id, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var entity = await _context.Payouts .AsNoTracking() diff --git a/Sheaft.Web.Manage/Controllers/ProducersController.cs b/Sheaft.Web.Manage/Controllers/ProducersController.cs index ec3012bda..f0716680c 100644 --- a/Sheaft.Web.Manage/Controllers/ProducersController.cs +++ b/Sheaft.Web.Manage/Controllers/ProducersController.cs @@ -5,16 +5,13 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Domain.Models; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; @@ -59,16 +56,8 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; - return View(entities); } @@ -94,7 +83,6 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(ProducerViewModel model, IFormFile picture, CancellationToken token) { - var requestUser = await GetRequestUser(token); if (picture != null) { using (var ms = new MemoryStream()) @@ -104,8 +92,8 @@ public async Task Edit(ProducerViewModel model, IFormFile picture } } - var entity = await _context.Users.OfType().SingleOrDefaultAsync(c => c.Id == model.Id, token); - var result = await _mediatr.Process(new UpdateProducerCommand(requestUser) + var producer = await _context.Users.OfType().SingleOrDefaultAsync(c => c.Id == model.Id, token); + var result = await _mediatr.Process(new UpdateProducerCommand(await GetRequestUser(token)) { Id = model.Id, Address = _mapper.Map(model.Address), @@ -117,7 +105,7 @@ public async Task Edit(ProducerViewModel model, IFormFile picture LastName = model.LastName, Kind = model.Kind, Phone = model.Phone, - Tags = model.Tags, + Tags = producer.Tags.Select(t => t.Tag.Id), Picture = model.Picture, NotSubjectToVat = model.NotSubjectToVat }, token); @@ -132,226 +120,22 @@ public async Task Edit(ProducerViewModel model, IFormFile picture return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); - } - - [HttpGet] - public async Task CreateLegal(Guid userId, CancellationToken token) - { - var entity = await _context.Users.OfType() - .AsNoTracking() - .Where(c => c.Id == userId) - .SingleOrDefaultAsync(token); - - if (entity == null) - throw new NotFoundException(); - - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - - return View(new BusinessLegalViewModel - { - Owner = new OwnerViewModel { Id = userId }, - Name = entity.Name, - Email = entity.Email - }); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task CreateLegal(BusinessLegalViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var user = await _context.FindByIdAsync(model.Owner.Id, token); - - var result = await _mediatr.Process(new CreateBusinessLegalCommand(requestUser) - { - UserId = model.Owner.Id, - Name = model.Name, - Email = model.Email, - Address = _mapper.Map(model.Address), - Kind = model.Kind, - Owner = _mapper.Map(model.Owner), - Siret = model.Siret, - VatIdentifier = user != null && user.NotSubjectToVat ? null : model.VatIdentifier - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Created"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Owner.Id, Name = $"{model.Email}" }); - return RedirectToAction("Edit", new { id = model.Owner.Id }); - } - - [HttpGet] - public async Task CreateBankAccount(Guid userId, CancellationToken token) - { - var entity = await _context.Users.OfType() - .AsNoTracking() - .Where(c => c.Id == userId) - .SingleOrDefaultAsync(token); - - if (entity == null) - throw new NotFoundException(); - - ViewBag.Countries = await GetCountries(token); - return View(new BankAccountViewModel - { - OwnerId = entity.Id, - IsActive = true - }); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task CreateBankAccount(BankAccountViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var user = await _context.FindByIdAsync(model.OwnerId, token); - - var result = await _mediatr.Process(new CreateBankAccountCommand(requestUser) - { - UserId = user.Id, - Address = _mapper.Map(model.Address), - BIC = model.BIC, - IBAN = model.IBAN, - Name = model.Name, - Owner = model.Owner - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Created"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.OwnerId, Name = $"{model.Name}" }); - return RedirectToAction("Edit", new { id = model.OwnerId }); - } - - [HttpGet] - public async Task UpdateLegal(Guid legalId, CancellationToken token) - { - var entity = await _context.Legals.OfType() - .Where(c => c.Id == legalId) - .ProjectTo(_configurationProvider) - .SingleOrDefaultAsync(token); - - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - return View(entity); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task UpdateLegal(BusinessLegalViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var user = await _context.FindByIdAsync(model.Owner.Id, token); - var result = await _mediatr.Process(new UpdateBusinessLegalCommand(requestUser) - { - Id = model.Id, - Name = model.Name, - Email = model.Email, - Address = _mapper.Map(model.Address), - Kind = model.Kind, - Owner = _mapper.Map(model.Owner), - Siret = model.Siret, - VatIdentifier = user != null && user.NotSubjectToVat ? null : model.VatIdentifier - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Owner.Id, Name = $"{model.Email}" }); - return RedirectToAction("Edit", new { id = model.Owner.Id }); - } - - [HttpGet] - public async Task UpdateBankAccount(Guid bankAccountId, CancellationToken token) - { - var entity = await _context.BankAccounts.Get(c => c.Id == bankAccountId) - .ProjectTo(_configurationProvider) - .SingleOrDefaultAsync(token); - - ViewBag.Countries = await GetCountries(token); - return View(entity); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task UpdateBankAccount(BankAccountViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new UpdateBankAccountCommand(requestUser) - { - Id = model.Id, - Address = _mapper.Map(model.Address), - BIC = model.BIC, - IBAN = model.IBAN, - Name = model.Name, - Owner = model.Owner - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.OwnerId, Name = $"{model.Name}" }); - return RedirectToAction("Edit", new { id = model.OwnerId }); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Users.OfType().SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - var result = await _mediatr.Process(new RemoveUserCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } - - private async Task> GetCountries(CancellationToken token) - { - return await _context.Countries - .AsNoTracking() - .ProjectTo(_configurationProvider) - .ToListAsync(token); - } - - private async Task> GetNationalities(CancellationToken token) - { - return await _context.Nationalities - .AsNoTracking() - .ProjectTo(_configurationProvider) - .ToListAsync(token); - } } } diff --git a/Sheaft.Web.Manage/Controllers/ProductsController.cs b/Sheaft.Web.Manage/Controllers/ProductsController.cs index 565289808..b5fe6ee12 100644 --- a/Sheaft.Web.Manage/Controllers/ProductsController.cs +++ b/Sheaft.Web.Manage/Controllers/ProductsController.cs @@ -61,13 +61,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; @@ -215,8 +208,7 @@ public async Task Edit(ProductViewModel model, IFormFile picture, return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] @@ -243,47 +235,31 @@ public async Task Import(IEnumerable products, Cancell [HttpPost] [ValidateAntiForgeryToken] - public async Task Delete(Guid id, CancellationToken token) + public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.Products.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteProductCommand(requestUser) + var result = await _mediatr.Process(new RestoreProductCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = name; - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Restore(Guid id, CancellationToken token) + public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Products.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestoreProductCommand(requestUser) + var result = await _mediatr.Process(new DeleteProductCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } diff --git a/Sheaft.Web.Manage/Controllers/PurchaseOrdersController.cs b/Sheaft.Web.Manage/Controllers/PurchaseOrdersController.cs index bd98d04d4..01404ccf6 100644 --- a/Sheaft.Web.Manage/Controllers/PurchaseOrdersController.cs +++ b/Sheaft.Web.Manage/Controllers/PurchaseOrdersController.cs @@ -4,12 +4,10 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Core.Extensions; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -65,13 +63,6 @@ public async Task Index(CancellationToken token, PurchaseOrderSta .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; @@ -80,7 +71,7 @@ public async Task Index(CancellationToken token, PurchaseOrderSta } [HttpGet] - public async Task Details(Guid id, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var requestUser = await GetRequestUser(token); @@ -98,57 +89,31 @@ public async Task Details(Guid id, CancellationToken token) [HttpPost] [ValidateAntiForgeryToken] - public async Task Details(PurchaseOrderViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Reference }); - return RedirectToAction("Index"); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Delete(Guid id, CancellationToken token) + public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.PurchaseOrders.SingleOrDefaultAsync(c => c.Id == id, token); - var reference = entity.Reference; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeletePurchaseOrderCommand(requestUser) + var result = await _mediatr.Process(new RestorePurchaseOrderCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = reference; - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Restore(Guid id, CancellationToken token) + public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.PurchaseOrders.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Reference; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestorePurchaseOrderCommand(requestUser) + var result = await _mediatr.Process(new DeletePurchaseOrderCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } } diff --git a/Sheaft.Web.Manage/Controllers/RegionsController.cs b/Sheaft.Web.Manage/Controllers/RegionsController.cs index abdb7e64c..b4de91f0e 100644 --- a/Sheaft.Web.Manage/Controllers/RegionsController.cs +++ b/Sheaft.Web.Manage/Controllers/RegionsController.cs @@ -4,11 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -51,9 +49,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - ViewBag.Page = page; ViewBag.Take = take; @@ -80,8 +75,7 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(RegionViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new UpdateRegionCommand(requestUser) + var result = await _mediatr.Process(new UpdateRegionCommand(await GetRequestUser(token)) { Id = model.Id, Name = model.Name, @@ -94,7 +88,6 @@ public async Task Edit(RegionViewModel model, CancellationToken t return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); return RedirectToAction("Index"); } } diff --git a/Sheaft.Web.Manage/Controllers/ReturnablesController.cs b/Sheaft.Web.Manage/Controllers/ReturnablesController.cs index c99cd0700..553421fd2 100644 --- a/Sheaft.Web.Manage/Controllers/ReturnablesController.cs +++ b/Sheaft.Web.Manage/Controllers/ReturnablesController.cs @@ -57,13 +57,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; @@ -111,10 +104,6 @@ public async Task Add(ReturnableViewModel model, CancellationToke [HttpGet] public async Task Edit(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - if (!requestUser.IsImpersonating) - return RedirectToAction("Impersonate", "Account"); - var entity = await _context.Returnables .AsNoTracking() .Where(c => c.Id == id) @@ -131,14 +120,7 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(ReturnableViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - if (!requestUser.IsImpersonating) - { - ModelState.AddModelError("", "You must impersonate returnable producer to edit it."); - return View(model); - } - - var result = await _mediatr.Process(new UpdateReturnableCommand(requestUser) + var result = await _mediatr.Process(new UpdateReturnableCommand(await GetRequestUser(token)) { Id = model.Id, Description = model.Description, @@ -153,53 +135,36 @@ public async Task Edit(ReturnableViewModel model, CancellationTok return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Delete(Guid id, CancellationToken token) + public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.Returnables.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteReturnableCommand(requestUser) + var result = await _mediatr.Process(new RestoreReturnableCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = name; - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Restore(Guid id, CancellationToken token) + public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Returnables.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestoreReturnableCommand(requestUser) + var result = await _mediatr.Process(new DeleteReturnableCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } } diff --git a/Sheaft.Web.Manage/Controllers/RewardsController.cs b/Sheaft.Web.Manage/Controllers/RewardsController.cs index 2739158cc..6b62c0cbd 100644 --- a/Sheaft.Web.Manage/Controllers/RewardsController.cs +++ b/Sheaft.Web.Manage/Controllers/RewardsController.cs @@ -52,10 +52,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; @@ -67,6 +63,7 @@ public async Task Add(CancellationToken token) { ViewBag.Levels = await GetLevels(token); ViewBag.Departments = await GetDepartments(token); + return View(new RewardViewModel()); } @@ -74,9 +71,7 @@ public async Task Add(CancellationToken token) [ValidateAntiForgeryToken] public async Task Add(RewardViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - - var result = await _mediatr.Process(new CreateRewardCommand(requestUser) + var result = await _mediatr.Process(new CreateRewardCommand(await GetRequestUser(token)) { Name = model.Name, Contact = model.Contact, @@ -103,8 +98,6 @@ public async Task Add(RewardViewModel model, CancellationToken to [HttpGet] public async Task Edit(Guid id, CancellationToken token) { - var requestUser = await GetRequestUser(token); - var entity = await _context.Rewards .AsNoTracking() .Where(c => c.Id == id) @@ -123,9 +116,7 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(RewardViewModel model, CancellationToken token) { - var requestUser = await GetRequestUser(token); - - var result = await _mediatr.Process(new UpdateRewardCommand(requestUser) + var result = await _mediatr.Process(new UpdateRewardCommand(await GetRequestUser(token)) { Id = model.Id, Name = model.Name, @@ -147,53 +138,36 @@ public async Task Edit(RewardViewModel model, CancellationToken t return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Delete(Guid id, CancellationToken token) + public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.Rewards.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteRewardCommand(requestUser) + var result = await _mediatr.Process(new RestoreRewardCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = name; - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Restore(Guid id, CancellationToken token) + public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Rewards.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestoreRewardCommand(requestUser) + var result = await _mediatr.Process(new DeleteRewardCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } diff --git a/Sheaft.Web.Manage/Controllers/StoresController.cs b/Sheaft.Web.Manage/Controllers/StoresController.cs index c63328107..01c134034 100644 --- a/Sheaft.Web.Manage/Controllers/StoresController.cs +++ b/Sheaft.Web.Manage/Controllers/StoresController.cs @@ -5,16 +5,13 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Domain.Models; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; @@ -59,16 +56,8 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; - return View(entities); } @@ -83,6 +72,7 @@ public async Task Edit(Guid id, CancellationToken token) if (entity == null) throw new NotFoundException(); + ViewBag.LegalsId = (await _context.FindSingleAsync(c => c.User.Id == id, token))?.Id; ViewBag.Tags = await GetTags(token); return View(entity); } @@ -91,8 +81,6 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(StoreViewModel model, IFormFile picture, CancellationToken token) { - var requestUser = await GetRequestUser(token); - if (picture != null) { using (var ms = new MemoryStream()) @@ -101,11 +89,9 @@ public async Task Edit(StoreViewModel model, IFormFile picture, C model.Picture = Convert.ToBase64String(ms.ToArray()); } } - - var entity = await _context.Users.OfType().SingleOrDefaultAsync(c => c.Id == model.Id, token); - + var store = await _context.Users.OfType().SingleOrDefaultAsync(c => c.Id == model.Id, token); - var result = await _mediatr.Process(new UpdateStoreCommand(requestUser) + var result = await _mediatr.Process(new UpdateStoreCommand(await GetRequestUser(token)) { Id = model.Id, Address = _mapper.Map(model.Address), @@ -124,143 +110,29 @@ public async Task Edit(StoreViewModel model, IFormFile picture, C if (!result.Success) { + ViewBag.LegalsId = (await _context.FindSingleAsync(c => c.User.Id == model.Id, token))?.Id; ViewBag.Tags = await GetTags(token); ModelState.AddModelError("", result.Exception.Message); return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); - } - - [HttpGet] - public async Task CreateLegal(Guid userId, CancellationToken token) - { - var entity = await _context.Users.OfType() - .AsNoTracking() - .Where(c => c.Id == userId) - .ProjectTo(_configurationProvider) - .SingleOrDefaultAsync(token); - - if (entity == null) - throw new NotFoundException(); - - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - - return View(new BusinessLegalViewModel - { - Owner = new OwnerViewModel { Id = userId }, - Name = entity.Name, - Email = entity.Email - }); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task CreateLegal(BusinessLegalViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new CreateBusinessLegalCommand(requestUser) - { - UserId = model.Owner.Id, - Name = model.Name, - Email = model.Email, - Address = _mapper.Map(model.Address), - Kind = model.Kind, - Owner = _mapper.Map(model.Owner), - Siret = model.Siret, - VatIdentifier = model.VatIdentifier - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Created"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Owner.Id, Name = $"{model.Email}" }); - return RedirectToAction("Edit", new { id = model.Owner.Id }); - } - - [HttpGet] - public async Task UpdateLegal(Guid userId, CancellationToken token) - { - var entity = await _context.Legals.OfType() - .Where(c => c.User.Id == userId) - .ProjectTo(_configurationProvider) - .SingleOrDefaultAsync(token); - - if (entity == null) - return RedirectToAction("CreateLegal", new { userId = userId }); - - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - return View(entity); - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task UpdateLegal(BusinessLegalViewModel model, CancellationToken token) - { - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new UpdateBusinessLegalCommand(requestUser) - { - Id = model.Id, - Name = model.Name, - Email = model.Email, - Address = _mapper.Map(model.Address), - Kind = model.Kind, - Owner = _mapper.Map(model.Owner), - Siret = model.Siret, - VatIdentifier = model.VatIdentifier - }, token); - - if (!result.Success) - { - ViewBag.Countries = await GetCountries(token); - ViewBag.Nationalities = await GetNationalities(token); - ModelState.AddModelError("", result.Exception.Message); - return View(model); - } - - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Owner.Id, Name = $"{model.Email}" }); - return RedirectToAction("Edit", new { id = model.Owner.Id }); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Users.OfType().SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - var result = await _mediatr.Process(new RemoveUserCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } - - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); + throw result.Exception; + return RedirectToAction("Index"); } - - private async Task> GetCountries(CancellationToken token) - { - return await _context.Countries.AsNoTracking().ProjectTo(_configurationProvider).ToListAsync(token); - } - - private async Task> GetNationalities(CancellationToken token) - { - return await _context.Nationalities.AsNoTracking().ProjectTo(_configurationProvider).ToListAsync(token); - } } } diff --git a/Sheaft.Web.Manage/Controllers/TagsController.cs b/Sheaft.Web.Manage/Controllers/TagsController.cs index 47c3e507a..a3a0491df 100644 --- a/Sheaft.Web.Manage/Controllers/TagsController.cs +++ b/Sheaft.Web.Manage/Controllers/TagsController.cs @@ -5,11 +5,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using Sheaft.Application.Commands; using Sheaft.Exceptions; using Sheaft.Application.Interop; -using Sheaft.Web.Manage.Models; using Sheaft.Application.Models; using Sheaft.Options; using System; @@ -53,13 +51,6 @@ public async Task Index(CancellationToken token, int page = 0, in .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; @@ -76,8 +67,6 @@ public IActionResult Add() [ValidateAntiForgeryToken] public async Task Add(TagViewModel model, IFormFile picture, IFormFile icon, CancellationToken token) { - var requestUser = await GetRequestUser(token); - if (picture != null) { using (var ms = new MemoryStream()) @@ -96,7 +85,7 @@ public async Task Add(TagViewModel model, IFormFile picture, IFor } } - var result = await _mediatr.Process(new CreateTagCommand(requestUser) + var result = await _mediatr.Process(new CreateTagCommand(await GetRequestUser(token)) { Description = model.Description, Name = model.Name, @@ -134,8 +123,6 @@ public async Task Edit(Guid id, CancellationToken token) [ValidateAntiForgeryToken] public async Task Edit(TagViewModel model, IFormFile picture, IFormFile icon, CancellationToken token) { - var requestUser = await GetRequestUser(token); - if (picture != null) { using (var ms = new MemoryStream()) @@ -154,7 +141,7 @@ public async Task Edit(TagViewModel model, IFormFile picture, IFo } } - var result = await _mediatr.Process(new UpdateTagCommand(requestUser) + var result = await _mediatr.Process(new UpdateTagCommand(await GetRequestUser(token)) { Id = model.Id, Description = model.Description, @@ -171,53 +158,36 @@ public async Task Edit(TagViewModel model, IFormFile picture, IFo return View(model); } - TempData["Edited"] = JsonConvert.SerializeObject(new EntityViewModel { Id = model.Id, Name = model.Name }); - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { model.Id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Delete(Guid id, CancellationToken token) + public async Task Restore(Guid id, CancellationToken token) { - var entity = await _context.Tags.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new DeleteTagCommand(requestUser) + var result = await _mediatr.Process(new RestoreTagCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Removed"] = name; - return RedirectToAction("Index"); + return RedirectToAction("Edit", new { id }); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Restore(Guid id, CancellationToken token) + public async Task Delete(Guid id, CancellationToken token) { - var entity = await _context.Tags.SingleOrDefaultAsync(c => c.Id == id, token); - var name = entity.Name; - - var requestUser = await GetRequestUser(token); - var result = await _mediatr.Process(new RestoreTagCommand(requestUser) + var result = await _mediatr.Process(new DeleteTagCommand(await GetRequestUser(token)) { Id = id }, token); if (!result.Success) - { - ModelState.AddModelError("", result.Exception.Message); - return RedirectToAction("Index"); - } + throw result.Exception; - TempData["Restored"] = JsonConvert.SerializeObject(new EntityViewModel { Id = entity.Id, Name = name }); return RedirectToAction("Index"); } } diff --git a/Sheaft.Web.Manage/Controllers/TransfersController.cs b/Sheaft.Web.Manage/Controllers/TransfersController.cs index f69ddf15a..97e71e583 100644 --- a/Sheaft.Web.Manage/Controllers/TransfersController.cs +++ b/Sheaft.Web.Manage/Controllers/TransfersController.cs @@ -59,13 +59,6 @@ public async Task Index(CancellationToken token, TransactionStatu .ProjectTo(_configurationProvider) .ToListAsync(token); - var edited = (string)TempData["Edited"]; - ViewBag.Edited = !string.IsNullOrWhiteSpace(edited) ? JsonConvert.DeserializeObject(edited) : null; - - var restored = (string)TempData["Restored"]; - ViewBag.Restored = !string.IsNullOrWhiteSpace(restored) ? JsonConvert.DeserializeObject(restored) : null; - - ViewBag.Removed = TempData["Removed"]; ViewBag.Page = page; ViewBag.Take = take; ViewBag.Status = status; @@ -74,7 +67,7 @@ public async Task Index(CancellationToken token, TransactionStatu } [HttpGet] - public async Task Details(Guid id, CancellationToken token) + public async Task Edit(Guid id, CancellationToken token) { var entity = await _context.Transfers .AsNoTracking() diff --git a/Sheaft.Web.Manage/Controllers/UsersController.cs b/Sheaft.Web.Manage/Controllers/UsersController.cs index 43170ed5f..8c20d152c 100644 --- a/Sheaft.Web.Manage/Controllers/UsersController.cs +++ b/Sheaft.Web.Manage/Controllers/UsersController.cs @@ -55,7 +55,7 @@ public async Task Edit(Guid id, CancellationToken token) break; } - return RedirectToAction("Edit", controller, new { id = id }); + return RedirectToAction("Edit", controller, new { id }); } } } diff --git a/Sheaft.Web.Manage/Startup.cs b/Sheaft.Web.Manage/Startup.cs index 118398be7..44a7311d3 100644 --- a/Sheaft.Web.Manage/Startup.cs +++ b/Sheaft.Web.Manage/Startup.cs @@ -285,11 +285,9 @@ public void ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else + app.UseDeveloperExceptionPage(); + + if (!env.IsDevelopment()) { app.UseHttpsRedirection(); app.UseExceptionHandler("/Error"); diff --git a/Sheaft.Web.Manage/Views/Agreements/Index.cshtml b/Sheaft.Web.Manage/Views/Agreements/Index.cshtml index 795d7ec91..e35fab17a 100644 --- a/Sheaft.Web.Manage/Views/Agreements/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Agreements/Index.cshtml @@ -11,44 +11,6 @@

Agreements


- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } -
- @*
-
-
Tags
-
@ViewBag.Tags
- Show -
+
+
+
Tags
+
@ViewBag.Tags
+ Show
-
-
-
Departments
-
@ViewBag.Departments
- Show -
+
+
+
+
Departments
+
@ViewBag.Departments
+ Show
-
-
-
Regions
-
@ViewBag.Regions
- Show -
+
+
+
+
Regions
+
@ViewBag.Regions
+ Show
-
-
-
Levels
-
@ViewBag.Levels
- Show -
+
+
+
+
Declarations
+
N/A
+ Show
-
-
-
Rewards
-
@ViewBag.Rewards
- Show -
-
*@ +
} @if (!user.IsInRole("STORE") && !user.IsInRole("CONSUMER")) { @@ -159,11 +152,4 @@ Show
-
-
-
Declarations
-
- Show -
-
diff --git a/Sheaft.Web.Manage/Views/Declarations/AddUbo.cshtml b/Sheaft.Web.Manage/Views/Declarations/AddUbo.cshtml index 5f5d4fd9b..42093c192 100644 --- a/Sheaft.Web.Manage/Views/Declarations/AddUbo.cshtml +++ b/Sheaft.Web.Manage/Views/Declarations/AddUbo.cshtml @@ -67,7 +67,7 @@

- + Go back - } - + + Go back + + + } + diff --git a/Sheaft.Web.Manage/Views/Documents/Edit.cshtml b/Sheaft.Web.Manage/Views/Documents/Edit.cshtml index 009b4b191..80e8f7789 100644 --- a/Sheaft.Web.Manage/Views/Documents/Edit.cshtml +++ b/Sheaft.Web.Manage/Views/Documents/Edit.cshtml @@ -132,7 +132,7 @@ }
- + Go back @if (Model.Status == DocumentStatus.Created || Model.Status == DocumentStatus.UnLocked) diff --git a/Sheaft.Web.Manage/Views/Donations/Details.cshtml b/Sheaft.Web.Manage/Views/Donations/Edit.cshtml similarity index 94% rename from Sheaft.Web.Manage/Views/Donations/Details.cshtml rename to Sheaft.Web.Manage/Views/Donations/Edit.cshtml index 334671f54..ff58b785e 100644 --- a/Sheaft.Web.Manage/Views/Donations/Details.cshtml +++ b/Sheaft.Web.Manage/Views/Donations/Edit.cshtml @@ -55,7 +55,7 @@ @Html.TextBoxFor(m => m.Order.Status.ToString("G"), null, new { @class = "form-control", @disabled = "disabled" }) diff --git a/Sheaft.Web.Manage/Views/Donations/Index.cshtml b/Sheaft.Web.Manage/Views/Donations/Index.cshtml index ccf278c4b..993893cfc 100644 --- a/Sheaft.Web.Manage/Views/Donations/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Donations/Index.cshtml @@ -6,89 +6,76 @@ string status = ((TransactionStatus?)ViewBag.Status)?.ToString("G"); } -
-

Donations

-
+
+

Donations

+
- @if (ViewBag.Edited != null) +
+ + @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) { - -
+ } +
+
-
- - @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) + + + + + + + + + + + + + + + @foreach (var entity in Model) { - - } - -
- -
IdentifierCreatedOnCreditedToStatusExecutedOnCode +
- - - - - - - - - - - - - @foreach (var entity in Model) - { - - - - - - - - - - - } - - - - + + + + + + + - -
IdentifierCreatedOnCreditedToStatusExecutedOnCode -
@entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Credited€@entity.CreditedUser.Name@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode - - - - - - -
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } + @entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Credited€@entity.CreditedUser.Name@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode + + + + + +
-
+ } + + + + + @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } + + + + +
diff --git a/Sheaft.Web.Manage/Views/Jobs/Index.cshtml b/Sheaft.Web.Manage/Views/Jobs/Index.cshtml index 43cf7b39c..d4e45db33 100644 --- a/Sheaft.Web.Manage/Views/Jobs/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Jobs/Index.cshtml @@ -11,44 +11,6 @@

Jobs


- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } -

Address

@@ -59,8 +63,8 @@ @Html.TextBoxFor(m => m.Owner.Address.City, null, new { @class = "form-control" })
- @Html.LabelFor(m => m.Owner.CountryOfResidence) - @Html.DropDownListFor(m => m.Owner.CountryOfResidence, countries, new { @class = "form-control" }) + @Html.LabelFor(m => m.Owner.Address.Country) + @Html.DropDownListFor(m => m.Owner.Address.Country, countries, new { @class = "form-control" })
diff --git a/Sheaft.Web.Manage/Views/Producers/UpdateLegal.cshtml b/Sheaft.Web.Manage/Views/Legals/EditLegalBusiness.cshtml similarity index 94% rename from Sheaft.Web.Manage/Views/Producers/UpdateLegal.cshtml rename to Sheaft.Web.Manage/Views/Legals/EditLegalBusiness.cshtml index e79b68d1c..540b0269a 100644 --- a/Sheaft.Web.Manage/Views/Producers/UpdateLegal.cshtml +++ b/Sheaft.Web.Manage/Views/Legals/EditLegalBusiness.cshtml @@ -1,6 +1,6 @@ @model BusinessLegalViewModel @{ - ViewData["Title"] = "Producer legal details"; + ViewData["Title"] = "Edit Business Legal"; var countries = ((List)ViewBag.Countries).Select(c => new SelectListItem(c.Name, c.Alpha2)).ToList(); var nationalities = ((List)ViewBag.Nationalities).Select(c => new SelectListItem(c.Name, c.Alpha2)).ToList(); var documents = (List)ViewBag.Documents; @@ -15,10 +15,10 @@ }
-

Producer legal details

+

Edit Business Legal


- @using (Html.BeginForm("UpdateLegal", "Producers", FormMethod.Post)) + @using (Html.BeginForm("EditLegalBusiness", "Legals", FormMethod.Post)) { @Html.AntiForgeryToken() @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @@ -144,7 +144,7 @@ @Html.TextBoxFor(m => m.RemovedOn, null, new { @class = "form-control", @disabled = "disabled" })
} - + Cancel - -
- } - - @if (ViewBag.Edited != null) - { - -
- } - - - - - - - - - - - - - @foreach (var entity in Model) - { +
NumberNameRequiredPointsCreatedOn - - - -
+ + + + + + + + + + + @foreach (var entity in Model) + { @@ -80,25 +55,25 @@ } - } - - - - - - -
NumberNameRequiredPointsCreatedOn + + + +
@entity.Name @entity.RequiredPoints
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } -
- + } + + + + + @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } + + + + + diff --git a/Sheaft.Web.Manage/Views/Orders/Details.cshtml b/Sheaft.Web.Manage/Views/Orders/Edit.cshtml similarity index 94% rename from Sheaft.Web.Manage/Views/Orders/Details.cshtml rename to Sheaft.Web.Manage/Views/Orders/Edit.cshtml index fb5d1c160..2987a5f8c 100644 --- a/Sheaft.Web.Manage/Views/Orders/Details.cshtml +++ b/Sheaft.Web.Manage/Views/Orders/Edit.cshtml @@ -71,7 +71,7 @@ @Html.LabelFor(m => m.Donation.Status) @Html.TextBoxFor(m => m.Donation.Status, null, new { @class = "form-control", @disabled = "disabled" }) - + Donation details
@@ -141,7 +141,7 @@ @purchaseOrder.TotalOnSalePrice€ @purchaseOrder.Status - + diff --git a/Sheaft.Web.Manage/Views/Orders/Index.cshtml b/Sheaft.Web.Manage/Views/Orders/Index.cshtml index 92e918e5e..324a63885 100644 --- a/Sheaft.Web.Manage/Views/Orders/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Orders/Index.cshtml @@ -10,19 +10,6 @@

Orders


- @if (ViewBag.Edited != null) - { - -
- } -
diff --git a/Sheaft.Web.Manage/Views/Payins/Index.cshtml b/Sheaft.Web.Manage/Views/Payins/Index.cshtml index df2444fa0..5a0e47eb9 100644 --- a/Sheaft.Web.Manage/Views/Payins/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Payins/Index.cshtml @@ -6,86 +6,73 @@ string status = ((TransactionStatus?)ViewBag.Status)?.ToString("G"); } -
-

Payins

-
+
+

Payins

+
- @if (ViewBag.Edited != null) +
+ + @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) { - -
+ } +
+
-
- - @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) + + + + + + + + + + + + + + + @foreach (var entity in Model) { - - } - -
- -
IdentifierCreatedOnCreditedToStatusExecutedOnCode +
- - - - - - - - - - - - - @foreach (var entity in Model) - { - - - - - - - - - - - } - - - - + + + + + + + - -
IdentifierCreatedOnCreditedToStatusExecutedOnCode -
@entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Credited€@entity.CreditedUser.Name@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode - - - -
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } + @entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Credited€@entity.CreditedUser.Name@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode + + +
-
+ } + + + + + @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } + + + + +
diff --git a/Sheaft.Web.Manage/Views/Payins/Todo.cshtml b/Sheaft.Web.Manage/Views/Payins/Todo.cshtml deleted file mode 100644 index 33d5c7174..000000000 --- a/Sheaft.Web.Manage/Views/Payins/Todo.cshtml +++ /dev/null @@ -1,77 +0,0 @@ -@model IEnumerable -@{ - ViewData["Title"] = "Orders to refund"; - int take = ViewBag.Take; - int currentPage = ViewBag.Page; -} - -
-

Orders to refund

-
- - @if (ViewBag.Submitted != null) - { - -
- } - - - - - - - - - - - - - - @foreach (var entity in Model) - { - - - - - - - - - } - - - - - - -
NameCreatedOnTotalStatusPurchase Orders -
@entity.User.Name@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.TotalPrice€@entity.Status@entity.PurchaseOrders.Count() - - - - @using (Html.BeginForm("CreatePayinRefund", "Payins", new { id = entity.Id }, FormMethod.Post, true, new { @class = "form d-inline" })) - { - - } -
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } -
-
diff --git a/Sheaft.Web.Manage/Views/Payouts/Details.cshtml b/Sheaft.Web.Manage/Views/Payouts/Edit.cshtml similarity index 94% rename from Sheaft.Web.Manage/Views/Payouts/Details.cshtml rename to Sheaft.Web.Manage/Views/Payouts/Edit.cshtml index 976da89a0..80fd9f81d 100644 --- a/Sheaft.Web.Manage/Views/Payouts/Details.cshtml +++ b/Sheaft.Web.Manage/Views/Payouts/Edit.cshtml @@ -82,10 +82,10 @@ @transfer.PurchaseOrder.TotalOnSalePrice€ @transfer.PurchaseOrder.Status - + - + diff --git a/Sheaft.Web.Manage/Views/Payouts/Index.cshtml b/Sheaft.Web.Manage/Views/Payouts/Index.cshtml index ce318c0ff..e44a2060f 100644 --- a/Sheaft.Web.Manage/Views/Payouts/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Payouts/Index.cshtml @@ -6,89 +6,76 @@ string status = ((TransactionStatus?)ViewBag.Status)?.ToString("G"); } -
-

Payouts

-
+
+

Payouts

+
- @if (ViewBag.Edited != null) +
+ + @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) { - -
+ } +
+
-
- - @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) + + + + + + + + + + + + + + + + @foreach (var entity in Model) { - - } - -
- -
IdentifierCreatedOnDebitedFromCreditedToExecutedOnCode +
- - - - - - - - - - - - - - @foreach (var entity in Model) - { - - - - - - - - - - - - - } - - - - + + + + + + + + + - -
IdentifierCreatedOnDebitedFromCreditedToExecutedOnCode -
@entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Debited€@entity.DebitedUser.Name@entity.Credited€@entity.BankAccount.Owner@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode - - - -
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } + @entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Debited€@entity.DebitedUser.Name@entity.Credited€@entity.BankAccount.Owner@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode + + +
-
+ } + + + + + @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } + + + + +
diff --git a/Sheaft.Web.Manage/Views/Payouts/Todo.cshtml b/Sheaft.Web.Manage/Views/Payouts/Todo.cshtml deleted file mode 100644 index 204dc9c68..000000000 --- a/Sheaft.Web.Manage/Views/Payouts/Todo.cshtml +++ /dev/null @@ -1,76 +0,0 @@ -@model IEnumerable -@{ - ViewData["Title"] = "Producers payouts"; - int take = ViewBag.Take; - int currentPage = ViewBag.Page; -} - -
-

Producers payouts

-
- - @if (ViewBag.Submitted != null) - { - -
- } - - - - - - - - - - - - - @foreach (var entity in Model) - { - @using (Html.BeginForm("CreatePayout", "Payouts", new { id = entity.Id }, FormMethod.Post, true, new { @class = "form d-inline" })) - { - - - - - - - - } - } - - - - - - -
NameEmailTotalTransfers -
@entity.Name@entity.Email@entity.Total€@entity.Transfers.Count() - - - - - -
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } -
-
diff --git a/Sheaft.Web.Manage/Views/Producers/Edit.cshtml b/Sheaft.Web.Manage/Views/Producers/Edit.cshtml index 52329ee16..a21bbc5bd 100644 --- a/Sheaft.Web.Manage/Views/Producers/Edit.cshtml +++ b/Sheaft.Web.Manage/Views/Producers/Edit.cshtml @@ -105,13 +105,13 @@

Legals

@if (ViewBag.LegalsId != null) { - + Legals details } else { - + Create Legals } @@ -120,13 +120,13 @@

BankAccount

@if (ViewBag.BankAccountId != null) { - + Bank Account details } else { - + Create Bank Account } diff --git a/Sheaft.Web.Manage/Views/Producers/Index.cshtml b/Sheaft.Web.Manage/Views/Producers/Index.cshtml index 3c8c7ac8d..8cd9f6a87 100644 --- a/Sheaft.Web.Manage/Views/Producers/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Producers/Index.cshtml @@ -9,44 +9,6 @@

Producers


- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } - diff --git a/Sheaft.Web.Manage/Views/Products/Index.cshtml b/Sheaft.Web.Manage/Views/Products/Index.cshtml index 7e9643e84..c01dd1f86 100644 --- a/Sheaft.Web.Manage/Views/Products/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Products/Index.cshtml @@ -9,44 +9,6 @@

Products

- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } - @if (Context.Request.ImpersonificationId().HasValue) { Download sample products catalog diff --git a/Sheaft.Web.Manage/Views/PurchaseOrders/Details.cshtml b/Sheaft.Web.Manage/Views/PurchaseOrders/Edit.cshtml similarity index 96% rename from Sheaft.Web.Manage/Views/PurchaseOrders/Details.cshtml rename to Sheaft.Web.Manage/Views/PurchaseOrders/Edit.cshtml index 23b365076..91a796006 100644 --- a/Sheaft.Web.Manage/Views/PurchaseOrders/Details.cshtml +++ b/Sheaft.Web.Manage/Views/PurchaseOrders/Edit.cshtml @@ -123,7 +123,7 @@ @Html.TextAreaFor(c => c.Transfer.Status.ToString("G"), new { @class = "form-control", @disabled = "disabled" })

- + User details } diff --git a/Sheaft.Web.Manage/Views/PurchaseOrders/Index.cshtml b/Sheaft.Web.Manage/Views/PurchaseOrders/Index.cshtml index 2d59b48e7..c2bc92628 100644 --- a/Sheaft.Web.Manage/Views/PurchaseOrders/Index.cshtml +++ b/Sheaft.Web.Manage/Views/PurchaseOrders/Index.cshtml @@ -11,44 +11,6 @@

Purchase Orders


- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } -
+ + + + +
- + diff --git a/Sheaft.Web.Manage/Views/Regions/Index.cshtml b/Sheaft.Web.Manage/Views/Regions/Index.cshtml index 5f8eb9ff9..b5f670841 100644 --- a/Sheaft.Web.Manage/Views/Regions/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Regions/Index.cshtml @@ -5,40 +5,26 @@ int currentPage = ViewBag.Page; } -
-

Regions

-
+
+

Regions

+
- - @if (ViewBag.Edited != null) - { - -
- } - - - - - - - - - - - - - - - - @foreach (var entity in Model) - { +
NamePositionPointsRequiredProducersProducersStoresConsumers
+ + + + + + + + + + + + + + @foreach (var entity in Model) + { @@ -53,25 +39,25 @@ - } - - - - - - -
NamePositionPointsRequiredProducersProducersStoresConsumers
@entity.Name @entity.Position
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } -
-
+ } + +
+ @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } +
+
diff --git a/Sheaft.Web.Manage/Views/Returnables/Index.cshtml b/Sheaft.Web.Manage/Views/Returnables/Index.cshtml index 442468f71..7fe9d2b67 100644 --- a/Sheaft.Web.Manage/Views/Returnables/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Returnables/Index.cshtml @@ -10,44 +10,6 @@

Returnables


- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } - diff --git a/Sheaft.Web.Manage/Views/Rewards/Index.cshtml b/Sheaft.Web.Manage/Views/Rewards/Index.cshtml index cc01bc128..a7841259f 100644 --- a/Sheaft.Web.Manage/Views/Rewards/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Rewards/Index.cshtml @@ -5,50 +5,25 @@ int currentPage = ViewBag.Page; } -
-

Rewards

-
+
+

Rewards

+
- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } - -
- - - - - - - - - @foreach (var entity in Model) - { +
NameCreatedOn - - - -
+ + + + + + + + + @foreach (var entity in Model) + { @@ -77,25 +52,25 @@ } - } - - - - - - -
NameCreatedOn + + + +
@entity.Name @entity.CreatedOn.ToString("dd/MM/yy hh:mm")
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } -
-
+ } + + + + + @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } + + + + + diff --git a/Sheaft.Web.Manage/Views/Stores/Edit.cshtml b/Sheaft.Web.Manage/Views/Stores/Edit.cshtml index 8b8e34fe8..20c044dc5 100644 --- a/Sheaft.Web.Manage/Views/Stores/Edit.cshtml +++ b/Sheaft.Web.Manage/Views/Stores/Edit.cshtml @@ -104,7 +104,21 @@ - +
+

Legals

+ @if (ViewBag.LegalsId != null) + { + + Legals details + + } + else + { + + Create Legals + + } +

Cancel diff --git a/Sheaft.Web.Manage/Views/Stores/Index.cshtml b/Sheaft.Web.Manage/Views/Stores/Index.cshtml index 1a5d685e2..fd9e4343b 100644 --- a/Sheaft.Web.Manage/Views/Stores/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Stores/Index.cshtml @@ -9,44 +9,6 @@

Stores


- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { -
-
- } - - @if (ViewBag.Edited != null) - { - -
- } - diff --git a/Sheaft.Web.Manage/Views/Tags/Index.cshtml b/Sheaft.Web.Manage/Views/Tags/Index.cshtml index 023b9ed94..ef3420f89 100644 --- a/Sheaft.Web.Manage/Views/Tags/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Tags/Index.cshtml @@ -5,66 +5,28 @@ int currentPage = ViewBag.Page; } -
-

Tags

-
+
+

Tags

+
- @if (ViewBag.Removed != null) - { - -
- } - - @if (ViewBag.Restored != null) - { - -
- } - - @if (ViewBag.Edited != null) - { - -
- } - -
- - - - - - - - - - - - @foreach (var entity in Model) - { +
NameKindCreatedOnAvailableRemoved - - - -
+ + + + + + + + + + + + @foreach (var entity in Model) + { @@ -96,25 +58,25 @@ } - } - - - - - - -
NameKindCreatedOnAvailableRemoved + + + +
@entity.Name @entity.Kind
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } -
- + } + + + + + @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } + + + + + diff --git a/Sheaft.Web.Manage/Views/Transfers/Details.cshtml b/Sheaft.Web.Manage/Views/Transfers/Edit.cshtml similarity index 94% rename from Sheaft.Web.Manage/Views/Transfers/Details.cshtml rename to Sheaft.Web.Manage/Views/Transfers/Edit.cshtml index 99d981f9c..dcdf38bf4 100644 --- a/Sheaft.Web.Manage/Views/Transfers/Details.cshtml +++ b/Sheaft.Web.Manage/Views/Transfers/Edit.cshtml @@ -69,7 +69,7 @@

Purchase Order

diff --git a/Sheaft.Web.Manage/Views/Transfers/Index.cshtml b/Sheaft.Web.Manage/Views/Transfers/Index.cshtml index 233e03fbc..565158dc2 100644 --- a/Sheaft.Web.Manage/Views/Transfers/Index.cshtml +++ b/Sheaft.Web.Manage/Views/Transfers/Index.cshtml @@ -6,90 +6,77 @@ string status = ((TransactionStatus?)ViewBag.Status)?.ToString("G"); } -
-

Transfers

-
+
+

Transfers

+
- @if (ViewBag.Edited != null) +
+ + @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) { - -
+ } +
+
-
- - @foreach (var existingStatus in Enum.GetNames(typeof(TransactionStatus))) + + + + + + + + + + + + + + + + + @foreach (var entity in Model) { - - } - -
- -
IdentifierCreatedOnDebitedFromCreditedToStatusExecutedOnCode +
- - - - - - - - - - - - - - - @foreach (var entity in Model) - { - - - - - - - - - - - - - } - - - - + + + + + + + + + - -
IdentifierCreatedOnDebitedFromCreditedToStatusExecutedOnCode -
@entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Debited€@entity.DebitedUser.Name@entity.Credited€@entity.CreditedUser.Name@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode - - - -
- @if (currentPage >= 1) - { - - - - } - @if (take == Model.Count()) - { - - - - } + @entity.Identifier@entity.CreatedOn.ToString("dd/MM/yy hh:mm")@entity.Debited€@entity.DebitedUser.Name@entity.Credited€@entity.CreditedUser.Name@entity.Status.ToString("G")@entity.ExecutedOn?.ToString("dd/MM/yy hh:mm")@entity.ResultCode + + +
-
+ } + + + + + @if (currentPage >= 1) + { + + + + } + @if (take == Model.Count()) + { + + + + } + + + + +