public void CreateRepository()
 {
     _repo = new UserRepository();
     _user1 = new User("admin","test");
     _repo.Save(_user1);
     _user2 = new User("razvan","1234");
     _repo.Save(_user2);
 }
 public void CreateRepository()
 {
     _repo = new ExpenseRepository();
     _exp1 = new Expense(TypeExpense.Car, 34, "euro");
     _exp2 = new Expense(TypeExpense.Eat, 45, "euro");
     _repo.Save(_exp1);
     _repo.Save(_exp2);
 }
        public when_implementing_base_repository() 
        {
            RefreshDb();

            _repository = new DataProviderRepository(Session);
            var dataProvider = ReadDataProviderMother.Ivid;
            _repository.Save(dataProvider);
            _repository.Save(ReadDataProviderMother.Rgt);

            Session.Flush();

            _id = GetFromDb(dataProvider).Id;
        }
        public void Common_CanDelete(IRepository<Product> db)
        {
            db.Save(new Product { ProductName = "Optimus", Category = "Autobots", MinimumPrice = 7 });

            var px = new Product { ProductName = "Bumble Bee", Category = "Autobots", MinimumPrice = 8 };
            db.Save(px);

            db.Save(new Product { ProductName = "Megatron", Category = "Decepticon", MinimumPrice = 9 });

            db.Delete(px.ProductId, px.RowVersion);

            Assert.AreEqual(7 + 9, db.All.Sum(x => x.MinimumPrice));
            Assert.AreEqual(null, db.Get(px.ProductId));
            Assert.AreEqual(2, db.All.Count());
        }
        // Update course 
        public static CourseUpdate.Response Handle(IRepository repository, CourseUpdate.Request request)
        {
            var container = CourseFactory.CreatePartial(request.CommandModel.CourseID).Modify(request.CommandModel);
            var validationDetails = repository.Save(container);

            return new CourseUpdate.Response(validationDetails);
        }
Example #6
0
 private static Setting InitializeSetting(string settingName, IRepository repository)
 {
     var setting = new Setting { Name = settingName.Encrypt() };
     repository.Add<Setting>(setting);
     repository.Save();
     return setting;
 }
 public override void Handle(IRepository _repository)
 {
     var command = this;
     var order = _repository.GetOrder(command.OrderId);
     var products = order.Products.Add(_repository.GetProduct(command.ProductId));
     _repository.Save(order.With(products:products));
 }
Example #8
0
        static void Main(string[] args)
        {
            IoC.Register();
            _repo = IoC.Resolve<IRepository>();

            var geos = _repo.Find<City>().ToList();
            Console.WriteLine(string.Format("{0} total cities...", geos.Count()));

            int i =0;
            foreach (var geo in geos)
            {
                if (geo.Geography.GetType() == typeof(NetTopologySuite.Geometries.MultiPoint))
                {
                    Console.WriteLine(string.Format("{0} is a MultiPoint...", geo.Name));
                    var point = new NetTopologySuite.Geometries.Point(geo.Geography.Coordinates.First());
                    geo.Geography = point;
                    _repo.Save<City>(geo);
                    _repo.SubmitChanges();
                    Console.WriteLine(string.Format("{0} updated to Point...", geo.Name));
                    i++;
                }
            }
            Console.WriteLine(string.Format("{0} total Cities updated...", i));
            Console.Read();
        }
        // Modify student
        public static StudentModify.Response Handle(IRepository repository, StudentModify.Request request)
        {
            var commandModel = request.CommandModel;
            var container = StudentFactory.CreatePartial(commandModel.ID).Modify(commandModel);
            var validationDetails = repository.Save(container);

            return new StudentModify.Response(validationDetails);
        }
        // Delete course 
        public static CourseDelete.Response Handle(IRepository repository, CourseDelete.Request request)
        {
            var course = CourseFactory.CreatePartial(request.CommandModel.CourseId);
            var container = course.Delete();
            repository.Save(container);

            return new CourseDelete.Response();
        }
Example #11
0
        /// <summary>Setups the basic settings.</summary>
        /// <param name="settingsRepository">The settings repository.</param>
        private static void SetupSettings(IRepository<Settings> settingsRepository)
        {
            var userRegistrationPrice = new Settings
            {
                _Key = USER_REGISTRATION_PRICE_KEY,
                Value = "50"
            };

            var vendorRegistrationPrice = new Settings
            {
                _Key = VENDOR_REGISTRATION_PRICE_KEY,
                Value = "100"
            };

            settingsRepository.Save(userRegistrationPrice);
            settingsRepository.Save(vendorRegistrationPrice);
        }
Example #12
0
        private static void SampleMethod(IRepository<Product,int?> productRepository)
        {
            SessionProvider.RebuildSchema();

            //Create a Product
            var pNew = new Product { ProductName = "Canned Salmon" };
            productRepository.Save(pNew);

            //Get a Product
            var pGet = productRepository.GetById(pNew.ProductId);

            //Update a Product
            pGet.ProductName = "Canned Tuna";
            productRepository.Save(pGet);

            //Delete a Product
            productRepository.Delete(pNew);
        }
        public void SetUp()
        {
            _repository = new MockRepository();

            _developer = new Developer() { Username = "jchadwick" };

            _calculators = new[] { new DefaultAchievementCalculator(_repository) };

            _repository.Save(_developer);
        }
        // Delete studen
        public static StudentDelete.Response Handle(IRepository repository, StudentDelete.Request request)
        {
            var container = StudentFactory
                .CreatePartial(request.CommandModel.StudentId)
                .Delete();

            var validationDetails = repository.Save(container);

            return new StudentDelete.Response(validationDetails);
        }
Example #15
0
        public virtual void setup()
        {
            var mongoRepository = new MongoRepository("blogspecs");
            mongoRepository.DeleteCollection<BlogSettings>();
            mongoRepository.DeleteCollection<Post>();

            _repository = mongoRepository;

            _blog = new BlogSettings
            {
                VirtualMediaPath = ""
            };
            _repository.Save(_blog);

            _fakePost = Post.CreatePost("Hello world", "", "BjartN", null);

            _repository.Save(_fakePost);

            _api = new  Infrastructure.MetaWeblogApi.MetaWeblog(_repository, new FakeUrlContext(),new FakeAuthenticationService());
        }
        // Create student
        public static StudentCreate.Response Handle(IRepository repository, StudentCreate.Request request)
        {
            var container = new EntityStateWrapperContainer();
            container.AddEntity(StudentFactory.Create(request.CommandModel));
            var validationDetails = repository.Save(container);

            var studentId = default(int?);
            if (!validationDetails.HasValidationIssues)
                studentId = container.FindEntity<Student>().ID;

            return new StudentCreate.Response(validationDetails, studentId);
        }
Example #17
0
        public static void InitializeTestClass(TestContext testContext)
        {
            if (Directory.Exists(Configuration.PERSITS_VIRTUAL_FILE_PATH))
            {
                Directory.Delete(Configuration.PERSITS_VIRTUAL_FILE_PATH, true);
            }

            Application.Current.SetApplicationAssembly(Assembly.GetExecutingAssembly());
            repository = new DefaultRepository(fileStoreService, cacheStoreService);

            repository.Save(RepositoryTests.GetContentTypeCollection());
        }
        public static CountryCreate.Response Handle(IRepository repository, CountryCreate.Request request)
        {
            var validationDetails = Validator.ValidateRequest(request);
            if (validationDetails.HasValidationIssues)
                return new CountryCreate.Response(validationDetails: validationDetails);

            var country = new Country(request.CommandModel.Name, request.CommandModel.Population);
            repository.Add(country);
            repository.Save();

            return new CountryCreate.Response(country.Id);
        }
        // Create Department
        public static DepartmentCreate.Response Handle(IRepository repository, DepartmentCreate.Request request)
        {
            // Validation now performed in the dispacther decorators (See AutoValidate<T> in the DomainBootstrapper class)

            var container = DepartmentFactory.Create(request.CommandModel);
            var validationDetails = repository.Save(container);

            var deptId = default(int?);
            if (!validationDetails.HasValidationIssues)
                deptId = container.FindEntity<Department>().DepartmentID;

            return new DepartmentCreate.Response(validationDetails, deptId);
        }
        // Create course
        public static CourseCreate.Response Handle(IRepository repository, CourseCreate.Request request)
        {
            // Validation now performed in the dispacther decorators (See AutoValidate<T> in the DomainBootstrapper class)

            var container = new EntityStateWrapperContainer();
            container.AddEntity(CourseFactory.Create(request.CommandModel));
            var validationDetails = repository.Save(container);

            var courseId = default(int?);
            if (!validationDetails.HasValidationIssues)
                courseId = container.FindEntity<Course>().CourseID;

            return new CourseCreate.Response(validationDetails, courseId);
        }
        // Modify instructor with course 
        public static InstructorModifyAndCourses.Response Handle(IRepository repository, InstructorModifyAndCourses.Request request)
        {
            var commandModel = request.CommandModel;
            var instructor = repository.GetEntity<Instructor>(
                p => p.ID == commandModel.InstructorId,
                new EagerLoadingQueryStrategy<Instructor>(
                    p => p.Courses,
                    p => p.OfficeAssignment));

            var container = instructor.Modify(repository, request.CommandModel);
            var validationDetails = repository.Save(container);

            return new InstructorModifyAndCourses.Response(validationDetails);
        }
        public void GetContact_ContactExists_ContactReturned(
            TestIndexUtils contactIndex,
            IRepository<ElasticContact> repo,
            ElasticContact contact,
            ISystemContext ctx)
        {
            using (contactIndex)
            {
                repo.Save(contact, ctx);

                var res = repo.Get(contact.Id, ctx);
                res.Should().NotBeNull();
                res.Id.Should().Be(contact.Id);
            }
        }
        public void GetContact_ContactDoesntExist_ContactNotReturned(
            TestIndexUtils contactIndex,
            IRepository<ElasticContact> repo,
            ElasticContact contact,
            ISystemContext ctx)
        {
            using (contactIndex)
            {
                // a little hacky - this is an easy way of ensuring the test index exists first.
                repo.Save(contact, ctx);

                var res = repo.Get(new Guid(), ctx);
                res.Should().BeNull();
            }
        }
Example #24
0
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<Customer>().As<ICustomer>();
            builder.RegisterType<LineItem>().As<ILineItem>();
            builder.RegisterType<Order>().As<IOrder>();
            builder.RegisterType<Product>().As<IProduct>();

            Container = builder.Build();

            _customerRepo = new Repository<Customer>();
            _customerRepo.Add(new Customer { FirstName = "Chris", LastName = "Cais" });
            _customerRepo.Add(new Customer { FirstName = "James", LastName = "Harden" });
            _customerRepo.Save();
        }
        // Update department
        #region Update department
        public static DepartmentUpdate.Response Handle(IRepository repository, DepartmentUpdate.Request request)
        {
            var validationDetails = Validator.ValidateRequest(request, repository);
            if (validationDetails.HasValidationIssues)
                return new DepartmentUpdate.Response(validationDetails);

            var commandModel = request.CommandModel;
            var currentDept = repository.GetEntity<Department>(
                p => p.DepartmentID == commandModel.DepartmentID,
                new AsNoTrackingQueryStrategy());

            var rowVersion = default(byte[]);
            var container = currentDept.Modify(request.CommandModel);
            validationDetails = repository.Save(container, dbUpdateEx => OnUpdateFailedFunc(repository, dbUpdateEx, commandModel, ref rowVersion));

            return new DepartmentUpdate.Response(validationDetails, rowVersion);
        }
        // Delete instructor
        public static InstructorDelete.Response Handle(IRepository repository, InstructorDelete.Request request)
        {
            var container = new EntityStateWrapperContainer();
            var depts = repository.GetEntities<Department>(p => p.InstructorID == request.CommandModel.InstructorId);
            foreach (var dept in depts)
                container.Add(dept.SetInstructorId(null));

            var deletedInstructor = repository.GetEntity<Instructor>(
                p => p.ID == request.CommandModel.InstructorId,
                new EagerLoadingQueryStrategy<Instructor>(
                    p => p.OfficeAssignment));

            container.Add(deletedInstructor.Delete());
            var validationDetails = repository.Save(container);

            return new InstructorDelete.Response(validationDetails);
        }
Example #27
0
        public virtual void setup()
        {
            _savedPosts = new List<Post>();

            var mongoRepository = new MongoRepository("blogspecs");
            mongoRepository.DeleteCollection<BlogSettings>();
            mongoRepository.DeleteCollection<Post>();

            _repository = mongoRepository;

            for (var i = 0; i < 10; i++)
            {
                var post = Post.CreatePost("Title" + i, "Body" + i, "BjartN", new List<Tag> {new Tag("tag"  + i), new Tag("tag" + (i+1))});
                _repository.Save(post);
                _savedPosts.Add(post);
            }
        }
        // Delete Department
        public static DepartmentDelete.Response Handle(IRepository repository, DepartmentDelete.Request request)
        {
            var validationDetails = Validator.ValidateRequest(request, repository);
            if (validationDetails.HasValidationIssues)
                return new DepartmentDelete.Response(validationDetails);

            var department = repository.GetEntity<Department>(
                p => p.DepartmentID == request.CommandModel.DepartmentID,
                new EagerLoadingQueryStrategy<Department>(
                    p => p.Administrator));

            var hasConcurrencyError = false;
            var container = department.Delete();
            validationDetails = repository.Save(container, dbUpdateConcurrencyExceptionFunc: dbUpdateEx =>
            {
                hasConcurrencyError = true;
                return new ValidationMessageCollection(new ValidationMessage(string.Empty, dbUpdateEx.ToString()));
            });

            return new DepartmentDelete.Response(validationDetails, hasConcurrencyError);
        }
        public JsonResult Create(BonusDto bonusDto)
        {
            BonusAggregate bonus;

            if (bonusDto.Amount <= 0)
                throw new ArgumentOutOfRangeException("Amount should be more than 0");

            if (bonusDto.EmployeeId <= 0)
                throw new ArgumentNullException("You should specify an existing employee");

            using (var dbContext = new DatabaseContext())
            {
                BonusesRepository = new BonusesRepository(dbContext);
                var employeeRepository = new EmployeesRepository(dbContext);
                bonus = new BonusFactory(employeeRepository).Create(bonusDto);

                BonusesRepository.Save(bonus);
            }

            return Json(bonus);
        }
Example #30
0
 public void TestInit()
 {
     repository = new DefaultRepository(fileStoreService, cacheStoreService);
     repository.Save(RepositoryTests.GetContentTypeCollection());
 }