public ActionResult Index()
        {
            List <Person> people = new List <Person>();

            using (PeopleDbContext context = new PeopleDbContext())
            {
                //CREATE AND FILL DATABASE
                if (context.People.Count() < 1)
                {
                    for (int i = 1; i < 500; i++)
                    {
                        context.People.Add(new Person {
                            FirstName = "FirstName" + i, LastName = "LastName" + i, Mark = new Mark {
                                Value = i
                            }
                        });
                    }
                    context.SaveChanges();
                }
                @ViewBag.totalPeople = context.People.Count();

                people = context.People.Include("Mark").OrderBy(x => x.Mark.Value).Take(10).ToList();
            }
            return(View(people));
        }
예제 #2
0
        public void GetPersonTest()
        {
            var options = new DbContextOptionsBuilder <PeopleDbContext>()
                          .UseInMemoryDatabase(databaseName: "PeopleTestDb")
                          .Options;

            using var context = new PeopleDbContext(options);
            context.Database.EnsureDeleted();
            var person = new Person {
                ID = 1, Name = "Putin", Rate = null
            };

            var controller = new PeopleApi.Controllers.PeopleController(context);

            var action = controller.PostPerson(person);

            Assert.IsInstanceOfType(action.Result, typeof(CreatedAtActionResult));

            var result = controller.GetPerson(1).Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            var okResult = result as OkObjectResult;
            var personR  = okResult.Value as Person;

            Assert.AreEqual(person, personR);
        }
예제 #3
0
 public void SetAsOnline(Guid userId, string signalRConnectionId)
 {
     try
     {
         using (var db = new PeopleDbContext())
         {
             var user = db.OnlineUserEntities.Find(userId);
             if (user != null)
             {
                 user.SignalRConnectionId = signalRConnectionId;
             }
             else
             {
                 db.OnlineUserEntities.Add(new OnlineUserEntity
                 {
                     Id = userId,
                     SignalRConnectionId = signalRConnectionId
                 });
             }
             db.SaveChanges();
         }
     }
     catch
     { }
 }
        public void test_1()
        {
            try
            {
                using (var context = new PeopleDbContext())
                {
                    var personId       = Guid.NewGuid();
                    var personDetailId = Guid.NewGuid();
                    var person         = Person.Create(personId);
                    person.PersonDetailOneToManies.Add(PersonDetailOneToMany.Create(personDetailId, person));
                    context.People.Add(person);
                    context.SaveChanges();

                    person.PersonDetailId = personDetailId;
                    context.SaveChanges();

                    var people  = context.People.ToList();
                    var details = context.PersonDetailOneToManies.ToList();
                }
            }
            catch (Exception ex)
            {
                var error = ex.InnerException?.Message;
                throw;
            }
        }
예제 #5
0
        public static void InitializeDbForTests(PeopleDbContext context)
        {
            var persons = new List <Person>
            {
                new Person
                {
                    PersonId     = 1,
                    Firstname    = "Some X 2",
                    Surname      = "XXXXX",
                    Gender       = Gender.Male,
                    EmailAddress = "Email Address"
                },
                new Person
                {
                    PersonId     = 2,
                    Firstname    = "Some X 2",
                    Surname      = "XXXXX",
                    Gender       = Gender.Female,
                    EmailAddress = "Email Address"
                }
            };

            context.Persons.AddRange(persons);

            context.SaveChanges();
        }
예제 #6
0
        public void GetPersonRatingTest()
        {
            var options = new DbContextOptionsBuilder <PeopleDbContext>()
                          .UseInMemoryDatabase(databaseName: "PeopleTestDb")
                          .Options;

            using var context = new PeopleDbContext(options);
            context.Database.EnsureDeleted();

            var rating1 = new Rating {
                PersonID = 1, UserID = "user1", Rate = 1
            };
            var rating2 = new Rating {
                PersonID = 1, UserID = "user2", Rate = 10
            };

            var controller = new PeopleApi.Controllers.RatingsController(context);

            var action1 = controller.PostRating(rating1);

            Assert.AreEqual(TaskStatus.RanToCompletion, action1.Status);
            var action2 = controller.PostRating(rating2);

            Assert.AreEqual(TaskStatus.RanToCompletion, action2.Status);

            var result = controller.GetRating(1).Result;

            var okResult = result as OkObjectResult;
            var rating   = okResult.Value as double?;

            Assert.IsNotNull(result);
            Assert.AreEqual(5.5, rating);
        }
예제 #7
0
파일: Program.cs 프로젝트: bngapiusr/Person
        private static void AddData()
        {
            using (var contx = new PeopleDbContext())
            {
                var p = new PersonInfo
                {
                    FirstName  = "Mike",
                    MiddleName = "J",
                    LastName   = "Laurance",
                    Email      = "*****@*****.**"
                };
                var c = new Customer
                {
                    CompanyName  = "Microsoft",
                    ContactTitle = "Manager",
                    //PersonInfoId = p.PersonInfoId //don't use the ids
                    PersonInfo = p
                };

                var e = new Employee
                {
                    HireDate = DateTime.UtcNow,
                    Title    = "Business Analyst",
                    //PersonInfoId = p.PersonInfoId //don't use the ids
                    PersonInfo = p
                };
                //Save data
                contx.PersonInfo.Add(p);
                contx.Customer.Add(c);
                contx.Employee.Add(e);
                contx.SaveChanges();
            }
        }
        public void test_1()
        {
            try
            {
                using (var context = new PeopleDbContext())
                {
                    context.People.RemoveRange(context.People);
                    context.Friendships.RemoveRange(context.Friendships);
                    context.SaveChanges();

                    var person1 = Person.Create(Guid.NewGuid());
                    var person2 = Person.Create(Guid.NewGuid());

                    context.People.Add(person1);
                    context.People.Add(person2);
                    context.Friendships.Add(Friendship.Create(person1.Id, person2.Id));
                    context.SaveChanges();

                    var result = context.Friendships.ToList();
                    var people = context.People.ToList();
                }
            }
            catch (Exception ex)
            {
                var error = ex.InnerException?.Message;
                throw;
            }
        }
예제 #9
0
 public PeopleService(
     PeopleDbContext context,
     IOptions <WSettings> wSettings
     )
 {
     _wSettings = wSettings.Value;
     Context    = context;
 }
예제 #10
0
        public static void Initialize(PeopleDbContext context)
        {
            context.Database.EnsureCreated();

            /*
             * Add Intitial records
             *
             */
            context.SaveChanges();
        }
예제 #11
0
        internal static void Initialize(PeopleDbContext context, RoleManager <IdentityRole> roleManager, UserManager <IdentityUser> userManager)
        {
            if (!roleManager.RoleExistsAsync("Admin").Result)
            {
                IdentityRole role = new IdentityRole("Admin");
                // Add custom properties
                roleManager.CreateAsync(role).Wait();
            }

            if (!roleManager.RoleExistsAsync("NormalUser").Result)
            {
                IdentityRole role = new IdentityRole("NormalUser");
                // Add custom properties
                roleManager.CreateAsync(role).Wait();
            }

            if (userManager.FindByNameAsync("Admin").Result == null)
            {
                IdentityUser user = new IdentityUser();
                user.Email    = "*****@*****.**";
                user.UserName = "******";

                IdentityResult result = userManager.CreateAsync(user, "!Sommar2019").Result;

                if (result.Succeeded)
                {
                    userManager.AddToRoleAsync(user, "Admin").Wait();
                }
            }

            if (userManager.FindByNameAsync("Mats").Result == null)
            {
                IdentityUser user = new IdentityUser();
                user.Email    = "*****@*****.**";
                user.UserName = "******";

                IdentityResult result = userManager.CreateAsync(user, "!Sommar2019").Result;

                if (result.Succeeded)
                {
                    userManager.AddToRoleAsync(user, "NormalUser").Wait();
                }
            }

            //---------------------------------------------------->

            // Userdata
            //context.SaveChanges();
        }
        public ActionResult NextPrev(PageInfo pageInfo)
        {
            List <Person> people = new List <Person>();

            using (PeopleDbContext context = new PeopleDbContext())
            {
                if (pageInfo.SortByValue)
                {
                    people = context.People.Include("Mark").OrderBy(x => x.Mark.Value).Skip(pageInfo.CurrentPageNumber * pageInfo.RowPerPage).Take(pageInfo.RowPerPage).ToList();
                }
                else
                {
                    people = context.People.Include("Mark").OrderBy(x => x.LastName).ThenByDescending(x => x.FirstName).Skip(pageInfo.CurrentPageNumber * pageInfo.RowPerPage).Take(pageInfo.RowPerPage).ToList();
                }
            }
            return(PartialView("PartialShowPeople", people));
        }
예제 #13
0
        public int?InsertPerson(PersonDto personEntity)
        {
            int?personId = default(int?);

            if (personEntity != null)
            {
                var sqlParams = new List <SqlParameter>();

                var personIdOutputParam = new SqlParameter()
                {
                    Direction     = System.Data.ParameterDirection.Output,
                    ParameterName = "@personId",
                    Value         = 0,
                    DbType        = System.Data.DbType.Int32
                };

                sqlParams.Add(personIdOutputParam);

                sqlParams.Add(new SqlParameter()
                {
                    ParameterName = "@personName",
                    Value         = personEntity.Name,
                });

                sqlParams.Add(new SqlParameter()
                {
                    ParameterName = "@registredOn",
                    Value         = personEntity.RegistredOn,
                });

                using (var context = new PeopleDbContext())
                {
                    var commandText = "exec [dbo].[InsertPerson] @personName, @registredOn, @personId OUTPUT";
                    var result      = context.Database.ExecuteSqlCommand(commandText, sqlParams.ToArray());

                    int newPersonId = 0;

                    if (int.TryParse(personIdOutputParam.Value.ToString(), out newPersonId))
                    {
                        personId = newPersonId;
                    }
                }
            }
            return(personId);
        }
예제 #14
0
        public void GetPersonNonRatingTest()
        {
            var options = new DbContextOptionsBuilder <PeopleDbContext>()
                          .UseInMemoryDatabase(databaseName: "PeopleTestDb")
                          .Options;

            using var context = new PeopleDbContext(options);
            context.Database.EnsureDeleted();

            var controller = new PeopleApi.Controllers.RatingsController(context);

            var result = controller.GetRating(1).Result;

            var okResult = result as OkObjectResult;
            var rating   = okResult.Value as double?;

            Assert.AreEqual(0.0, rating);
        }
예제 #15
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider services)
        {
            app.UseSwagger();
            app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", ApiName); c.RoutePrefix = ""; });

            app.UseDeveloperExceptionPage();

            app.UseCors(b => b.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());

            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseMvc();

            var db = services.GetService <PeopleDbContext>();

            db.Database.Migrate();
            PeopleDbContext.Seed(db);
        }
예제 #16
0
        public void GetPeopleTest()
        {
            var options = new DbContextOptionsBuilder <PeopleDbContext>()
                          .UseInMemoryDatabase(databaseName: "PeopleTestDb")
                          .Options;

            using var context = new PeopleDbContext(options);
            context.Database.EnsureDeleted();

            var rates = new List <Rating>()
            {
                new Rating {
                    PersonID = 1, UserID = "user1", Rate = 1
                },
                new Rating {
                    PersonID = 1, UserID = "user2", Rate = 10
                }
            };

            var person1 = new Person {
                ID = 1, Name = "Putin", Rate = rates
            };
            var person2 = new Person {
                ID = 2, Name = "Trump", Rate = null
            };

            var controller = new PeopleApi.Controllers.PeopleController(context);

            var action1 = controller.PostPerson(person1);

            Assert.IsInstanceOfType(action1.Result, typeof(CreatedAtActionResult));
            var action2 = controller.PostPerson(person2);

            Assert.IsInstanceOfType(action2.Result, typeof(CreatedAtActionResult));
            var result = controller.GetPeople().Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            var okResult = result as OkObjectResult;
            var people   = okResult.Value as IEnumerable <Person>;
            var count    = people.Count();

            Assert.IsNotNull(result);
            Assert.AreEqual(2, count);
        }
예제 #17
0
        public void SetAsOffline(Guid userId)
        {
            try
            {
                using (var db = new PeopleDbContext())
                {
                    var user = db.OnlineUserEntities.Find(userId);
                    if (user == null)
                    {
                        return;
                    }
                    db.OnlineUserEntities.Remove(user);

                    db.SaveChanges();
                }
            }
            catch
            { }
        }
예제 #18
0
파일: Program.cs 프로젝트: bngapiusr/Person
        static void Main(string[] args)
        {
            using (var context = new PeopleDbContext())
            {
                AddData();
                // AddExtraAuthorOk();

                var people = context.PersonInfo.ToList();

                //var book = context.Books.Include(p => p.AuthorLink)
                //    .Single(p => p.Title == "Java 2 ME(Micro Edition) is the client.");

                Console.WriteLine("getting a list of authors");
                foreach (var person in people)
                {
                    Console.WriteLine("The Person Name is: " + person.FirstName + "," + person.LastName + ".");
                }

                // pause the screen
                Console.ReadLine();
            }
        }
 public ActionResult AddNewPerson(Person person)
 {
     using (PeopleDbContext context = new PeopleDbContext())
     {
         try
         {
             context.People.Add(person);
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             string message = $"<b>Message:</b> {ex.Message}<br /><br />";
             message += $"<b>InnerExeption:</b> {ex.InnerException}<br /><br />";
             message += $"<b>StackTrace:</b> {ex.StackTrace}<br /><br />";
             message += $"<b>Source:</b> {ex.StackTrace}<br /><br />";
             message += $"<b>TargetSite:</b> {ex.StackTrace}<br /><br />";
             ModelState.AddModelError(string.Empty, message);
             return(View("Error"));
         }
     }
     return(RedirectToAction("Index"));
 }
예제 #20
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     PeopleDbContext Peopledb,
     IOptions <JwtIssuerOptions> JwtOptions,
     //IEmailSender emailSender,
     //ISmsSender smsSender,
     ILoggerFactory loggerFactory
     )
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _Peopledb      = Peopledb;
     _jwtOptions    = JwtOptions.Value;
     //_emailSender = emailSender;
     //_smsSender = smsSender;
     _logger             = loggerFactory.CreateLogger <AccountController>();
     _serializerSettings = new JsonSerializerSettings
     {
         Formatting = Formatting.Indented
     };
 }
예제 #21
0
 public DBPersonLanguageRepo(PeopleDbContext peopleDbContext)
 {
     _peopleDbContext = peopleDbContext;
 }
예제 #22
0
 public PeopleController(PeopleDbContext context)
 {
     _context = context;
 }
 public PhoneNumberController(PeopleDbContext peopleDbContext)
 {
     this.peopleDbContext = peopleDbContext;
 }
        // Just reuse another controller, and expose the endpoints in a
        // controller requiring Authorization.

        public ProtectedTeamsController(MetaDbContext teamUserDb, PeopleDbContext db)
            : base(teamUserDb, db)
        {
        }
예제 #25
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new PeopleDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <PeopleDbContext> >()))
            {
                if (context.Countries.Any())
                {
                    return;   // DB has been seeded
                }
                context.Countries.AddRange(
                    new Country
                {
                    Name = "Sweden"
                },
                    new Country
                {
                    Name = "Norway"
                },
                    new Country
                {
                    Name = "Denmark"
                },
                    new Country
                {
                    Name = "Finland"
                },
                    new Country
                {
                    Name = "Island"
                }
                    );

                context.SaveChanges();
            }

            using (var context = new PeopleDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <PeopleDbContext> >()))
            {
                if (context.Cities.Any())
                {
                    return;   // DB has been seeded
                }
                context.Cities.AddRange(
                    new City
                {
                    Name       = "Stockholm",
                    Population = "1 515 017",
                    CountryId  = 1
                },
                    new City
                {
                    Name       = "Gothenburg",
                    Population = "599 011",
                    CountryId  = 1
                },
                    new City
                {
                    Name       = "Malmoe",
                    Population = "316 588",
                    CountryId  = 1
                },
                    new City
                {
                    Name       = "Oslo",
                    Population = "1 000 467",
                    CountryId  = 2
                },
                    new City
                {
                    Name       = "Bergen",
                    Population = "255 464",
                    CountryId  = 2
                }
                    ,
                    new City
                {
                    Name       = "Stavanger",
                    Population = "222 697",
                    CountryId  = 2
                },
                    new City
                {
                    Name       = "Copenhagen",
                    Population = "1 320 629",
                    CountryId  = 3
                },
                    new City
                {
                    Name       = "Aarhus",
                    Population = "277 086",
                    CountryId  = 3
                },
                    new City
                {
                    Name       = "Odense",
                    Population = "179 601",
                    CountryId  = 3
                },
                    new City
                {
                    Name       = "Helsinki",
                    Population = "1 176 976",
                    CountryId  = 4
                },
                    new City
                {
                    Name       = "Tampere",
                    Population = "317 316",
                    CountryId  = 4
                },
                    new City
                {
                    Name       = "Turku",
                    Population = "254 671",
                    CountryId  = 4
                }

                    );

                context.SaveChanges();
            }

            using (var context = new PeopleDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <PeopleDbContext> >()))
            {
                if (context.Persons.Any())
                {
                    return;   // DB has been seeded
                }
                context.Persons.AddRange(
                    new Person
                {
                    FirstName = "Kalle",
                    LastName  = "Karlsson",
                    Email     = "*****@*****.**",
                    Phone     = "08123456",
                    CityId    = 1
                },
                    new Person
                {
                    FirstName = "Pelle",
                    LastName  = "Persson",
                    Email     = "*****@*****.**",
                    Phone     = "08123456",
                    CityId    = 1
                },
                    new Person
                {
                    FirstName = "Nisse",
                    LastName  = "Nilsson",
                    Email     = "*****@*****.**",
                    Phone     = "08123456",
                    CityId    = 1
                },
                    new Person
                {
                    FirstName = "Pelle",
                    LastName  = "Persson",
                    Email     = "*****@*****.**",
                    Phone     = "031123456",
                    CityId    = 2
                },
                    new Person
                {
                    FirstName = "Nisse",
                    LastName  = "Nilsson",
                    Email     = "*****@*****.**",
                    Phone     = "042123456",
                    CityId    = 3
                },

                    new Person
                {
                    FirstName = "Kalle",
                    LastName  = "Karlsson",
                    Email     = "*****@*****.**",
                    Phone     = "08123456",
                    CityId    = 4
                },
                    new Person
                {
                    FirstName = "Pelle",
                    LastName  = "Persson",
                    Email     = "*****@*****.**",
                    Phone     = "031123456",
                    CityId    = 5
                },
                    new Person
                {
                    FirstName = "Nisse",
                    LastName  = "Nilsson",
                    Email     = "*****@*****.**",
                    Phone     = "042123456",
                    CityId    = 6
                },

                    new Person
                {
                    FirstName = "Kalle",
                    LastName  = "Karlsson",
                    Email     = "*****@*****.**",
                    Phone     = "08123456",
                    CityId    = 7
                },
                    new Person
                {
                    FirstName = "Pelle",
                    LastName  = "Persson",
                    Email     = "*****@*****.**",
                    Phone     = "031123456",
                    CityId    = 8
                },
                    new Person
                {
                    FirstName = "Nisse",
                    LastName  = "Nilsson",
                    Email     = "*****@*****.**",
                    Phone     = "042123456",
                    CityId    = 9
                },

                    new Person
                {
                    FirstName = "Kalle",
                    LastName  = "Karlsson",
                    Email     = "*****@*****.**",
                    Phone     = "08123456",
                    CityId    = 10
                },
                    new Person
                {
                    FirstName = "Pelle",
                    LastName  = "Persson",
                    Email     = "*****@*****.**",
                    Phone     = "031123456",
                    CityId    = 11
                },
                    new Person
                {
                    FirstName = "Nisse",
                    LastName  = "Nilsson",
                    Email     = "*****@*****.**",
                    Phone     = "042123456",
                    CityId    = 12
                }



                    );


                context.SaveChanges();
            }
        }
예제 #26
0
 public HomeCountryRepository(PeopleDbContext peopleDbContext)
 {
     this.peopleDbContext = peopleDbContext;
 }
예제 #27
0
 public LanguagePersonRepository(PeopleDbContext peopleDbContext)
 {
     this.peopleDbContext = peopleDbContext;
 }
예제 #28
0
 public CountryService(PeopleDbContext peopleDBContext)
 {
     _db = peopleDBContext;
 }
예제 #29
0
 public NumberKindRepository(PeopleDbContext peopleDbContext)
 {
     this.peopleDbContext = peopleDbContext;
 }
예제 #30
0
        static void Main(string[] args)
        {
            var services = new ServiceCollection();

            services.AddTransient <PeopleDbContext>();
            var provider = services.BuildServiceProvider();

            _db = provider.GetService <PeopleDbContext>();

            //--- Cache data to List<String>
            var users = _db.Users.Select(u => u.Givenname.ToLower().Trim()).ToList();

            Term = "Jack".ToLower();

            if (args != null)
            {
                if (args.Length > 1)
                {
                    numberOfRequests = int.Parse(args[1]);
                }

                if (args.Length > 2)
                {
                    Term = args[2];
                    if (Term.Length < 3)
                    {
                        Console.WriteLine("Too short!");
                        return;
                    }
                }

                switch (args[0])
                {
                case "query":
                    TestToLowerQuery();
                    break;

                case "blaze":
                    TestBlaze(users);
                    break;

                case "blaze2":
                    TestBlaze2(users);
                    break;

                case "parallel":
                    TestBlazeParallel(users);
                    break;

                case "byte":
                    TestByte(users);
                    break;

                case "tolower":
                    TestToLower(users);
                    break;

                case "tolower2":
                    TestToLower2(users);
                    break;

                case "equal":
                    TestEqual(users);
                    break;

                case "equal2":
                    TestEqual2(users);
                    break;

                case "equal3":
                    TestEqual3(users);
                    break;

                case "equal4":
                    TestEqual4(users);
                    break;

                case "vector":
                    TestVector.Execute(numberOfRequests, users, Term);
                    break;

                case "long":
                    TestByLong.Execute(numberOfRequests, users, Term);
                    break;

                default:
                    break;
                }
            }
        }