/// <summary> /// The get next enp number facets. /// </summary> /// <param name="tfomsId"> /// The tfoms id. /// </param> /// <param name="genderId"> /// The gender id. /// </param> /// <param name="birthday"> /// The birthday. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public string GetNextEnpNumber(Guid tfomsId, int genderId, DateTime birthday) { var tfoms = ObjectFactory.GetInstance <IOrganisationCacheManager>().GetBy(x => x.Id == tfomsId).FirstOrDefault(); if (tfoms == null || tfoms.Code.Length != 2) { throw new Exception("Не найден ТФОМС для расчета фасеты ЕНП"); } var facet = tfoms.Code + EnpChecker.GetFacet(birthday, genderId == Sex.Sex1); NumberPolicyCounter numberPolicyCounter; // получение значения счетчика var session = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession(); numberPolicyCounter = GetById(facet); var number = "1"; if (numberPolicyCounter == null) { numberPolicyCounter = new NumberPolicyCounter { Id = facet, CurrentNumber = 2 }; } else { number = numberPolicyCounter.CurrentNumber.ToString(CultureInfo.InvariantCulture); numberPolicyCounter.CurrentNumber++; } // сохранение session.SaveOrUpdate(numberPolicyCounter); var enp = string.Format("{0}{1}", facet, number.PadLeft(5, '0')); return(EnpChecker.AppendCheckSum(enp)); }