public void Insert(Departament item)
        {
            Departament newDep = new Departament()
            {
                Name = item.Name
            };

            _context.Departament.Add(newDep);
            _context.SaveChanges();
        }
        public void Insert(Company item)
        {
            Company newCompany = new Company()
            {
                Name = item.Name
            };

            _context.Company.Add(newCompany);
            _context.SaveChanges();
        }
Exemple #3
0
        public void Insert(Employee item)
        {
            Employee newEmployee = new Employee()
            {
                Name        = string.Concat(item.FirstName, " ", item.Departament, " ", item.SecondName),
                FirstName   = item.FirstName,
                SecondName  = item.SecondName,
                Patronymic  = item.Patronymic,
                Departament = item.Departament,
                User        = item.User,
                IsDeleted   = false
            };

            _context.Employee.Add(newEmployee);
            _context.SaveChanges();
        }
        public void Insert(Contracts item)
        {
            Contracts newContract = new Contracts()
            {
                DateStart   = item.DateStart,
                DateEnd     = item.DateEnd,
                DocNumber   = item.DocNumber,
                Departament = _context.Departament.FirstOrDefault(c => c.Id == item.Departament).Id,
                Partner     = _context.Company.FirstOrDefault(c => c.Id == item.Partner).Id,
                FileName    = item.FileName,
                Files       = item.Files,
                Responsible = _context.Employee.FirstOrDefault(c => c.Id == item.Responsible).Id,
                Company     = _context.Company.FirstOrDefault(c => c.Id == item.Company).Id
            };

            _context.Contracts.Add(newContract);
            _context.SaveChanges();
        }
Exemple #5
0
        public static void Initialize(DocsDbContext context)
        {
            context.Database.EnsureCreated();
            if (!context.Departament.Any())
            {
                var deps = new Departament[]
                {
                    new Departament()
                    {
                        Name = "Відділ ІТ"
                    },
                    new Departament()
                    {
                        Name = "Торговий"
                    },
                    new Departament()
                    {
                        Name = "Юристи"
                    }
                };
                foreach (var item in deps)
                {
                    context.Departament.Add(item);
                }
                context.SaveChanges();
            }
            if (!context.Employee.Any())
            {
                var employee = new Employee[]
                {
                    new Employee()
                    {
                        Name        = "Максим Біловус",
                        FirstName   = "Максим",
                        SecondName  = "Біловус",
                        Departament = context.Departament.FirstOrDefault(c => c.Name == "Відділ ІТ").Id
                    }
                };
                foreach (var item in employee)
                {
                    context.Employee.Add(item);
                }
                context.SaveChanges();
            }
            if (!context.Company.Any())
            {
                var companies = new Company[]
                {
                    new Company()
                    {
                        Name = "24 Карата"
                    },
                    new Company()
                    {
                        Name = "Діадема"
                    },
                    new Company()
                    {
                        Name = "Тіара"
                    },
                    new Company()
                    {
                        Name = "Вінтелепорт"
                    },
                    new Company()
                    {
                        Name = "Датагруп"
                    },
                    new Company()
                    {
                        Name = "Укртелеком"
                    }
                };
                foreach (var item in companies)
                {
                    context.Company.Add(item);
                }
                context.SaveChanges();
            }

            //var username = "******";
            //if (context.Users.Count(x => x.Email == username) == 0)
            //{
            //    var user = context.Users.FirstOrDefault(u => u.UserName == username);
            //    if (user == null)
            //    {
            //        var hashedPassword = new PasswordHasher<IdentityUser>().HashPassword(null, username);
            //        user = new IdentityUser()
            //        {
            //            UserName = username,
            //            Email = username,
            //            EmailConfirmed = true,
            //            LockoutEnabled = true,
            //            NormalizedEmail = username,
            //            NormalizedUserName = username,
            //            PasswordHash = hashedPassword
            //        };
            //        context.Users.Add(user);

            //    }
            //}
            //var roleAdmin = "Admin";
            //if (context.Roles.Count(x => x.Name == roleAdmin) == 0)
            //{
            //    var role = context.Roles.FirstOrDefault(u => u.Name == roleAdmin);
            //    if (role == null)
            //    {
            //        role = new IdentityRole()
            //        {
            //            Name = roleAdmin
            //        };
            //        context.Roles.Add(role);
            //    }
            //}
            //if (!context.UserRoles.Any())
            //{
            //    context.UserRoles.Add(new IdentityUserRole<string>()
            //    {
            //        UserId = context.Users.FirstOrDefault(u => u.UserName == username)?.Id,
            //        RoleId = context.Roles.FirstOrDefault(u => u.Name == roleAdmin)?.Id
            //    }
            //    );
            //}
        }