public void Should_Create_CheckinTool_In_The_Database() { //Arrange var stuffContext = new StuffContext(); var personContext = new PersonsContext(); var stuffUow = new StuffUow(stuffContext); var checkinToolRepository = new CheckinToolRepository(stuffUow); var holderId = 4; var tool = stuffContext.Tools.Find(2); var companyArea = personContext.CompanyAreas.Find(2); var newCheckin = new CheckinTool { Tool = tool, EmployeeCompanyHolderId = holderId, CheckinDateTime = DateTime.Now, CompanyAreaId = companyArea.Id }; //Act checkinToolRepository.Add(newCheckin); //Assert stuffUow.Save(); }
private void InitContext() { if (_db == null) { var builder = new DbContextOptionsBuilder <PersonsContext>().UseInMemoryDatabase(); var context = new PersonsContext(builder.Options); var persons = Enumerable.Range(1, 10) .Select(i => new Person { FirstName = $"Person{i}", LastName = $"Last{i}", Identifiers = new List <Identifier> { new Identifier { Type = IdentifierTypes.Email, Value = $"Identifier{i}" }, new Identifier { Type = IdentifierTypes.Email, Value = $"Identifier{i+1}" } } }); context.Persons.AddRange(persons); int changed = context.SaveChanges(); _db = context; } }
public void Should_Create_Company() { try { var personContext = new PersonsContext(); var uow = new UnitOfWork<PersonsContext>(); var companyRepository = new CompanyRepository(uow); var company = new Company { Name = "P", Email = "*****@*****.**" }; companyRepository.Add(company); Assert.IsNotNull(personContext.Companies.FirstOrDefault(c => c.Name == "P")); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Console.WriteLine(("Property: {0} Error: {1}"), validationError.PropertyName, validationError.ErrorMessage); } } } }
static void TryPersonsContext() { using (var context = new PersonsContext()) { var person1 = new Person { FirstName = "Alexandra", MiddleName = "Ioana", LastName = "Ghidersa", TelephoneNumber = "0789369548" }; var person2 = new Person { FirstName = "Ana", MiddleName = "Maria", LastName = "Popescu", TelephoneNumber = "0789309549" }; context.People.AddRange(new Person[] { person1, person2 }); context.SaveChanges(); foreach (var person in context.People) { Console.WriteLine(person); } } }
public void EnsureFillingUpDB() { try { var csvFile = new FavouriteColorCSVFileRepository(); var test = csvFile.GetPeople(); PersonsContext pc = new PersonsContext(); //Dumb cleaning pc.Database.ExecuteSqlCommand("delete from [Person];"); pc.Database.ExecuteSqlCommand("delete from [Color];"); pc.Colors.AddRange(UtilColor.Colors); pc.Persons.AddRange(test); pc.SaveChanges(); Assert.IsTrue(true); } catch (Exception) { Assert.IsTrue(false); } }
public void Manually_Remove_Reference() { using (var personsContext = new PersonsContext(DbContextOptions)) { var him = new Person { Id = 1, Name = "Him", SpouseId = 2 }; var her = new Person { Id = 2, Name = "Her", SpouseId = 1 }; personsContext.Persons.Add(him); personsContext.Persons.Add(her); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { var him = personsContext.Persons.Find(1); var her = personsContext.Persons.Find(2); him.SpouseId = null; personsContext.SaveChanges(); her.SpouseId = null; personsContext.SaveChanges(); personsContext.Persons.Remove(him); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { Assert.Null(personsContext.Find <Person>(1)); } }
public void Run() { using (var db = new PersonsContext(Constants.ConnectionString)) { var person = new Person { Firstname = "Travis", LastName = "Howe" }; db.Persons.Add(person); db.SaveChanges(); } var options = new DbContextOptionsBuilder <PersonsContext>() .EnableDetailedErrors() .EnableSensitiveDataLogging() .LogTo(Console.WriteLine) .UseNpgsql(Constants.ConnectionString) .Options; using (var db = new PersonsContext(options)) { var customer = new Person { Firstname = "Edward", LastName = "Chester" }; db.Persons.Add(customer); db.SaveChanges(); } }
public void OnDelete_SetNull() { using (var personsContext = new PersonsContext(DbContextOptions)) { var him = new Person { Id = 1, Name = "Him", SpouseId = 2 }; var her = new Person { Id = 2, Name = "Her", SpouseId = 1 }; personsContext.Persons.Add(him); personsContext.Persons.Add(her); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { var him = personsContext.Persons.Find(1); personsContext.Persons.Remove(him); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { Assert.Null(personsContext.Find <Person>(1)); } }
public List <DisplayProfileModel> GetProfiles() { using (var dbContext = new PersonsContext()) { var profilesList = dbContext.GetProfile.SqlQuery("EXECUTE GetProfiles").ToListAsync().Result; return(profilesList); } }
public DisplayProfileModel GetProfile(long profileId) { using (var dbContext = new PersonsContext()) { var profile = dbContext.GetProfile.SqlQuery("EXECUTE GetProfile {0}", profileId).ToListAsync().Result.FirstOrDefault(); return(profile); } }
public UnitTest1() { using (var personsContext = new PersonsContext(DbContextOptions)) { personsContext.Database.EnsureDeleted(); personsContext.Database.EnsureCreated(); } }
public IEnumerable <Person> Get() { using (var db = new PersonsContext()) { var persons = db.persons.OrderBy(p => p.Id); return(persons.ToList()); } }
public bool UpdateProfile(UpdateProfileModel model) { var inId = new SqlParameter { ParameterName = "Id", Value = model.Id, DbType = System.Data.DbType.Int64, Direction = System.Data.ParameterDirection.Input }; var inFirstName = new SqlParameter { ParameterName = "FirstName", Value = model.FirstName, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var inLastName = new SqlParameter { ParameterName = "LastName", Value = model.LastName, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var inPatronymic = new SqlParameter { ParameterName = "Patronymic", Value = model.Patronymic, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var inPhoneNumber = new SqlParameter { ParameterName = "PhoneNumber", Value = model.PhoneNumber, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var outResult = new SqlParameter { ParameterName = "Result", DbType = System.Data.DbType.Boolean, Direction = System.Data.ParameterDirection.Output }; var sql = "exec UpdateProfile @Id, @FirstName, @LastName, @Patronymic, @PhoneNumber, @Result OUT"; using (var dbContext = new PersonsContext()) { _ = dbContext.Database.ExecuteSqlCommand(sql, inId, inFirstName, inLastName, inPatronymic, inPhoneNumber, outResult); } if (!Boolean.TryParse(outResult.Value.ToString(), out bool result)) { return(false); } return(result); }
public IEnumerable <string> Get() { using (var db = new PersonsContext()) { var persons = db.persons.OrderBy(p => p.Id).ToList <Person>(); List <string> test = persons.Select(p => p.Name).ToList(); return(test); } }
/// <summary> /// Constructor /// </summary> /// <param name="db"></param> public PersonController(PersonsContext db) { _db = db; Mapper.Initialize(cfg => { cfg.CreateMap <Person, PersonModel>(); cfg.CreateMap <Identifier, IdentifierModel>(); }); }
private Event Map(StorePersonCommand cmd) { var person_avatar_data = new PersonAvatarData() { Person_Id = cmd.Id, Avatar = cmd.Avatar }; var person_context = new PersonsContext(cmd.Id, nameof(PersonsContext)); return(new PersonAvatarStored(nameof(PersonAvatarStored), person_context, person_avatar_data)); }
public long AddProfile(AddProfileModel model) { var inFirstName = new SqlParameter { ParameterName = "FirstName", Value = model.FirstName, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var inLastName = new SqlParameter { ParameterName = "LastName", Value = model.LastName, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var inPatronymic = new SqlParameter { ParameterName = "Patronymic", Value = model.Patronymic, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var inPhoneNumber = new SqlParameter { ParameterName = "PhoneNumber", Value = model.PhoneNumber, DbType = System.Data.DbType.String, Direction = System.Data.ParameterDirection.Input }; var outResultProfileId = new SqlParameter { ParameterName = "ResultProfileId", DbType = System.Data.DbType.Int64, Direction = System.Data.ParameterDirection.Output }; var sql = "exec AddProfile @FirstName, @LastName, @Patronymic, @PhoneNumber, @ResultProfileId OUT"; using (var dbContext = new PersonsContext()) { _ = dbContext.Database.ExecuteSqlCommand(sql, inFirstName, inLastName, inPatronymic, inPhoneNumber, outResultProfileId); } if (!long.TryParse(outResultProfileId.Value.ToString(), out long result)) { return(0); } return(result); }
static void Main(string[] args) { using (context = new PersonsContext()) { if (context.Persons.Count() <= 0) { context.Persons.Add(new Person("test1", "1")); context.Persons.Add(new Person("test2", "2")); context.Persons.Add(new Person("test3", "3")); context.SaveChanges(); } context.Persons.Load(); } IPAddress ip = IPAddress.Parse("127.0.0.1"); const int PORT = 2020; Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { IPEndPoint ep = new IPEndPoint(ip, PORT); socket.Bind(ep); socket.Listen(10);//max queue 10 clients while (true) { const int SIZE = 1024; Socket client = socket.Accept(); byte[] buffer = new byte[SIZE]; int countBytes = 0; do { countBytes = client.Receive(buffer); }while (client.Available > 0); string data = Encoding.UTF8.GetString(buffer, 0, countBytes); Person[] tmp; using (context = new PersonsContext()) { tmp = context.Persons.Where(x => x.Name.Contains(data)).ToArray(); } byte[] response = Formatter.Serialize(tmp); client.Send(response); client.Shutdown(SocketShutdown.Both); client.Close(); } } catch (SocketException e) { Console.WriteLine(e.Message); }; }
public Output Process(IMessage input, IMessageContext model) { var cmd = input as DeletePersonCommand; var ctx_model = model as DeletePersonCommandContextModel; if (ctx_model.Person_existing) { var person_context = new PersonsContext(cmd.Id, nameof(PersonsContext)); var ev = new PersonDeleted(nameof(PersonDeleted), person_context, new PersonDeleteData() { Id = cmd.Id }); return(new CommandOutput(new Success(), new Event[] { ev })); } return(new CommandOutput(new Failure("Person existiert nicht"))); }
public void DeleteProfile(long profileId) { var inProfileId = new SqlParameter { ParameterName = "ProfileId", Value = profileId, DbType = System.Data.DbType.Int64, Direction = System.Data.ParameterDirection.Input }; var sql = "exec DeleteProfile @ProfileId"; using (var dbContext = new PersonsContext()) { _ = dbContext.Database.ExecuteSqlCommand(sql, inProfileId); } return; }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new PersonsContext( serviceProvider.GetRequiredService < DbContextOptions <PersonsContext> >())) { // Look for any movies. if (context.persons.Any()) { return; // DB has been seeded } context.persons.AddRange( new Person { age = 20, hair_color = "Brown", eye_color = "Green", }, new Person { age = 23, hair_color = "Pink", eye_color = "Blue", }, new Person { age = 22, hair_color = "Black", eye_color = "Red", }, new Person { age = 50, hair_color = "Red", eye_color = "Brown", } ); context.SaveChanges(); } }
private Event Map(StorePersonCommandContextModel cmd_model, StorePersonCommand cmd) { var person_data = new PersonData() { Person = new Person() { Id = cmd.Id, First_name = cmd.FirstName, Last_name = cmd.LastName } }; var person_context = new PersonsContext(person_data.Person.Id, nameof(PersonsContext)); if (cmd_model.Person_existing) { return(new PersonUpdated(nameof(PersonUpdated), person_context, person_data)); } return(new PersonStored(nameof(PersonStored), person_context, person_data)); }
public void Should_Update_ToolsLocalization_In_Company() { try { var personContext = new PersonsContext(); var uow = new UnitOfWork<PersonsContext>(); var companyRepository = new CompanyRepository(uow); var CompanyAreaRepository = new CompanyAreaRepository(uow); var CompanyArea = CompanyAreasDummies.CreateListOfCompanyAreas().FirstOrDefault(t => t.Id == 2); var company = companyRepository.GetById(4); CompanyAreaRepository.Add(CompanyArea); uow.Save(); company.CompanyAreas.Add(CompanyAreaRepository.GetById(6)); companyRepository.Update(company); uow.Save(); Assert.IsNotNull(personContext.Companies.FirstOrDefault(c => c.Name == "Portoverano")); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Console.WriteLine(("Property: {0} Error: {1}"), validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception ex) { Console.WriteLine((" Error: {0}"), ex.Message); } }
public void SetUp() { using var db = new PersonsContext(Constants.ConnectionString); db.Database.EnsureCreated(); }
/// <summary> /// Constructor /// </summary> /// <param name="db"></param> public PersonController(PersonsContext db) { _db = db; }
public PersonsDetailsModel(PersonsContext context) { _context = context; }
public PhonesRepository(PersonsContext context) { _context = context; }
public PersonsRepository(PersonsContext personCtx) { _context = personCtx; }
public PeopleController(PersonsContext context) { _context = context; }
public PersonsManager(PersonsContext context) { _personsContext = context; }
public void TearDown() { using var db = new PersonsContext(Constants.ConnectionString); db.Persons.Clear(); db.SaveChanges(); }
//public void OnGetByName(string name) //{ // DisplayedPeople = people.Where(x => x.Name.Contains(name)).ToList(); //} //public IActionResult OnGetByAge(int age) //{ // DisplayedPeople = people.Where(x => x.Age == age).ToList(); // return Page(); //} public PersonModel(PersonsContext dbcontext) { _db = dbcontext; }
public IndexModel(PersonsContext context) { _context = context; }