Example #1
0
        public BaseResponse AddCourt(AddCourtRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () =>
            {
            },

                                                   req =>
            {
                var response = new BaseResponse();
                using (var repo = new NhRepository <Court>())
                {
                    var entity = repo.Query(x => x.Name == req.Name).FirstOrDefault();
                    if (entity != null)
                    {
                        throw new EeException(ErrorCodes.Existed, "Object is existed.");
                    }
                    entity = new Court()
                    {
                        Name = req.Name,
                        Province = req.Province,
                        City = req.City,
                        County = req.County,
                        Address = req.Address,
                        Rank = req.Rank,
                        ContactNo = req.ContactNo,
                    };
                    repo.Create(entity);
                }
                return response;
            }
                                                   ));
        }
Example #2
0
        public BaseResponse UpdateCourt(UpdateCourtRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () =>
            {
            },

                                                   req =>
            {
                var response = new BaseResponse();
                using (var repo = new NhRepository <Court>())
                {
                    var entity = repo.GetById(req.Id);
                    if (entity == null)
                    {
                        throw new EeException(ErrorCodes.NotFound, "Object is not found.");
                    }
                    entity.Name = req.Name;
                    entity.Rank = req.Rank;
                    entity.Province = req.Province;
                    entity.City = req.City;
                    entity.County = req.County;
                    entity.Address = req.Address;
                    entity.ContactNo = req.ContactNo;
                    repo.Update(entity);
                }
                return response;
            }
                                                   ));
        }
Example #3
0
        public BaseResponse RemoveClient(RemoveClientRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () =>
            {
            },

                                                   req =>
            {
                var response = new BaseResponse();
                using (var repo = new NhRepository <Client>())
                {
                    foreach (var id in req.Ids)
                    {
                        var entity = repo.GetById(id);
                        if (entity != null)
                        {
                            repo.Delete(entity);
                        }
                    }
                }
                return response;
            }
                                                   ));
        }
Example #4
0
        public BaseResponse UpdateClient(UpdateClientRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () =>
            {
            },

                                                   req =>
            {
                var response = new BaseResponse();
                using (var repo = new NhRepository <Client>())
                {
                    var entity = repo.GetById(req.Id);
                    if (entity == null)
                    {
                        throw new EeException(ErrorCodes.NotFound, "Object is not found.");
                    }

                    entity.Name = req.Name;
                    //TODO:

                    repo.Update(entity);
                }
                return response;
            }
                                                   ));
        }
		public void nontest()
		{
			var t = typeof(Entity.Blog);
			IRepository x = new NhRepository(t);
			var blog = new Entity.Blog()
			{
				Title = "adsf",
				Entries = new List<Entity.Entry>() { new Entity.Entry() { Name = "asdf", Content = "blah blah blah" } }
			};
			x.Persist(blog);
		}
Example #6
0
        public void QueryTest()
        {
            using (var session = SessionManager.GetConnection())
            {
                using (var repo = new NhRepository <Court>())
                {
                    var query = repo.Query();

                    var list = query.ToList();
                }
            }
        }
Example #7
0
        public void QueryAreaTest()
        {
            using (var session = SessionManager.GetConnection())
            {
                using (var repo = new NhRepository <Area>())
                {
                    var query = repo.Query(x => x.AreaCode == "440000");

                    var list = query.ToList();
                }
            }
        }
Example #8
0
 public void DeleteTest()
 {
     using (var session = SessionManager.GetConnection())
     {
         using (var repo = new NhRepository <Court>())
         {
             var entity = repo.GetById(3);
             if (entity != null)
             {
                 repo.Delete(entity);
             }
         }
     }
 }
Example #9
0
 public void AddTest()
 {
     using (var session = SessionManager.GetConnection())
     {
         using (var repo = new NhRepository <Court>())
         {
             repo.Create(new Court()
             {
                 Id   = 1,
                 Name = "a"
             });
         }
     }
 }
Example #10
0
 public void UpdateTest()
 {
     using (var session = SessionManager.GetConnection())
     {
         using (var repo = new NhRepository <Court>())
         {
             var entity = repo.GetById(1);
             if (entity != null)
             {
                 entity.Name = "new-Name" + DateTime.Now;
                 repo.Update(entity);
             }
         }
     }
 }
        public void WhenInsertingAllIntoTableAllCountriesAreInTable()
        {
            var parser       = new CsvCountrieFileParser();
            var dbOperations = new NhRepository <Country>(session);

            var target = CreateTarget(parser, dbOperations);

            target.SaveCountriesInDatabase(@"Countries.csv");

            var expected = parser.Read(@"Countries.csv");

            var actural = dbOperations.GetAll();

            Assert.AreEqual(expected.Count, actural.Count);

            for (int i = 0; i < expected.Count; i++)
            {
                expected[i].AssertAreSame(actural[i]);
            }
        }
Example #12
0
        public BaseQueryResponse <PropertyItemCategory> GetPropertyItemCategory(GetPropertyItemCategoryRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () => { },

                                                   req =>
            {
                var response = new BaseQueryResponse <PropertyItemCategory>();
                using (var repo = new NhRepository <PropertyItemCategory>())
                {
                    var query = repo.Query().Where(x => x.Parent != null && x.Parent.Code == req.Code);

                    response.Total = query.Count();
                    response.QueryList = query.ToList();
                }
                return response;
            }
                                                   ));
        }
Example #13
0
        public BaseQueryResponse <Client> QueryClient(QueryClientRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () =>
            {
            },

                                                   req =>
            {
                var response = new BaseQueryResponse <Client>();
                using (var repo = new NhRepository <Client>())
                {
                    var query = repo.Query();

                    response.Total = query.Count();
                    response.QueryList = query.ToList();
                }
                return response;
            }
                                                   ));
        }
Example #14
0
        public BaseQueryResponse <Area> GetAreas(GetAreasRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () =>
            {
            },

                                                   req =>
            {
                var response = new BaseQueryResponse <Area>();
                using (var repo = new NhRepository <Area>())
                {
                    var query = repo.Query(x => x.Parent == null);

                    response.Total = query.Count();
                    response.QueryList = query.ToList();
                }
                return response;
            }
                                                   ));
        }
 private CountriesFromFieToDatabase CreateTarget(CsvCountrieFileParser parser, NhRepository <Country> dbOperations)
 {
     return(new CountriesFromFieToDatabase(parser, dbOperations));
 }