/// <summary>
        /// Возвращает патент (свидетельство) пользователя userName
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public Patent GetPatent(int?id)
        {
            Patent patent = new Patent();

            if (id == null)
            {
                return(patent);
            }

            List <Patent> userPatents = GetPatents().ToList();

            patent = userPatents.SingleOrDefault(p => p.PatentId == id);
            return(patent);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="patentEntry"></param>
        /// <param name="patent"></param>
        public void UpdatePatent(Patent patentEntry, Patent patent)
        {
            patentEntry.PatentNumber = patent.PatentNumber;
            patentEntry.PatentName   = patent.PatentName;
            patentEntry.PatentVidId  = patent.PatentVidId;
            patentEntry.FileModelId  = patent.FileModelId;
            patentEntry.YearId       = patent.YearId;
            patentEntry.PatentOwner  = patent.PatentOwner;
            patentEntry.IsACHII      = patent.IsACHII;
            patentEntry.IsZarubejn   = patent.IsZarubejn;
            patentEntry.RowStatusId  = patent.RowStatusId;

            if (patent.PatentNirSpecials != null && patent.PatentNirSpecials.Count > 0)
            {
                foreach (var patentNirSpecial in patent.PatentNirSpecials)
                {
                    bool isExists = false;
                    foreach (var patentNirSpecialEntry in patentEntry.PatentNirSpecials)
                    {
                        if (patentNirSpecialEntry.NirSpecialId == patentNirSpecial.NirSpecialId)
                        {
                            isExists = true;
                        }
                    }
                    if (!isExists)
                    {
                        patentEntry.PatentNirSpecials.Add(patentNirSpecial);
                    }
                }
            }

            if (patent.PatentAuthors != null && patent.PatentAuthors.Count > 0)
            {
                foreach (var patentAuthor in patent.PatentAuthors)
                {
                    bool isExists = false;
                    foreach (var patentAuthorEntry in patentEntry.PatentAuthors)
                    {
                        if (patentAuthorEntry.PatentAuthorId == patentAuthor.PatentAuthorId)
                        {
                            isExists = true;
                        }
                    }
                    if (!isExists)
                    {
                        patentEntry.PatentAuthors.Add(patentAuthor);
                    }
                }

                decimal firstAuthorPart = 1;
                for (int i = 1; i < patentEntry.PatentAuthors.Count; i++)
                {
                    firstAuthorPart -= patentEntry.PatentAuthors[i].AuthorPart;
                }

                if (firstAuthorPart < 0)
                {
                    firstAuthorPart = 0;
                }
                patentEntry.PatentAuthors[0].AuthorPart = firstAuthorPart;
            }

            _context.SaveChanges();
        }