LibiadaWeb.Models.Repositories.Sequences.ElementRepository.ElementsInDb C# (CSharp) Method

ElementsInDb() public method

The elements in db.
public ElementsInDb ( Alphabet alphabet, int notationId ) : bool
alphabet Alphabet /// The alphabet. ///
notationId int /// The notation id. ///
return bool
        public bool ElementsInDb(Alphabet alphabet, int notationId)
        {
            var elements = from IBaseObject element in alphabet select element.ToString();

            int existingElementsCount = db.Element.Count(e => elements.Contains(e.Value) && e.NotationId == notationId);

            return alphabet.Cardinality == existingElementsCount;
        }

Usage Example

        /// <summary>
        /// The create DNA sequence.
        /// </summary>
        /// <param name="sequence">
        /// The common sequence.
        /// </param>
        /// <param name="fastaSequence">
        /// Sequence as <see cref="ISequence"/>>.
        /// </param>
        /// <param name="partial">
        /// The partial.
        /// </param>
        /// <exception cref="Exception">
        /// Thrown if at least one element of new sequence is missing in db
        /// or if sequence is empty or invalid.
        /// </exception>
        public void Create(CommonSequence sequence, ISequence fastaSequence, bool partial)
        {
            if (fastaSequence.ID.Contains("Resource temporarily unavailable"))
            {
                throw new Exception("Sequence is empty or invalid (probably ncbi is not responding).");
            }

            string stringSequence = fastaSequence.ConvertToString().ToUpper();

            var chain = new BaseChain(stringSequence);

            if (!ElementRepository.ElementsInDb(chain.Alphabet, sequence.Notation))
            {
                throw new Exception("At least one element of new sequence is invalid (not A, C, T, G or U).");
            }

            MatterRepository.CreateOrExtractExistingMatterForSequence(sequence);

            long[] alphabet = ElementRepository.ToDbElements(chain.Alphabet, sequence.Notation, false);
            Create(sequence, partial, alphabet, chain.Building);
        }