Exemplo n.º 1
0
        public static Lib.Data.Smlouva Load(string Id, ElasticClient client = null)
        {
            try
            {
                ElasticClient c = client;
                if (client == null)
                {
                    c = Lib.ES.Manager.GetESClient();
                }

                var res = c
                          .Get <Lib.Data.Smlouva>(Id);
                if (res.Found)
                {
                    return(res.Source);
                }
                else
                {
                    if (client == null)
                    {
                        c = GetESClient_Sneplatne();
                    }
                    res = c.Get <Lib.Data.Smlouva>(Id);
                    if (res.Found)
                    {
                        return(res.Source);
                    }
                    else
                    {
                        ESLogger.Warning("Cannot load Smlouva Id " + Id, res.OriginalException);
                        DirectDB.NoResult("delete from SmlouvyIds where id = @id", new System.Data.SqlClient.SqlParameter("id", Id));
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                ESLogger.Error("Cannot load Smlouva Id " + Id, e);
                return(null);
            }
        }
Exemplo n.º 2
0
        //public static Nest.IIndexResponse Save(Person p, ElasticClient client = null)
        //{
        //    p.PrepareBeforeSave();
        //    if (client == null)
        //        client = Lib.ES.Manager.GetESClient();
        //    var res = client
        //        .Index<Lib.Data.Person>(p);
        //    return res;
        //}

        public static Nest.IIndexResponse Save(Lib.Data.Smlouva item, ElasticClient client = null)
        {
            if (item == null)
            {
                return(new Nest.IndexResponse());
            }

            item.PrepareBeforeSave();
            ElasticClient c = client;

            if (c == null)
            {
                if (item.platnyZaznam)
                {
                    c = Lib.ES.Manager.GetESClient();
                }
                else
                {
                    c = Lib.ES.Manager.GetESClient_Sneplatne();
                }
            }
            var res = c
                      //.Update<Lib.Data.Smlouva>()
                      .Index <Lib.Data.Smlouva>(item, m => m.Id(item.Id));

            if (item.platnyZaznam == false && res.IsValid && client == null)
            {
                //zkontroluj zda neni v indexu s platnymi. pokud ano, smaz ho tam
                var cExist = GetESClient();
                var s      = Manager.Load(item.Id, cExist);
                if (s != null)
                {
                    Delete(item.Id, cExist);
                }
            }

            if (res.IsValid)
            {
                try
                {
                    DirectDB.NoResult("exec smlouvaId_save @id,@active, @created, @updated",
                                      new System.Data.SqlClient.SqlParameter("id", item.Id),
                                      new System.Data.SqlClient.SqlParameter("created", item.casZverejneni),
                                      new System.Data.SqlClient.SqlParameter("updated", item.LastUpdate),
                                      new System.Data.SqlClient.SqlParameter("active", item.znepristupnenaSmlouva() ? (int)0 : (int)1)
                                      );
                }
                catch (Exception e)
                {
                    ESLogger.Error("Manager Save", e);
                }



                if (!string.IsNullOrEmpty(item.Platce?.ico))
                {
                    DirectDB.NoResult("exec Firma_IsInRS_Save @ico",
                                      new System.Data.SqlClient.SqlParameter("ico", item.Platce?.ico)
                                      );
                }
                if (!string.IsNullOrEmpty(item.VkladatelDoRejstriku?.ico))
                {
                    DirectDB.NoResult("exec Firma_IsInRS_Save @ico",
                                      new System.Data.SqlClient.SqlParameter("ico", item.VkladatelDoRejstriku?.ico)
                                      );
                }
                foreach (var s in item.Prijemce ?? new Data.Smlouva.Subjekt[] { })
                {
                    if (!string.IsNullOrEmpty(s.ico))
                    {
                        DirectDB.NoResult("exec Firma_IsInRS_Save @ico",
                                          new System.Data.SqlClient.SqlParameter("ico", s.ico)
                                          );
                    }
                }
            }
            return(res);
        }