Beispiel #1
0
        public void Hire(Person person, EmploymentType employmentType)
        {
            var employee = new Employee {
                Person = person, EmploymentType = employmentType, StartDate = DateTime.UtcNow
            };
            var employmentContract = EmploymentContract.CreateNew(employee, this, employmentType);

            Emit(new EmploymentStarted(this, employee, default));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Ograniczenie unique//

            Subject s1 = new Subject("Relacyjne bazy danych", "RBD", 2);
            Subject s2 = new Subject("Systemy baz danych", "SBD", 3);

            //Subject s3 = new Subject("Systemy baz danych", "RBD", 3); //błąd, powielone nazwy

            Console.WriteLine("---Ograniczenie atrybutu i własne--\n");

            User u1 = new User("Thomas", "password", new DateTime(2020, 05, 11));

            //User u2 = new User("Robson", "master", new DateTime(2019, 09, 30)); //błąd, hasło poniżej 8 znaków

            u1.ChangeUsername("Thomas1");
            //u1.ChangeUsername("Thomas123"); błąd, druga zmiana nazwy użytkownika

            //Ograniczenie ordered//

            Line l1  = new Line(179, LineType.Normal);
            Line l2  = new Line(192, LineType.Normal);
            Stop st1 = new Stop("Os.Kabaty", 2);
            Stop st2 = new Stop("Metro Kabaty", 4);
            Stop st3 = new Stop("Mielczarskiego", 1);

            l1.AddStop(st1);
            l2.AddStop(st1);
            l1.AddStop(st2);
            l1.AddStop(st3);
            //l1.AddStop(st3); błąd, drugie dodanie tej samej stacji do linii

            Console.WriteLine(l1.ShowStops());
            Console.WriteLine(st1.ShowLines() + "\n");

            Console.WriteLine("---Ograniczenie bag---\n");

            Driver  d1 = new Driver("Tomasz", "Kowalski", "Poland");
            Circuit c1 = new Circuit("Monza", 5.793, 11);

            Lap lap1 = new Lap(d1, c1, new TimeSpan(0, 0, 2, 18, 343), new DateTime(2019, 06, 14, 10, 23, 47));
            Lap lap2 = new Lap(d1, c1, new TimeSpan(0, 0, 2, 17, 891), new DateTime(2019, 06, 14, 10, 30, 04));
            Lap lap3 = new Lap(d1, c1, new TimeSpan(0, 0, 2, 20, 164), new DateTime(2019, 07, 05, 18, 04, 36));

            Console.WriteLine(d1.ShowTimes());
            Console.WriteLine(c1.ShowTimes());
            Console.WriteLine(d1.LapsOnCircuit(c1));

            Console.WriteLine("---Ograniczenie subset---\n");

            Team   t1 = new Team("FC Barcelona", "Spain", 1989);
            Player p1 = new Player("Leo", "Messi", "Argentina", new DateTime(1987, 06, 24));

            Team   t2 = new Team("Real Madrid", "Spain", 1902);
            Player p2 = new Player("Sergio", "Ramos", "Spain", new DateTime(1986, 03, 30));

            t1.SignPlayer(p1);
            t2.SignPlayer(p2);

            t1.SetCaptain(p1);
            t2.SetCaptain(p2);

            Console.WriteLine(t1.GetCaptainInfo());
            Console.WriteLine(t2.GetCaptainInfo());

            //t1.SetCaptain(p2); //błąd, gracz p2 nie jest zawodnikiem t1
            t2.ReleasePlayer(p2);

            t1.SignPlayer(p2);
            t1.SetCaptain(p2);

            Console.WriteLine(t1.GetCaptainInfo() + "\n");

            //Ograniczenie XOR/

            Employee           e1  = new Employee("Marek", "Nowak", new DateTime(1996, 10, 17));
            EmploymentContract ec1 = new EmploymentContract("Junior C# Developer", 3000, new DateTime(2021, 03, 15), new DateTime(2024, 03, 15), 40, 90, e1);
            //MandateContract mc1 = new MandateContract("Create mobile app", 5000, new DateTime(2021, 05, 13), new DateTime(2021, 08, 13), e1); //błąd, pracownik ma już ważną umowę o pracę
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <CarPurchaseContract>()
            .HasKey(t => new { t.CarId, t.PurchaseContractId });

            modelBuilder.Entity <CarPurchaseContract>()
            .HasOne(sc => sc.Car)
            .WithMany(s => s.CarPurchaseContracts)
            .HasForeignKey(sc => sc.CarId);

            modelBuilder.Entity <CarPurchaseContract>()
            .HasOne(sc => sc.PurchaseContract)
            .WithMany(c => c.CarPurchaseContracts)
            .HasForeignKey(sc => sc.PurchaseContractId);


            ////Конфигурация, заполняем таблицу ролей и добавляем админа
            //string adminRoleName = "admin";
            //string userRoleName = "user";
            //string employeeRoleName = "employee";

            //string adminEmail = "*****@*****.**";
            //string adminPassword = "******";

            //// добавляем роли
            //Role adminRole = new Role { Id = 1, Name = adminRoleName };
            //Role userRole = new Role { Id = 2, Name = userRoleName };
            //Role employeeRole = new Role { Id = 3, Name = employeeRoleName };

            Position admin = new Position()
            {
                Id = 1, Name = "admin"
            };
            Position director = new Position()
            {
                Id = 2, Name = "alex27super"
            };

            modelBuilder.Entity <Position>().HasData(admin, director);

            //User adminUser = new User { Id = 1, Firstname = "Oleksiy", Surname = "Garnik", Patronymic = "Igorovich", Email = adminEmail, Password = adminPassword, RoleId = adminRole.Id };

            //modelBuilder.Entity<Role>().HasData(new Role[] { adminRole, userRole, employeeRole });
            EmploymentContract lol = new EmploymentContract()
            {
                Id = 1, Salary = 300, PositionId = admin.Id
            };

            modelBuilder.Entity <EmploymentContract>().HasData(lol);

            ContactInfo cinfo = new ContactInfo()
            {
                Id = 1, Phone = "0971844085"
            };

            modelBuilder.Entity <ContactInfo>().HasData(cinfo);

            Employee adminUser = new Employee {
                Id    = 1, Name = "Leha", Surname = "Garnich", Patronymic = "Igorovich",
                Age   = 20, ContactInfoId = cinfo.Id,
                Email = "*****@*****.**", Password = "******", EmploymentContractId = lol.Id
            };


            modelBuilder.Entity <Employee>().HasData(new Employee[] { adminUser });

            base.OnModelCreating(modelBuilder);
        }
Beispiel #4
0
 public static Employee WithContract(this Employee employee, EmploymentContract contract)
 {
     employee.Contract = contract;
     return(employee);
 }
Beispiel #5
0
 public static EmploymentContract Per(this EmploymentContract contract, TimeSpan salaryUnit)
 {
     contract.SalaryUnit = salaryUnit;
     return(contract);
 }
Beispiel #6
0
 public static EmploymentContract Earning(this EmploymentContract contract, int salaryPerUnit)
 {
     contract.SalaryPerUnit = salaryPerUnit;
     return(contract);
 }