public virtual ExcludeData GetExcludeData(uint excludeId)
        {
            return(Slave(s => {
                var exclude = s.Load <Exclude>(excludeId);
                var equivalients = s.CreateSQLQuery(@"
select e.ProducerId as Id, concat(e.Name, ' [', p.Name, ' ]') as Name
from Catalogs.ProducerEquivalents e
join Catalogs.Assortment a on a.ProducerId = e.ProducerId
join Catalogs.Producers p on p.Id = a.ProducerId
where a.Checked = 1 and a.CatalogId = :catalogId")
                                   .SetParameter("catalogId", exclude.CatalogProduct.Id)
                                   .SetResultTransformer(new AliasToPropertyTransformer(typeof(ProducerOrEquivalentDto)))
                                   .List <ProducerOrEquivalentDto>();
                var assortment = Assortment.Search(s, 0, new Query("CatalogId", exclude.CatalogProduct.Id)).Content.Where(a => a.Checked).ToList();
                var producers = equivalients
                                .Concat(assortment.Select(a => new ProducerOrEquivalentDto {
                    Id = a.ProducerId, Name = a.Producer
                }))
                                .OrderBy(p => p.Name).ToList();
                return new ExcludeData {
                    Producers = producers,
                    Synonyms = ProducerSynonym.Load(s, new Query("Name", exclude.ProducerSynonym)),
                };
            }));
        }
        public void Get_assortment_for_producer()
        {
            var testProducer = session.Query <Producer>().FirstOrDefault(p => p.Name == "test-producer");

            if (testProducer != null)
            {
                session.Delete(testProducer);
            }
            session.Flush();

            var producer = new Producer();

            producer.Name = "test-producer";
            session.Save(producer);

            var assortment = new Assortment(session.Query <CatalogProduct>().First(), producer);

            session.Save(assortment);
            session.Flush();

            var producerId = producer.Id;

            session.Clear();

            var assortments = Assortment.Search(session, 0, new Query("ProducerId", producerId));

            Assert.That(assortments.Content.Count, Is.EqualTo(1));
            var assortment1 = assortments.Content.Single();

            Assert.That(assortment1.Producer, Is.EqualTo("test-producer"));
        }
        public void Search_text()
        {
            var assortments       = Assortment.Search(session, 5, null);
            var findedAssortments = Assortment.Search(session, 0, new Query("ProducerId", assortments.Content[1].ProducerId));

            Assert.That(findedAssortments.Content.Count, Is.GreaterThan(1));
            Assert.That(findedAssortments.Page, Is.EqualTo(0));
        }
 public virtual Pager <AssortmentDto> ShowAssortment(uint assortimentId)
 {
     return(Slave(session => {
         uint page = 0;
         if (assortimentId != 0)
         {
             page = Assortment.GetPage(session, assortimentId);
         }
         return Assortment.Search(session, page, null);
     }));
 }
        public void Get_page()
        {
            var assortments = Assortment.Search(session, 3, null);

            Assert.That(Assortment.GetPage(session, assortments.Content[3].Id), Is.GreaterThan(3));
        }
        public void Total()
        {
            var assortments = Assortment.Search(session, 0, null);

            Assert.That(assortments.TotalPages, Is.GreaterThan(0));
        }
 public virtual Pager <AssortmentDto> ShowAssortmentForProducer(uint producerId, uint page)
 {
     return(Slave(session => Assortment.Search(session, page, new Query("ProducerId", producerId))));
 }
 public virtual Pager <AssortmentDto> SearchAssortment(string text, uint page)
 {
     return(Slave(session => Assortment.Search(session, page, new Query("CatalogName", "%" + text + "%"))));
 }
 public virtual Pager <AssortmentDto> GetAssortmentPage(uint page)
 {
     return(Slave(session => Assortment.Search(session, page, null)));
 }