Beispiel #1
0
        public KendoResult <RadniNalog> PregledGrid([FromBody] KendoRequest kr) //Get([FromUri] FilterContainer filter, int take, int skip, int page, int pageSize)
        {
            //if (kr.Filter != null && kr.Filter.Filters.FirstOrDefault(x => x.Field == "all") != null)
            //{
            //    var sp = _session.CreateSQLQuery("exec KupacLookup")
            //}
            RadniNalog       nalog       = null;
            Klijent          klijent     = null;
            Ponuda           ponuda      = null;
            RadniNalogStatus nalogStatus = null;
            //RadniNalogPredmet radniNalogPredmet = null;
            ObimPoslovanja obim = null;
            var            upit = _session.QueryOver(() => nalog)
                                  .Where(x => x.Obrisan == false);


            upit.JoinAlias(x => x.Ponuda, () => ponuda)
            .JoinAlias(x => x.Ponuda.Klijent, () => klijent)
            .JoinAlias(x => x.PredmetNaloga, () => obim)
            .JoinAlias(x => x.RadniNalogStatus, () => nalogStatus);
            //.JoinAlias(x => x.PredmetNaloga, () => radniNalogPredmet)
            //.JoinAlias(() => radniNalogPredmet.ObimPoslovanja, () => obim);



            //TextInfo textInfo = CultureInfo.InvariantCulture.TextInfo;
            if (kr.Filter != null && kr.Filter.Filters.Any())
            {
                foreach (FilterDescription filter in kr.Filter.Filters)
                {
                    //string prop = textInfo.ToTitleCase(filter.Field);
                    string prop = filter.Field.FirstCharToUpper();

                    if (prop.ToLower().Contains("ponuda.klijent.id"))
                    {
                        upit.And(() => ponuda.Klijent.Id == int.Parse(filter.Value));
                    }
                    else if (prop.ToLower().Contains("nalogstatus"))
                    {
                        upit.And(() => nalogStatus.Id == int.Parse(filter.Value));
                    }
                    else if (prop.ToLower().Contains("predmetnaloga"))
                    {
                        upit.And(Restrictions.Disjunction()
                                 .Add(Restrictions.On(() => obim.Sifra)
                                      .IsInsensitiveLike(filter.Value, MatchMode.Anywhere))
                                 .Add(Restrictions.On(() => obim.Naziv)
                                      .IsInsensitiveLike(filter.Value, MatchMode.Anywhere)));
                    }
                    else if (prop.ToLower().Contains("klijent.naziv"))
                    {
                        upit.AndRestrictionOn(() => klijent.Naziv).IsInsensitiveLike(filter.Value, MatchMode.Anywhere);
                    }
                    else if (prop.Contains("DatumKreiranja"))
                    {
                        var d = Convert.ToDateTime(filter.Value);
                        filter.Value = d.ToLocalTime().ToString("yyyyMMdd");
                        if (filter.Operator == "gte")
                        {
                            upit.And(x => x.DatumKreiranja >= d);
                        }
                        if (filter.Operator == "lte")
                        {
                            upit.And(x => x.DatumKreiranja <= d);
                        }
                    }
                    else
                    {
                        upit.Where(Restrictions.InsensitiveLike(prop, filter.Value, MatchMode.Anywhere));
                    }
                }
            }


            var rowcount = upit.ToRowCountQuery();

            if (kr.PageSize != 0)
            {
                upit.Skip(kr.Skip);
                upit.Take(kr.Take);
            }

            if (kr.Sort.Any())
            {
                foreach (Sort sort in kr.Sort)
                {
                    string prop = sort.Field.FirstCharToUpper(); //textInfo.ToTitleCase(sort.Field);
                    upit.UnderlyingCriteria.AddOrder(new Order(prop, sort.Dir.ToLower() == "asc"));
                }
            }



            upit.Future <RadniNalog>();
            //supit.TransformUsing(Transformers.DistinctRootEntity);


            //rowcount.Select(Projections.Count(Projections.Id()));

            var redova = rowcount.FutureValue <int>().Value;

            var lista = upit.List <RadniNalog>();
            var res   = new KendoResult <RadniNalog>
            {
                Data  = lista,
                Total = redova
            };

            return(res);
        }
Beispiel #2
0
        public void UnesiRadniNalogStatus(RadniNalogStatus radniNalogStatus)
        {
            try
            {
                LavDataClassesDataContext _baza = new LavDataClassesDataContext(konekcioniString);

                _baza.ResetujBrojac("RadniNalogStatus", "RadniNalogStatusID");

                if (radniNalogStatus.Sifra == null)
                {
                    radniNalogStatus.Sifra = _baza.DajSledeciIdentity("RadniNalogStatus").ToString();
                }

                _baza.RadniNalogStatus.InsertOnSubmit(radniNalogStatus);

                _baza.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public void IzmeniRadniNalogStatus(RadniNalogStatus radniNalogStatus, RadniNalogStatus radniNalogStatusOrginal)
        {
            try
            {
                LavDataClassesDataContext _baza = new LavDataClassesDataContext(konekcioniString);

                _baza.RadniNalogStatus.Attach(radniNalogStatus, radniNalogStatusOrginal);

                _baza.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public void ObrisiRadniNalogStatus(RadniNalogStatus radniNalogStatus)
        {
            try
            {
                LavDataClassesDataContext _baza = new LavDataClassesDataContext(konekcioniString);

                //ovo mora zato sto se ne moze dodati u ovaj DataContext zato sto pripada nekom drugom
                DB.RadniNalogStatus _radniNalogStatus = new DB.RadniNalogStatus
                {
                    RadniNalogStatusID = radniNalogStatus.RadniNalogStatusID,
                    Sifra = radniNalogStatus.Sifra,
                    Naziv = radniNalogStatus.Naziv,
                };

                _baza.RadniNalogStatus.Attach(_radniNalogStatus);
                _baza.RadniNalogStatus.DeleteOnSubmit(_radniNalogStatus);
                _baza.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }