public void CustomerRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            ICustomerRepository customerRepository = new CustomerRepository(unitOfWork);

            var countryId = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C");

            var customer = CustomerFactory.CreateCustomer("Felix", "Trend", countryId, new Address("city", "zipCode", "addressLine1", "addressLine2"));
            customer.Id = IdentityGenerator.NewSequentialGuid();

            customer.Picture = new Picture()
            {
                Id = customer.Id
            };

            //Act

            customerRepository.Add(customer);
            customerRepository.UnitOfWork.Commit();

            //Assert

            var result = customerRepository.Get(customer.Id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == customer.Id);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "TEST";

            var uow = new UnitOfWork();
            var customerRepository = new CustomerRepository(uow);
            var orderRepository = new OrderRepository(uow);

            Console.WriteLine("SIMPLE CRUD TEST APP");
            //FindAll TEST
            Console.WriteLine("FINDALL TEST");
            Console.WriteLine("List of Customers:");
            var customers = customerRepository.FindAll().ToList<Customer>();
            for (var index = 0; index < customers.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, customers[index].FullName));
            PressTo("CONTINUE");

            //Update TEST
            Console.WriteLine("UPDATE TEST");
            var customerEntity = customers[0];
            Console.WriteLine(string.Format("Customer current FirstName: {0}", customerEntity.FirstName));
            Console.WriteLine("ENTER Customer NEW FirstName: ");
            var newName = Console.ReadLine();
            var oldName = customerEntity.FirstName;
            customerEntity.FirstName = newName;
            Console.WriteLine("Update data? (Y/N): ");

            var keyPressed = Console.ReadKey(true).Key;
            while (keyPressed != ConsoleKey.Y && keyPressed != ConsoleKey.N) { keyPressed = Console.ReadKey(true).Key; }
            if (keyPressed == ConsoleKey.Y)
            {
                customerRepository.Update(customerEntity);
                uow.Commit();
                Console.WriteLine("Data updated!");
            }
            else
            {
                customerEntity.FirstName = oldName;
                Console.WriteLine("Change reverted!");
            }

            Console.WriteLine(string.Format("Customer Full Name: {0}", customerEntity.FullName));
            PressTo("CONTINUE");

            //Insert TEST
            Console.WriteLine("INSERT TEST");

            Console.WriteLine("ENTER NEW Customer FirstName: ");
            var newFirstName = Console.ReadLine();
            Console.WriteLine("ENTER NEW Customer LastName: ");
            var newLastName = Console.ReadLine();
            customerEntity = Customer.Create(newFirstName, newLastName);
            customerRepository.Add(customerEntity);
            uow.Commit();
            Console.WriteLine("NEW Customer CREATED!");
            Console.WriteLine("");
            Console.WriteLine("List of Customers:");
            customers = customerRepository.FindAll().ToList<Customer>();
            for (var index = 0; index < customers.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, customers[index].FullName));
            PressTo("CONTINUE");

            //Delete TEST
            Console.WriteLine("DELETE TEST");

            Console.WriteLine("ENTER Customer's number to DELETE: ");
            int deleteIndex;
            while (!int.TryParse(Console.ReadLine(), out deleteIndex) || (deleteIndex < 0 || deleteIndex > customers.Count))
            {
                Console.WriteLine("ENTER a valid Customer's number to DELETE: ");
            }
            customerEntity = customers[deleteIndex - 1];
            customerRepository.Remove(customerEntity);
            uow.Commit();
            Console.WriteLine(string.Format("Customer '{0}' was DELETED!", customerEntity.FullName));
            Console.WriteLine("");
            Console.WriteLine("List of Customers:");
            customers = customerRepository.FindAll().ToList<Customer>();
            for (var index = 0; index < customers.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, customers[index].FullName));
            PressTo("CONTINUE");

            //FindAll TEST [Orders]
            Console.WriteLine("FINDALL TEST [Orders]");
            Console.WriteLine("Enter Customer's number to display the list of Orders:");
            int customerIndex;
            while (!int.TryParse(Console.ReadLine(), out customerIndex) || (customerIndex < 0 || customerIndex > customers.Count))
            {
                Console.WriteLine("ENTER a valid Customer's number: ");
            }
            customerEntity = customers[customerIndex - 1];
            Console.WriteLine(string.Format("{0}'s ORDERS LIST:", customerEntity.FirstName));
            var orders = orderRepository.FindAllBy(customerEntity.Id).ToList<Order>();
            for (var index = 0; index < orders.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, orders[index].OrderDate));
            PressTo("CONTINUE");

            //FindAll TEST [Orders] with QueryObject
            Console.WriteLine("FINDALL TEST [Orders] with QueryObject");
            Console.WriteLine("Enter Customer's FirstName to display the list of Orders:");
            var customerFirstName = Console.ReadLine();

            var query = new QueryObject(typeof(Customer));
            query.AddCriteria(Criteria.Matches("FirstName", customerFirstName));
            var customerByQueryObject = query.Execute(uow);
            query = new QueryObject(typeof(Order));
            query.AddCriteria(Criteria.Matches("CustomerId", customerByQueryObject[0].Id.ToString()));
            var ordersByQueryObject = query.Execute(uow);
            Console.WriteLine(string.Format("{0}'s ORDERS LIST:", ((Customer)customerByQueryObject[0]).FirstName));
            for (var index = 0; index < ordersByQueryObject.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, ((Order)ordersByQueryObject[index]).OrderDate));
            PressTo("CONTINUE");

            PressTo("EXIT");
        }
        public void CustomerRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var customerRepository = new CustomerRepository(unitOfWork);

            var country = new Country("spain", "es-ES");
            country.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));

            var customer = CustomerFactory.CreateCustomer("Felix", "Trend","+3434","company", country, new Address("city", "zipCode", "addressLine1", "addressLine2"));
            customer.SetTheCountryReference(country.Id);


            //Act
            customerRepository.Add(customer);
            unitOfWork.Commit();
        }
        public void CustomerRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var customerRepository = new CustomerRepository(unitOfWork);

            var country = new Country("Spain","es-ES");
            country.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));

            

            var address =  new Address("city", "zipCode", "addressline1", "addressline2");

            var customer = CustomerFactory.CreateCustomer("Frank", "Frank","+3444","company", country,address);
            customer.SetTheCountryReference(country.Id);
            
            customerRepository.Add(customer);
            unitOfWork.Commit();

            //Act
            customerRepository.Remove(customer);
            unitOfWork.Commit();

            var result = customerRepository.Get(customer.Id);

            //Assert
            Assert.IsNull(result);
        }
Ejemplo n.º 5
0
 public bool Add(Customer customer)
 {
     return(_customerRepository.Add(customer));
 }
 public int AddCustomer(Customer item)
 {
     return(custumerRepository.Add(item));
 }
 public bool Add(string name, string contact, string address)
 {
     return(_customerRepository.Add(name, contact, address));
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            BeverageRepository                _beverageRepository                = new BeverageRepository();
            CustomerRepository                _customerRepository                = new CustomerRepository();
            EmployeeRepository                _employeeRepository                = new EmployeeRepository();
            ReservationRepository             _reservationRepository             = new ReservationRepository();
            TablePackageRepository            _tablePackageRepository            = new TablePackageRepository();
            ReservationTablePackageRepository _reservationTablePackageRepository = new ReservationTablePackageRepository();
            TableRepository         _tableRepository         = new TableRepository();
            VenueHourRepository     _venueHourRepository     = new VenueHourRepository();
            VenueEmployeeRepository _venueEmployeeRepository = new VenueEmployeeRepository();
            VenueRepository         _venueRepository         = new VenueRepository();

            Console.WriteLine("Seeding database ..");
            _beverageRepository.Truncate();
            _reservationTablePackageRepository.Truncate();
            _reservationRepository.Truncate();
            _tablePackageRepository.Truncate();
            _tableRepository.Truncate();
            _venueHourRepository.Truncate();
            _venueEmployeeRepository.Truncate();
            _venueRepository.Truncate();
            _customerRepository.Truncate();
            _employeeRepository.Truncate();

            Console.WriteLine("Seeding venues ..");
            Venue venue = new Venue {
                Name    = "Kongebaren",
                Address = "Gammel Kongevej 1",
                Zip     = 9000,
                City    = "Aalborg"
            };

            venue.Id = _venueRepository.Add(venue);

            Venue venue1 = new Venue {
                Name    = "Dronningenbaren",
                Address = "Gammel Kongevej 2",
                Zip     = 9000,
                City    = "Aalborg"
            };

            venue1.Id = _venueRepository.Add(venue1);

            Console.WriteLine("Seeding employees ..");
            Employee employee0 = new Employee
            {
                Name       = "Kongen Kongessen",
                Phone      = "+4598765432",
                Email      = "*****@*****.**",
                Password   = HashingHelper.GenerateHash("12345678"),
                EmployeeNo = 1,
                Title      = "Kongen",
                Salt       = HashingHelper.RandomString(20)
            };
            Employee employee1 = new Employee
            {
                Name       = "Dronningen Dronningensen",
                Phone      = "+4509876543",
                Email      = "*****@*****.**",
                Password   = HashingHelper.GenerateHash("12345678"),
                EmployeeNo = 1,
                Title      = "Dronningen",
                Salt       = HashingHelper.RandomString(20),
            };

            Employee employee2 = new Employee {
                Name       = "Prins Prinsen",
                Phone      = "+4539847837",
                Email      = "*****@*****.**",
                Password   = HashingHelper.GenerateHash("12345678"),
                EmployeeNo = 1,
                Title      = "Prinsen",
                Salt       = HashingHelper.RandomString(20),
            };

            employee0.Id = _employeeRepository.Add(employee0);
            employee1.Id = _employeeRepository.Add(employee1);
            employee2.Id = _employeeRepository.Add(employee2);

            Console.WriteLine("Seeding venue employees ..");
            _venueEmployeeRepository.Add(new VenueEmployee
            {
                VenueId     = venue.Id,
                EmployeeId  = employee0.Id,
                AccessLevel = 1
            });
            _venueEmployeeRepository.Add(new VenueEmployee
            {
                VenueId     = venue1.Id,
                EmployeeId  = employee1.Id,
                AccessLevel = 1
            });

            _venueEmployeeRepository.Add(new VenueEmployee {
                VenueId     = venue.Id,
                EmployeeId  = employee2.Id,
                AccessLevel = 1
            });

            _venueEmployeeRepository.Add(new VenueEmployee {
                VenueId     = venue1.Id,
                EmployeeId  = employee2.Id,
                AccessLevel = 1
            });

            Console.WriteLine("Seeding customers ..");
            string   salt      = HashingHelper.RandomString(20);
            Customer customer0 = new Customer {
                Name       = "Kunde Kundessen",
                Phone      = "+4512345678",
                Email      = "*****@*****.**",
                Salt       = salt,
                Password   = HashingHelper.GenerateHashWithSalt("12345678", salt),
                CustomerNo = 1,
            };

            salt = HashingHelper.RandomString(20);
            Customer customer1 = new Customer
            {
                Name       = "Gæst Gæstessen",
                Phone      = "+4587654321",
                Email      = "*****@*****.**",
                Salt       = salt,
                Password   = HashingHelper.GenerateHashWithSalt("87654321", salt),
                CustomerNo = 2
            };

            customer0.Id = _customerRepository.Add(customer0);
            customer1.Id = _customerRepository.Add(customer1);

            Console.WriteLine("Seeding tables ..");
            Table table0 = new Table {
                NoOfSeats = 4,
                Name      = "Vinderbordet",
                VenueId   = venue.Id,
            };
            Table table1 = new Table
            {
                NoOfSeats = 6,
                Name      = "Taberbordet",
                VenueId   = venue.Id
            };
            Table table2 = new Table {
                NoOfSeats = 7,
                Name      = "Det gode bord",
                VenueId   = venue1.Id,
            };
            Table table3 = new Table {
                NoOfSeats = 3,
                Name      = "Det dårlige bord",
                VenueId   = venue1.Id
            };

            table0.Id = _tableRepository.Add(table0);
            table1.Id = _tableRepository.Add(table1);
            table2.Id = _tableRepository.Add(table2);
            table3.Id = _tableRepository.Add(table3);

            Console.WriteLine("Seeding table packages ..");
            TablePackage tablePackage0 = new TablePackage {
                Name    = "Den dyre",
                Price   = 6000,
                VenueId = venue.Id,
            };
            TablePackage tablePackage1 = new TablePackage
            {
                Name    = "Den billige",
                Price   = 500,
                VenueId = venue.Id
            };
            TablePackage tablePackage2 = new TablePackage {
                Name    = "Den Gode",
                Price   = 4000,
                VenueId = venue1.Id,
            };
            TablePackage tablePackage3 = new TablePackage {
                Name    = "Den Den Dårlige",
                Price   = 300,
                VenueId = venue1.Id
            };

            tablePackage0.Id = _tablePackageRepository.Add(tablePackage0);
            tablePackage1.Id = _tablePackageRepository.Add(tablePackage1);
            tablePackage2.Id = _tablePackageRepository.Add(tablePackage2);
            tablePackage3.Id = _tablePackageRepository.Add(tablePackage3);

            Console.WriteLine("Seeding reservations ..");
            Reservation reservation0 = new Reservation
            {
                ReservationNo = 10001,
                DateTimeStart = Convert.ToDateTime("28/12-2019 20:00"),
                DateTimeEnd   = Convert.ToDateTime("29/12-2019 05:00"),
                State         = 1,
                CustomerId    = customer0.Id,
                VenueId       = venue.Id,
                TableId       = table0.Id,
                CreatedAt     = DateTime.Now,
                UpdatedAt     = DateTime.Now
            };
            Reservation reservation1 = new Reservation
            {
                ReservationNo = 10002,
                DateTimeStart = Convert.ToDateTime("31/12-2019 20:00"),
                DateTimeEnd   = Convert.ToDateTime("01/01-2020 05:00"),
                State         = 1,
                CustomerId    = customer1.Id,
                VenueId       = venue1.Id,
                TableId       = table1.Id,
                CreatedAt     = DateTime.Now,
                UpdatedAt     = DateTime.Now
            };

            reservation0.Id = _reservationRepository.Add(reservation0);
            reservation1.Id = _reservationRepository.Add(reservation1);
            _reservationTablePackageRepository.Add(new ReservationTablePackage
            {
                ReservationId  = reservation0.Id,
                TablePackageId = tablePackage0.Id
            });
            _reservationTablePackageRepository.Add(new ReservationTablePackage
            {
                ReservationId  = reservation1.Id,
                TablePackageId = tablePackage1.Id
            });
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            var newProduct1 = new Product {
                Name = "firstProduct"
            };
            var newProduct2 = new Product()
            {
                Name = "secondProduct"
            };
            var newCustomer1 = new Customer()
            {
                Name = "firstCustomer", Email = "*****@*****.**", Adress = "sadsaswwww", Id = Guid.NewGuid(), PhoneNumber = "0742757942"
            };
            var newCustomer2 = new Customer()
            {
                Name = "secondCustomer", Email = "*****@*****.**", Adress = "sdsaswwww", Id = Guid.NewGuid(), PhoneNumber = "0742757942"
            };
            var newCustomer3 = new Customer()
            {
                Name = "thirdCustomer", Email = "*****@*****.**", Adress = "sadsasww", Id = Guid.NewGuid(), PhoneNumber = "0742757942"
            };

            using (var dbCtx1 = new DbEntities())
            {
                var productRepo  = new ProductRepository <Product>(dbCtx1);
                var customerRepo = new CustomerRepository <Customer>(dbCtx1);


                productRepo.Add(newProduct1);
                productRepo.Add(newProduct2);

                customerRepo.Add(newCustomer1);
                customerRepo.Add(newCustomer2);
                customerRepo.Add(newCustomer3);

                var numberOfProducts  = dbCtx1.Products.Count();
                var numberOfCustomers = dbCtx1.Customers.Count();
                Console.WriteLine("Number of Customers: " + numberOfCustomers);
                Console.WriteLine("Number of Products: " + numberOfProducts);
            }

            using (var dbCtx2 = new DbEntities())
            {
                var userRepo         = new UserRepository <User>(dbCtx2);
                var organisationRepo = new OrganizationRepository <Organization>(dbCtx2);

                for (int i = 0; i < 10; ++i)
                {
                    userRepo.Add(new User()
                    {
                        Id = Guid.NewGuid(), FirstName = "asda", LastName = "SdSDS"
                    });
                }

                for (int i = 0; i < 5; ++i)
                {
                    organisationRepo.Add(new Organization()
                    {
                        Id = Guid.NewGuid(), Name = "dasxx", Description = "trololololoool"
                    });
                }
            }


            using (var dbCtx3 = new DbEntities())
            {
                //var userRepo = new UserRepository<User>(dbCtx3);
                //var organisationRepo = new OrganizationRepository<Organization>(dbCtx3);

                foreach (var user in dbCtx3.Users)
                {
                    Console.WriteLine(user.FirstName + " " + user.LastName);
                }

                foreach (var org in dbCtx3.Organizations)
                {
                    Console.WriteLine(org.Name + " " + org.Description);
                }

                var lazyQuary = dbCtx3.Organizations;

                foreach (var item in lazyQuary)
                {
                    Console.WriteLine($"{item.Name} has {item.AssignedUsers.Count} Assigned");
                }

                var eagerQuary = dbCtx3.Organizations.Include("AssignedUsers");

                foreach (var item in eagerQuary)
                {
                    Console.WriteLine($"{item.Name} has {item.AssignedUsers.Count} Assigned");
                }

                var explicitQuary = dbCtx3.Organizations.Include("AssignedUsers");

                foreach (var item in explicitQuary)
                {
                    var users = dbCtx3.Entry(item).Collection(c => c.AssignedUsers);
                    if (!users.IsLoaded)
                    {
                        users.Load();
                    }
                    Console.WriteLine($"{item.Name} has {item.AssignedUsers.Count} Assigned");
                }
                Console.ReadLine();
            }
        }
Ejemplo n.º 10
0
        public static void CreateNewCustomer()
        {
            var customer = new Customer("Jack", new DateTime(2015, 1, 20));

            _repository.Add(customer);
        }
Ejemplo n.º 11
0
        public IActionResult CreateCustomer(Customer customer)
        {
            _repo.Add(customer);

            return(Created($"/api/customers/{customer.Id}", customer));
        }
Ejemplo n.º 12
0
 public void Add_single_customer()
 {
     customer.Name = $"Customer-{nameof(Add_single_customer)}";
     customerRepository.Add(customer);
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            CustomerRepository repository = new CustomerRepository();
            Address            address1;
            Address            address2;
            Address            address3;

            setAddresses(out address1, out address2, out address3);

            Customer customer1;
            Customer customer2;
            Customer customer3;
            Customer internalCustomer = new Customer("Coffee and sandwiches", 0, Address.SHOP_ADDRESS);

            setCustomers(out customer1, out customer2, out customer3, address1, address2, address3);

            repository.Add(customer1);
            repository.Add(customer2);
            repository.Add(customer3);
            repository.Add(internalCustomer);

            titleMeessage("CUSTOMERS");
            Console.WriteLine(customer1);
            Console.WriteLine(customer2);
            Console.WriteLine(customer3);
            Console.WriteLine(internalCustomer);

            MenuItem[] menuItems = new MenuItem[10];

            setMenuItems(menuItems);

            titleMeessage("Menu Items");
            for (int i = 0; i < menuItems.Length; i++)
            {
                Console.WriteLine(menuItems[i]);
            }

            Order order1 = customer1.CreatePhoneOrder(address1);
            Order order2 = customer2.CreatePhoneOrder(address2);
            Order order3 = customer3.CreatePhoneOrder(address3);
            Order order4 = customer1.CreatePhoneOrder(address1);

            //Tying to change customer for order 4

            order4.Customer = customer3;
            order4.Customer = customer1;

            Order order5 = new Order();
            Order order6 = new Order();



            titleMeessage("Customer with empty orders");
            Console.WriteLine(customer1);
            Console.WriteLine(customer2);
            Console.WriteLine(customer3);
            Console.WriteLine(internalCustomer);

            //populate orders
            order1.AddOrderItem(menuItems[0]);
            order1.AddOrderItem(menuItems[1]);
            order1.AddOrderItem(menuItems[2]);
            order1.AddOrderItem(menuItems[2]);

            order2.AddOrderItem(menuItems[3]);
            order2.AddOrderItem(menuItems[3]);

            order3.AddOrderItem(menuItems[4]);
            order3.AddOrderItem(menuItems[5]);
            order3.AddOrderItem(menuItems[5]);

            order4.AddOrderItem(menuItems[6]);
            order4.AddOrderItem(menuItems[7]);

            order5.AddOrderItem(menuItems[7]);

            order6.AddOrderItem(menuItems[8]);
            order6.AddOrderItem(menuItems[9]);

            internalCustomer.AddOrder(order5);
            internalCustomer.AddOrder(order6);

            titleMeessage("Customer with  non empty orders");
            Console.WriteLine(customer1);
            Console.WriteLine(customer2);
            Console.WriteLine(customer3);
            Console.WriteLine(internalCustomer);

            //marked as delivered
            order1.Deliver();
            order2.Deliver();
            order3.Deliver();
            order4.Deliver();

            titleMeessage("Customer with all orders delivered");
            Console.WriteLine(customer1);
            Console.WriteLine(customer2);
            Console.WriteLine(customer3);
            Console.WriteLine(internalCustomer);

            titleMeessage("Saving then loading and displaying content");
            repository.Save("Customers.json");

            repository.Load("Customers.json");
            foreach (Customer customer in repository.Customers)
            {
                Console.WriteLine(customer);
            }
        }
Ejemplo n.º 14
0
 public void Add(Customer customer)
 {
     _customerRepository.Add(customer);
 }
Ejemplo n.º 15
0
 public JsonResult Add(Customers customer)
 {
     return(Json(customerRepository.Add(customer), JsonRequestBehavior.AllowGet));
 }
 public bool Add(Customer categoryModel)
 {
     return(_customerRepository.Add(categoryModel));
 }