public async Task <IActionResult> PutReleaseNote(ReleaseNoteParms rnp)
        {
            ReleaseNote existingReleaseNote = await _context.ReleaseNote.Where(x => x.Id == rnp.ReleaseNoteId).Include("CountryCodeReleaseNote").Include("EnvironmentReleaseNote").SingleAsync();

            _context.CountryCodeReleaseNote.RemoveRange(existingReleaseNote.CountryCodeReleaseNote);
            _context.EnvironmentReleaseNote.RemoveRange(existingReleaseNote.EnvironmentReleaseNote);

            foreach (int id in rnp.CountryCodeId)
            {
                existingReleaseNote.CountryCodeReleaseNote.Add(new CountryCodeReleaseNote {
                    CountryCodeId = id
                });
            }

            foreach (int id in rnp.EnvironmentId)
            {
                existingReleaseNote.EnvironmentReleaseNote.Add(new EnvironmentReleaseNote {
                    EnvironmentId = id
                });
            }

            existingReleaseNote.KeyName   = rnp.KeyName;
            existingReleaseNote.Value     = rnp.Value;
            existingReleaseNote.CleTypeId = rnp.CleTypeId; // The same key cannot occur in tech and func ?? yes !! maar waarschuwing !!!
            existingReleaseNote.CommentId = rnp.CommentId;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReleaseNoteExists(rnp.ReleaseNoteId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(existingReleaseNote));
        }
        [Route("SearchReleaseNotes")] // So the complete route is : /api/ReleaseNote/SearchReleaseNotes
        public async Task <IEnumerable <ReleaseNoteParms> > SearchReleaseNotes(ReleaseNoteParms parms)
        {
            List <ReleaseNote> releaseNotesFound = await GetAllReleaseNotes().Where(r =>
                                                                                    r.ReleaseId == parms.ReleaseId &&
                                                                                    // r.EnvironmentId == parms.CleTypeId &&
                                                                                    //  parms.CountryCodeId.Contains(r.CountryCodeId) &&
                                                                                    //  parms.EnvironmentId.Contains(r.EnvironmentId) &&
                                                                                    r.KeyName.Contains(parms.KeyName)
                                                                                    ).ToListAsync();

            List <ReleaseNoteParms> lReleaseNotes = new List <ReleaseNoteParms>();
            var keys      = releaseNotesFound.GroupBy(p => p.KeyName, (key) => new { key });
            var countries = releaseNotesFound.GroupBy(p => p.CountryCodeReleaseNote).Select(x => x.Key);

            foreach (var rnf in releaseNotesFound)
            {
                int CleTypeId = rnf.CleTypeId;
                //     var rn = FindUniqueReleaseNote(releaseNotesFound, parms.ReleaseId, parms.CleTypeId, parms.KeyName);
                int[] countryCodeId = rnf.CountryCodeReleaseNote.Select(x => x.CountryCodeId).OrderBy(x => x).ToArray();
                int[] environmentId = rnf.EnvironmentReleaseNote.Select(x => x.EnvironmentId).OrderBy(x => x).ToArray();


                //  string value = releaseNotesFound.Where(x => x.KeyName == k.Key).GroupBy(p => p.Value).Select(x => x.Key).First();
                lReleaseNotes.Add(new ReleaseNoteParms
                {
                    ReleaseNoteId = rnf.Id,
                    KeyName       = rnf.KeyName,
                    Value         = rnf.Value,
                    CountryCodeId = countryCodeId,
                    EnvironmentId = environmentId,
                    CleTypeId     = rnf.CleTypeId,
                    CommentId     = rnf.CommentId
                });
            }

            return(lReleaseNotes);
        }
        public async Task <IActionResult> PostReleaseNote(ReleaseNoteParms rnp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ReleaseNote releaseNote = new ReleaseNote();

            var rn = await _context.ReleaseNote.Where(x => x.KeyName == rnp.KeyName && x.ReleaseId == rnp.ReleaseId && rnp.CleTypeId == rnp.CleTypeId).Include("CountryCodeReleaseNote").Include("EnvironmentReleaseNote").SingleOrDefaultAsync();

            if (rn == null)
            {
                releaseNote = new ReleaseNote {
                    KeyName = rnp.KeyName, Value = rnp.Value, CleTypeId = rnp.CleTypeId, ReleaseId = rnp.ReleaseId, CommentId = rnp.CommentId
                };
                foreach (int id in rnp.CountryCodeId)
                {
                    releaseNote.CountryCodeReleaseNote.Add(new CountryCodeReleaseNote {
                        CountryCodeId = id
                    });
                }

                foreach (int id in rnp.EnvironmentId)
                {
                    releaseNote.EnvironmentReleaseNote.Add(new EnvironmentReleaseNote {
                        EnvironmentId = id
                    });
                }

                _context.ReleaseNote.Add(releaseNote);
            }

            await _context.SaveChangesAsync();

            return(Ok());
            //   return CreatedAtAction("GetReleaseNote", new { id = rn.Id }, rn);
        }