public virtual void AddToAssotrment(uint excludeId, uint producerId, string equivalent) { Transaction(s => { var exclude = s.Load <Exclude>(excludeId); var producer = s.Load <Producer>(producerId); var assortment = new Assortment(exclude.CatalogProduct, producer) { Checked = true }; if (assortment.Exist(s)) { assortment = s.Query <Assortment>() .First(a => a.Producer == assortment.Producer && a.CatalogProduct == assortment.CatalogProduct); assortment.Checked = true; } if (!String.IsNullOrEmpty(equivalent)) { equivalent = equivalent.Trim(); if (!producer.Equivalents.Any(e => e.Name.Equals(equivalent, StringComparison.CurrentCultureIgnoreCase))) { s.Save(new ProducerEquivalent(producer, equivalent)); } } var synonym = new ProducerSynonym { Price = exclude.Price, Name = exclude.ProducerSynonym, Producer = producer }; if (!synonym.Exist(s)) { s.Save(synonym); } s.SaveOrUpdate(assortment); exclude.Remove(s); s.Flush(); assortment.CleanupExcludes(s); }); }