Пример #1
0
        public async Task <UpdateContactUpdated> Handle(UpdateContactCommand request, CancellationToken cancellationToken)
        {
            if (!db.Contacts.Where(c => c.Id == request.Id).Any())
            {
                throw new NotFoundException(nameof(Contact), request.Id);
            }

            var ent = db.Contacts.Where(c => c.Id == request.Id).FirstOrDefault();

            ent.Name            = request.Name;
            ent.PhoneNumber     = request.PhoneNumber;
            ent.Email           = request.Email;
            ent.ClientId        = request.ClientId;
            ent.RecibeLicencias = request.RecibeLicencias;
            ent.LicenseId       = request.LicenseId;

            db.Contacts.Update(ent);

            await db.SaveChangesAsync();

            return(new UpdateContactUpdated()
            {
                Id = ent.Id, Email = ent.Email, Name = ent.Name, PhoneNumber = ent.PhoneNumber
            });
        }
        public async Task <CreateContactCreated> Handle(CreateContactCommand request, CancellationToken cancellationToken)
        {
            if (!db.Clients.Where(c => c.Id == request.ClientId).Any())
            {
                throw new NotFoundException(nameof(Client), request.ClientId);
            }

            var ent = new Contact()
            {
                Id              = Guid.NewGuid(),
                Name            = request.Name,
                Email           = request.Email,
                PhoneNumber     = request.PhoneNumber,
                ClientId        = request.ClientId,
                RecibeLicencias = request.RecibeLicencias,
                LicenseId       = request.LicenseId
            };

            db.Contacts.Add(ent);
            await db.SaveChangesAsync(cancellationToken);

            return(new CreateContactCreated()
            {
                Id = ent.Id, Email = ent.Email, Name = ent.Name, PhoneNumber = ent.PhoneNumber
            });
        }
        public async Task <CreateClientCreated> Handle(CreateClientCommand request, CancellationToken cancellationToken)
        {
            if (db.Clients.Where(c => c.Code == request.Code).Any())
            {
                throw new CodeUsedException(nameof(Client), request.Code);
            }

            var ent = new Client()
            {
                Id                    = Guid.NewGuid(),
                Code                  = request.Code,
                Description           = request.Description,
                Discontinued          = false,
                AssetsCode            = request.AssetsCode,
                LicenseClasifications = { new LicenseClientClasification()
                                          {
                                              Id = Guid.NewGuid(), Code = "All", Name = "Todas las Licencias del Cliente"
                                          } }
            };

            db.Clients.Add(ent);

            await db.SaveChangesAsync(cancellationToken);

            return(new CreateClientCreated()
            {
                Id = ent.Id, Code = ent.Code, Description = ent.Description
            });
        }
        public async Task <ContractDto> Handle(CreateContractCommand request, CancellationToken cancellationToken)
        {
            if (db.Contracts.Where(c => c.Numero == request.Numero).Any())
            {
                throw new CodeUsedException(nameof(Contract), request.Numero);
            }

            var contrato = new Contract()
            {
                Id                  = Guid.NewGuid(),
                ClientId            = request.ClientId,
                Discontinued        = false,
                FechaEntrega        = request.FechaEntrega,
                FechaFirma          = request.FechaFirma,
                FechaRecibido       = request.FechaRecibido,
                IdInstalador        = request.IdInstalador,
                ImporteLicenciasCUC = request.ImporteLicenciasCUC,
                ImporteLicenciasMN  = request.ImporteLicenciasMN,
                ImportePostVentaCUC = request.ImportePostVentaCUC,
                ImportePostVentaMN  = request.ImportePostVentaMN,
                Master              = request.Master,
                InicioPostVenta     = request.InicioPostVenta,
                FinalPostVenta      = request.FinalPostVenta,
                Numero              = request.Numero,
                NumeroSuplement     = request.NumeroSuplement,
                Objeto              = request.Objeto,
                Suplemento          = request.Suplemento,
                Ubicacion           = request.Ubicacion
            };

            db.Contracts.Add(contrato);
            await db.SaveChangesAsync(cancellationToken);

            return(mapper.Map <ContractDto>(contrato));
        }
        public async Task <UpdateClientUpdated> Handle(UpdateClientCommand request, CancellationToken cancellationToken)
        {
            var ent = await db.Clients.FindAsync(request.Id);

            if (ent == null)
            {
                throw new NotFoundException(nameof(Client), request.Id);
            }

            if (db.Clients.Where(c => c.Id != request.Id && c.Code == request.Code).Any())
            {
                throw new CodeUsedException(nameof(Client), request.Code);
            }

            ent.Code        = request.Code;
            ent.Description = request.Description;
            ent.AssetsCode  = request.AssetsCode;

            db.Clients.Update(ent);

            await db.SaveChangesAsync();

            return(new UpdateClientUpdated()
            {
                Id = ent.Id, Code = ent.Code, Description = ent.Description
            });
        }
Пример #6
0
        public async Task <ContractDto> Handle(UpdateContractCommand request, CancellationToken cancellationToken)
        {
            var contract = db.Contracts.Find(request.Id);

            if (contract == null)
            {
                throw new NotFoundException(nameof(Contract), request.Id);
            }


            contract.Discontinued        = false;
            contract.FechaEntrega        = request.FechaEntrega;
            contract.FechaFirma          = request.FechaFirma;
            contract.FechaRecibido       = request.FechaRecibido;
            contract.IdInstalador        = request.IdInstalador;
            contract.ImporteLicenciasCUC = request.ImporteLicenciasCUC;
            contract.ImporteLicenciasMN  = request.ImporteLicenciasMN;
            contract.ImportePostVentaCUC = request.ImportePostVentaCUC;
            contract.ImportePostVentaMN  = request.ImportePostVentaMN;
            contract.Master          = request.Master;
            contract.InicioPostVenta = request.InicioPostVenta;
            contract.FinalPostVenta  = request.FinalPostVenta;
            contract.Numero          = request.Numero;
            contract.NumeroSuplement = request.NumeroSuplement;
            contract.Objeto          = request.Objeto;
            contract.Suplemento      = request.Suplemento;
            contract.Ubicacion       = request.Ubicacion;

            db.Contracts.Update(contract);

            await db.SaveChangesAsync(cancellationToken);

            return(mapper.Map <ContractDto>(contract));
        }
        public async Task <CreateStockTypeCreated> Handle(CreateStockTypeCommand request, CancellationToken cancellationToken)
        {
            var ent = new StockType()
            {
                Id = Guid.NewGuid(), Description = request.Description, WorkStations = request.WorkStations
            };

            await db.StockTypes.AddAsync(ent, cancellationToken);

            await db.SaveChangesAsync(cancellationToken);

            return(mapper.Map <CreateStockTypeCreated>(ent));
        }
Пример #8
0
        public async Task <Unit> Handle(DeleteContractCommand request, CancellationToken cancellationToken)
        {
            var contract = db.Contracts.Find(request.Id);

            if (contract == null)
            {
                throw new NotFoundException(nameof(Contract), request.Id);
            }

            db.Contracts.Remove(contract);
            await db.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Пример #9
0
        public async Task <Unit> Handle(DeleteAssetsVersionCommand request, CancellationToken cancellationToken)
        {
            var ent = await db.AssetsVersions.FindAsync(request.Id);

            if (ent == null)
            {
                throw new NotFoundException(nameof(AssetsVersion), request.Id);
            }

            db.Remove(ent);
            await db.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteStockTypeCommand request, CancellationToken cancellationToken)
        {
            var ent = await db.StockTypes.FindAsync(request.Id);

            if (ent == null)
            {
                throw new NotFoundException(nameof(StockType), request.Id);
            }

            db.StockTypes.Remove(ent);

            await db.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DescontinueClientCommand request, CancellationToken cancellationToken)
        {
            if (!db.Clients.Where(c => c.Id == request.Id).Any())
            {
                throw new NotFoundException(nameof(Client), request.Id);
            }

            var ent = db.Clients.Where(c => c.Id == request.Id).FirstOrDefault();

            ent.Discontinued = true;

            await db.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteContactCommand request, CancellationToken cancellationToken)
        {
            if (!db.Contacts.Where(c => c.Id == request.Id).Any())
            {
                throw new NotFoundException(nameof(Contact), request.Id);
            }

            var ent = db.Contacts.Where(c => c.Id == request.Id).FirstOrDefault();

            db.Contacts.Remove(ent);

            await db.SaveChangesAsync();

            return(Unit.Value);
        }
Пример #13
0
        public async Task <Unit> Handle(DiscontinueLincenseCommand request, CancellationToken cancellationToken)
        {
            if (!db.Licenses.Where(c => c.Id == request.Id).Any())
            {
                throw new NotFoundException(nameof(License), request.Id);
            }

            var ent = db.Licenses.Where(c => c.Id == request.Id).FirstOrDefault();

            ent.Descontinued = true;
            db.Licenses.Update(ent);

            await db.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <UpdateConfigurationDto> Handle(UpdateConfigurationCommand request, CancellationToken cancellationToken)
        {
            var configuration = db.Configuration.First();

            if (configuration == null)
            {
                configuration = new clientsControl.Domain.Entities.Configuration()
                {
                    Id = Guid.NewGuid(),
                    ClientConsecutive           = request.ClientConsecutive,
                    GeneratedPaymentControlPath = request.GeneratedPaymentControlPath,
                    LicenceConsecutive          = request.LicenceConsecutive,
                    SmtpPassword = request.SmtpPassword,
                    SmtpPort     = request.SmtpPort,
                    SmtpServer   = request.SmtpServer,
                    StmpUser     = request.StmpUser
                };

                await db.Configuration.AddAsync(configuration, cancellationToken);
            }
            else
            {
                configuration.ClientConsecutive           = request.ClientConsecutive;
                configuration.GeneratedPaymentControlPath = request.GeneratedPaymentControlPath;
                configuration.LicenceConsecutive          = request.LicenceConsecutive;
                configuration.SmtpPassword = request.SmtpPassword;
                configuration.SmtpPort     = request.SmtpPort;
                configuration.SmtpServer   = request.SmtpServer;
                configuration.StmpUser     = request.StmpUser;

                db.Configuration.Update(configuration);
            }

            await db.SaveChangesAsync(cancellationToken);

            return(new UpdateConfigurationDto()
            {
                Id = configuration.Id,
                ClientConsecutive = configuration.ClientConsecutive,
                GeneratedPaymentControlPath = configuration.GeneratedPaymentControlPath,
                LicenceConsecutive = configuration.LicenceConsecutive,
                SmtpPassword = configuration.SmtpPassword,
                SmtpPort = configuration.SmtpPort,
                SmtpServer = configuration.SmtpServer,
                StmpUser = configuration.StmpUser
            });
        }
        public async Task <UpdateStockTypeUpdated> Handle(UpdateStockTypeCommand request, CancellationToken cancellationToken)
        {
            var ent = await db.StockTypes.FindAsync(request.Id);

            if (ent == null)
            {
                throw new NotFoundException(nameof(StockType), request.Id);
            }

            ent.Description  = request.Description;
            ent.WorkStations = request.WorkStations;

            db.StockTypes.Update(ent);

            await db.SaveChangesAsync(cancellationToken);

            return(mapper.Map <UpdateStockTypeUpdated>(ent));
        }
Пример #16
0
        public async Task <CreatePaymentControlCreated> Handle(CreatePaymentControlCommand request, CancellationToken cancellationToken)
        {
            var license = await db.Licenses.FindAsync(request.LicenceId);

            if (license == null)
            {
                throw new NotFoundException(nameof(License), request.LicenceId);
            }

            var client = await db.Clients.FindAsync(license.ClientId);

            if (client == null)
            {
                throw new NotFoundException(nameof(Client), request.LicenceId);
            }

            var configuration = db.Configuration.FirstOrDefault();

            if (configuration == null)
            {
                throw new NotFoundException(nameof(Configuration), Guid.Empty);
            }

            string location = paymentTool.generatePaymentControl(client.Description, license.Name, request.ExpirationDate, configuration.GeneratedPaymentControlPath);

            var ent = new PaymentControl()
            {
                Id              = Guid.NewGuid(),
                GeneratedDate   = DateTime.Now,
                ExpirationDate  = request.ExpirationDate,
                LicenceId       = request.LicenceId,
                Localization    = location,
                Public          = request.Public,
                SendByEmail     = request.SendByEmail,
                SentByEmail     = false,
                SentByEmailDate = DateTime.Now
            };

            await db.PaymentControls.AddAsync(ent);

            await db.SaveChangesAsync();

            return(mapper.Map <CreatePaymentControlCreated>(ent));
        }
Пример #17
0
        public async Task <UpdateModuleUpdated> Handle(UpdateModuleCommand request, CancellationToken cancellationToken)
        {
            var ent = await db.Module.FindAsync(request.Id);

            if (ent == null)
            {
                throw new NotFoundException(nameof(Module), request.Id);
            }

            ent.Description  = request.Description;
            ent.WorkStations = request.WorkStations;

            await db.SaveChangesAsync(cancellationToken);

            return(new UpdateModuleUpdated()
            {
                Id = ent.Id, Description = ent.Description, WorkStations = ent.WorkStations
            });
        }
Пример #18
0
        public async Task <UpdateAssetsVersionUpdated> Handle(UpdateAssetsVersionCommand request, CancellationToken cancellationToken)
        {
            var ent = await db.AssetsVersions.FindAsync(request.Id);

            if (ent == null)
            {
                throw new NotFoundException(nameof(AssetsVersion), request.Id);
            }

            ent.Description = request.Description;

            db.AssetsVersions.Update(ent);

            await db.SaveChangesAsync(cancellationToken);

            return(new UpdateAssetsVersionUpdated()
            {
                Id = ent.Id, Description = ent.Description
            });
        }
Пример #19
0
        public async Task <CreateModuleCreated> Handle(CreateModuleCommand request, CancellationToken cancellationToken)
        {
            if (db.Module.Where(c => c.Description == request.Description).Any())
            {
                throw new DescriptionUsedException(nameof(Module), request.Description);
            }

            var ent = new Module()
            {
                Id = Guid.NewGuid(), Description = request.Description, WorkStations = request.WorkStations
            };

            db.Module.Add(ent);
            await db.SaveChangesAsync();

            return(new CreateModuleCreated()
            {
                Id = ent.Id, Description = ent.Description, WorkStations = ent.WorkStations
            });
        }
        public async Task <CreateAssetsVersionCreated> Handle(CreateAssetsVersionCommand request, CancellationToken cancellationToken)
        {
            if (db.AssetsVersions.Where(c => c.Description == request.Description).Any())
            {
                throw new CodeUsedException(nameof(AssetsVersions), request.Description);
            }

            var ent = new AssetsVersion()
            {
                Id = Guid.NewGuid(), Description = request.Description
            };

            db.AssetsVersions.Add(ent);

            await db.SaveChangesAsync();

            return(new CreateAssetsVersionCreated()
            {
                Id = ent.Id, Description = ent.Description
            });
        }
Пример #21
0
        public async Task <UpdateLicenseUpdated> Handle(UpdateLicenseCommand request, CancellationToken cancellationToken)
        {
            if (!db.Licenses.Where(c => c.Id == request.Id).Any())
            {
                throw new NotFoundException(nameof(License), request.Id);
            }

            if (!db.Clients.Where(c => c.Id == request.ClientId).Any())
            {
                throw new NotFoundException(nameof(Client), request.ClientId);
            }

            if (!db.StockTypes.Where(c => c.Id == request.StockTypeId).Any())
            {
                throw new NotFoundException(nameof(StockType), request.StockTypeId);
            }

            if (!db.AssetsVersions.Where(c => c.Id == request.VersionId).Any())
            {
                throw new NotFoundException(nameof(AssetsVersion), request.VersionId);
            }

            if (!db.LicenseClientClasification.Where(c => c.ClientId == request.ClasificationId).Any())
            {
                throw new NotFoundException(nameof(LicenseClientsClasifications), request.ClasificationId);
            }

            var ent = db.Licenses.Where(c => c.Id == request.Id).FirstOrDefault();

            bool changeName = request.Name != ent.Name || request.REUP != ent.REUP;

            ent.ClientId        = request.ClientId;
            ent.Code            = request.Code;
            ent.CreationDate    = request.CreationDate;
            ent.Descontinued    = request.Descontinued;
            ent.Name            = request.Name;
            ent.REUP            = request.REUP;
            ent.StockTypeId     = request.StockTypeId;
            ent.VersionId       = request.VersionId;
            ent.ClasificationId = request.ClasificationId;

            db.Licenses.Update(ent);

            if (changeName)
            {
                db.LicenseNames.Add(new LicenseName()
                {
                    Id = Guid.NewGuid(), Date = DateTime.Now, LicenseId = ent.Id, Name = request.Name, REUP = request.REUP
                });
            }

            await db.SaveChangesAsync();

            return(new UpdateLicenseUpdated()
            {
                Id = ent.Id,
                ClientId = ent.ClientId,
                Code = ent.Code,
                CreationDate = ent.CreationDate,
                Descontinued = ent.Descontinued,
                Name = ent.Name,
                REUP = ent.REUP,
                StockTypeId = ent.StockTypeId,
                VersionId = ent.VersionId
            });
        }
Пример #22
0
        public async Task <CreateLicenseCreated> Handle(CreateLicenseCommand request, CancellationToken cancellationToken)
        {
            if (!db.Clients.Where(c => c.Id == request.ClientId).Any())
            {
                throw new NotFoundException(nameof(Client), request.ClientId);
            }

            if (!db.StockTypes.Where(c => c.Id == request.StockTypeId).Any())
            {
                throw new NotFoundException(nameof(StockType), request.StockTypeId);
            }

            if (!db.AssetsVersions.Where(c => c.Id == request.VersionId).Any())
            {
                throw new NotFoundException(nameof(AssetsVersion), request.VersionId);
            }

            if (!db.LicenseClientClasification.Where(c => c.ClientId == request.ClientId && c.Code == "All").Any())
            {
                throw new NotFoundException(nameof(LicenseClientsClasifications), "All");
            }

            var licenseClientAllClasification = db.LicenseClientClasification.Where(c => c.ClientId == request.ClientId && c.Code == "All").FirstOrDefault();

            var ent = new License()
            {
                Id              = Guid.NewGuid(),
                REUP            = request.REUP,
                ClasificationId = licenseClientAllClasification.Id,
                ClientId        = request.ClientId,
                Code            = request.Code,
                CreationDate    = request.CreationDate,
                Descontinued    = false,
                Name            = request.Name,
                StockTypeId     = request.StockTypeId,
                VersionId       = request.VersionId,
                LicenseNames    = new List <LicenseName>()
                {
                    new LicenseName()
                    {
                        Id = Guid.NewGuid(), Date = request.CreationDate, Name = request.Name, REUP = request.REUP
                    }
                },
                //LicenseDetails = mapper.ProjectTo<LicenseDetail>(request.LicenseDetails.AsQueryable<LicenseDetailDto>())
            };

            // buscar como hacer esto mejor

            foreach (var detail in request.LicenseDetails)
            {
                ent.LicenseDetails.Add(new LicenseDetail()
                {
                    ModuleId = detail.ModuleId, Licencias = detail.Licencias, PcAdicionales = detail.PcAdicionales, PcConsultas = detail.PcConsultas
                });
            }



            db.Licenses.Add(ent);
            await db.SaveChangesAsync(cancellationToken);

            return(new CreateLicenseCreated()
            {
                Id = ent.Id,
                ClientId = ent.ClientId,
                Code = ent.Code,
                CreationDate = ent.CreationDate,
                Descontinued = ent.Descontinued,
                Name = ent.Name,
                REUP = ent.REUP,
                StockTypeId = ent.StockTypeId,
                VersionId = ent.VersionId
            });
        }