public async Task<ActionResult<LicenceDto>> Put(int id, LicenceDto licenceDto)
 {
     if (licenceDto == null) return BadRequest("Keine Lizenz zum Updaten");
     if (id <= 0 || licenceDto.UserId <= 0 || licenceDto.CreatorId <= 0) return BadRequest("Id Fehler");
     var updateLicence = await _licenceRepository.UpdateLicenceAsync(licenceDto);
     if (updateLicence == null) return BadRequest("Fehler beim aktualisieren");
     return Ok(updateLicence);
 }
        public async Task<ActionResult<LicenceDto>> Post(LicenceDto licenceDto)
        {
            if (licenceDto == null) return BadRequest("Keine Lizenz zum einfügen");
            if (licenceDto.UserId <= 0 || licenceDto.CreatorId <= 0) return BadRequest("User oder Creator Fehler");

            var newLicence = await _licenceRepository.InsertLicenceAsync(licenceDto);
            if (newLicence == null) return BadRequest("Lizenz konnte nicht hinzugefügt werden");
            return Ok(newLicence);
        }
        public async Task <LicenceDto> UpdateLicenceAsync(LicenceDto licenceDto)
        {
            var licenceToUpdate = await _context.Licences.FindAsync(licenceDto.LicenceId);

            licenceToUpdate.CreatorId = licenceDto.CreatorId;
            licenceToUpdate.UserId    = licenceDto.UserId;
            licenceToUpdate.Paid      = licenceDto.Paid;
            licenceToUpdate.StartDate = new DateTime(licenceDto.StartDate.Year, licenceDto.StartDate.Month,
                                                     licenceDto.StartDate.Day, 0, 0, 0).AddDays(1);
            licenceToUpdate.EndDate = new DateTime(licenceDto.EndDate.Year, licenceDto.EndDate.Month,
                                                   licenceDto.EndDate.Day, 23, 59, 59);
            licenceToUpdate.LicenseName = licenceDto.LicenceName;
            licenceToUpdate.Year        = licenceDto.Year;

            var user = await _context.Users
                       .Select(u => new
            {
                u.FirstName,
                u.LastName,
                UserId = u.Id
            })
                       .AsNoTracking()
                       .FirstOrDefaultAsync(u => u.UserId == licenceDto.UserId);

            var statistic = await _context.Statistics
                            .FirstOrDefaultAsync(s => s.LicenceId == licenceDto.LicenceId);

            statistic.UserId = licenceDto.UserId;
            statistic.Year   = licenceDto.EndDate.Year;

            var xml = new XmlDocument();

            xml.LoadXml(statistic.StatisticXml);

            var nodeFirstName = xml.SelectSingleNode("Statistik/Vorname");
            var nodeLastName  = xml.SelectSingleNode("Statistik/Nachname");
            var nodeYear      = xml.SelectSingleNode("Statistik/Jahr");

            if (nodeFirstName == null || nodeLastName == null || nodeYear == null)
            {
                _logger.InsertDatabaseLog(new DataBaseLog
                {
                    Type    = "XML Error StatisticRepository",
                    Message = "Fehler beim Zugriff auf XML Node"
                });
                return(null);
            }

            nodeFirstName.InnerText = user.FirstName;
            nodeLastName.InnerText  = user.LastName;
            nodeYear.InnerText      = licenceDto.StartDate.Year.ToString();
            statistic.StatisticXml  = xml.OuterXml;

            var checkUpdate = await Complete();

            return(checkUpdate ? licenceDto : null);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            if (args.Any(a => a == "--generate"))
            {
                GenerateNewKeyPair();
            }
            var dto = new LicenceDto()
            {
                ValidUntil = DateTime.Now.AddDays(7)
            };
            var fileName = string.Join("", DateTime.Now.ToString().Where(c => char.IsDigit(c)));

            new LicenceGenerator().CreateLicenseFile(dto, fileName + ".po_licence");
        }
Esempio n. 5
0
        public void CreateLicenseFile(LicenceDto dto, string fileName)

        {
            var ms = new MemoryStream();

            new XmlSerializer(typeof(LicenceDto)).Serialize(ms, dto);



            // Create a new CspParameters object to specify

            // a key container.



            // Create a new RSA signing key and save it in the container.

            RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();

            rsaKey.FromXmlString(PrivateKey);



            // Create a new XML document.

            XmlDocument xmlDoc = new XmlDocument();



            // Load an XML file into the XmlDocument object.

            xmlDoc.PreserveWhitespace = true;

            ms.Seek(0, SeekOrigin.Begin);

            xmlDoc.Load(ms);



            // Sign the XML document.

            SignXml(xmlDoc, rsaKey);



            // Save the document.

            xmlDoc.Save(fileName);
        }
Esempio n. 6
0
        public void CreateLicenseFile(LicenceDto dto, string fileName)
        {
            var ms = new MemoryStream();

            new XmlSerializer(typeof(LicenceDto)).Serialize(ms, dto);
            RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();

            rsaKey.FromXmlString(PrivateKey);
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            ms.Seek(0, SeekOrigin.Begin);
            xmlDoc.Load(ms);
            SignXml(xmlDoc, rsaKey);
            xmlDoc.Save(fileName);
        }
        public async Task <LicenceDto> InsertLicenceAsync(LicenceDto licenceDto)
        {
            var newLicence = new Licence()
            {
                UserId      = licenceDto.UserId,
                CreatorId   = licenceDto.CreatorId,
                LicenseName = licenceDto.LicenceName,
                StartDate   = new DateTime(licenceDto.StartDate.Year, licenceDto.StartDate.Month,
                                           licenceDto.StartDate.Day, 0, 0, 0),
                EndDate = new DateTime(licenceDto.EndDate.Year, licenceDto.EndDate.Month, licenceDto.EndDate.Day, 23,
                                       59, 59),
                Paid = licenceDto.Paid,
                Year = licenceDto.Year
            };
            var user = await _context.Users
                       .Select(u => new
            {
                u.FirstName,
                u.LastName,
                UserId = u.Id
            })
                       .AsNoTracking()
                       .FirstOrDefaultAsync(u => u.UserId == licenceDto.UserId);

            var xml = new XmlDocument();

            xml.LoadXml(@"<Statistik>
                 <Fischerverein>Fischerverein Muster</Fischerverein>
                 <Vorname />
                 <Nachname />
                 <Jahr />
                 <Monate/>
                 </Statistik>");

            var nodeFirstName = xml.SelectSingleNode("Statistik/Vorname");
            var nodeLastName  = xml.SelectSingleNode("Statistik/Nachname");
            var nodeYear      = xml.SelectSingleNode("Statistik/Jahr");

            if (nodeFirstName == null || nodeLastName == null || nodeYear == null)
            {
                _logger.InsertDatabaseLog(new DataBaseLog
                {
                    Type    = "XML Error StatisticRepository",
                    Message = "Fehler beim Zugriff auf XML Node"
                });
                return(null);
            }

            nodeFirstName.InnerText = user.FirstName;
            nodeLastName.InnerText  = user.LastName;
            nodeYear.InnerText      = licenceDto.Year.ToString();
            var newStatistic = new Statistic()
            {
                Licence      = newLicence,
                UserId       = licenceDto.UserId,
                Year         = licenceDto.StartDate.Year,
                StatisticXml = xml.OuterXml
            };
            await _context.Statistics.AddAsync(newStatistic);

            var checkInsert = await Complete();

            if (!checkInsert)
            {
                return(null);
            }

            _logger.InsertDatabaseLog(new DataBaseLog()
            {
                Type      = "Neue Lizenz",
                Message   = $"Neue Lizenz {licenceDto.LicenceName} wurde hinzugefügt durch {licenceDto.CreatorId}",
                CreatedAt = DateTime.Now
            });
            return(licenceDto);
        }