Exemple #1
0
 protected void Application_Start()
 {
     ElasticServer.Initialize();
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
        public void InsertPerson(Person person)
        {
            var elastic = ElasticServer.GetClient();
            var res     = elastic.Index <Person>(person);

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
        }
        public void DeletePlace(Place place)
        {
            var elastic = ElasticServer.GetClient();
            var res     = elastic.Delete <Place>(place);

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
        }
        public void UpdatePerson(Person person)
        {
            var elastic = ElasticServer.GetClient();
            var path    = new DocumentPath <Person>(person);
            var res     = elastic.Update(path, x => x.Doc(person));

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
        }
        public Person[] GetAllPerson()
        {
            var elastic = ElasticServer.GetClient();
            var res     = elastic.Search <Person>(s => s.AllTypes());

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
            return(new List <Person>(res.Documents).ToArray());
        }
Exemple #6
0
        public Loan[] GetByPerson(string id)
        {
            var elastic = ElasticServer.GetClient();
            var res     = elastic.Search <Loan>(s => s.Query(q => q.Match(m => m.Field(f => f.PersonId).Query(id))));

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
            return(new List <Loan>(res.Documents).ToArray());
        }
Exemple #7
0
        public Loan[] GetAll()
        {
            var elastic = ElasticServer.GetClient();
            var res     = elastic.Search <Loan>();

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
            return(new List <Loan>(res.Documents).ToArray());
        }
        public void DeleteItem(Item item)
        {
            var elastic  = ElasticServer.GetClient();
            var itemType = item.Type.ToString().ToLower();
            var result   = elastic.Delete <Item>(item, t => t.Type(itemType));

            if (result.ServerError != null)
            {
                throw new System.Exception(result.ServerError.Error.ToString());
            }
        }
        //Insert title to database.
        public void InsertItem(Item item)
        {
            var elastic  = ElasticServer.GetClient();
            var itemType = item.Type.ToString().ToLower();
            var result   = elastic.Index(item, m => m.Type(itemType));

            if (result.ServerError != null)
            {
                throw new System.Exception(result.ServerError.Error.ToString());
            }
        }
        public void UpdatePlace(Place place)
        {
            var elastic = ElasticServer.GetClient();
            var path    = new DocumentPath <Place>(place);
            var res     = elastic.Update <Place>(path, x => x.Doc(place));

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
        }
        //Update title in the database.
        public void UpdateItem(Item item)
        {
            var elastic  = ElasticServer.GetClient();
            var itemType = item.Type.ToString().ToLower();
            var path     = new DocumentPath <Item>(item).Type(itemType);
            var res      = elastic.Update(path, x => x.Doc(item));

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
        }
        public Item GetById(string Id)
        {
            var elastic = ElasticServer.GetClient();
            var res     = elastic.Get <Item>(new Item {
                Id = Id
            });

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
            return(res.Source);
        }
Exemple #13
0
        public void EndLoan(Item item, Person person, DateTime date)
        {
            //Create new loan object with end date for partial update in Elastic.
            var newLoan = new Loan
            {
                Id      = item.Id + person.Id,
                EndDate = date,
                Ended   = true
            };
            //Update loan in ElasticSearch.
            var elastic = ElasticServer.GetClient();
            var path    = new DocumentPath <Loan>(newLoan);
            var res     = elastic.Update <Loan>(path, x => x.Doc(newLoan));

            if (res.ServerError != null)
            {
                throw new System.Exception(res.ServerError.Error.ToString());
            }
        }
Exemple #14
0
        public void StartLoan(Item item, Person person, DateTime date)
        {
            //Create new loan object with item's and person's id, saving it's start date.
            var newLoan = new Loan
            {
                Id        = item.Id + person.Id,
                ItemId    = item.Id,
                PersonId  = person.Id,
                StartDate = date
            };
            //Insert loan in ElasticSearch.
            var elastic = ElasticServer.GetClient();
            var result  = elastic.Index(newLoan);

            if (result.ServerError != null)
            {
                throw new System.Exception(result.ServerError.Error.ToString());
            }
        }