public PartialViewResult GetCitizensByString(string txtSearch) { txtSearch = txtSearch.Trim(); PhoneBookDbContext db = new PhoneBookDbContext(); //if string is null or empty - show the first page of the contacts from db if (string.IsNullOrEmpty(txtSearch)) { return(PartialView("_Citizen", db.spGetContacts(1).ToList())); } else { List <Citizen> citizens = new List <Citizen>(); citizens = db.tblCitizens.Where(c => c.Name.Contains(txtSearch)).OrderBy(o => o.Name).ToList(); if (citizens.Count > 0) { //if any contact mathes - show it through the partial view return(PartialView("_Citizen", citizens)); } else { //Show a message to user that there isn't any contacts match through a partial view return(PartialView("_SomethingWrong", txtSearch)); } } }
public bool PersonExists(Guid personId) { using (var context = new PhoneBookDbContext(_dbConfiguration)) { return(context.People.Any(p => p.Id == personId)); } }
public async Task <Person> GetPersonById(Guid personId) { using (var context = new PhoneBookDbContext(_dbConfiguration)) { return(await context.People.FirstOrDefaultAsync(p => p.Id == personId)); } }
public async Task <IEnumerable <Person> > GetPeople() { using (var context = new PhoneBookDbContext(_dbConfiguration)) { return(await context.People.ToListAsync()); } }
public PhoneBookManager() { this.phoneBook = new List <PhoneUser>(); this.dbContext = new PhoneBookDbContext(); this.checkPhoneNormalBg = new PhoneNumberCheck(); this.Load(); }
public Entities.ContactEntity.Contact GetById(int contactId) { Entities.ContactEntity.Contact contact = new Entities.ContactEntity.Contact(); PhoneBookDbContext db = new PhoneBookDbContext(); contact = db.Contacts.FirstOrDefault(c => c.ContactId == contactId); return(contact); }
public void Delete(int contactId) { PhoneBookDbContext db = new PhoneBookDbContext(); var contact = GetById(contactId); db.Remove(contact); db.SaveChanges(); }
public int Add(Entities.ContactEntity.Contact contact) { PhoneBookDbContext db = new PhoneBookDbContext(); var result = db.Add(contact); db.SaveChanges(); return(result.Entity.ContactId); }
public ReportsController(PhoneBookDbContext dbContext, IMediator mediator, IBusPublisher busPublisher) { _dbContext = dbContext; _mediator = mediator; BusPublisher = busPublisher; }
public CreatePersonEmailCommandHandler(PhoneBookDbContext dbContext, ILogger <CreatePersonCommandHandler> logger, IBusPublisher busPublisher) { _logger = logger; _busPublisher = busPublisher; _dbContext = dbContext; }
public Entities.ContactEntity.Contact Update(Entities.ContactEntity.Contact contact) { PhoneBookDbContext db = new PhoneBookDbContext(); db.Contacts.Update(contact); db.SaveChanges(); return(contact); }
public List <Entities.ContactEntity.Contact> GetAll() { List <Entities.ContactEntity.Contact> contacts = new List <Entities.ContactEntity.Contact>(); PhoneBookDbContext db = new PhoneBookDbContext(); contacts = db.Contacts.ToList(); return(contacts); }
public DeletePersonInformationCommandHandler(PhoneBookDbContext dbContext, ILogger <CreatePersonCommandHandler> logger, IBusPublisher busPublisher) { _logger = logger; _busPublisher = busPublisher; _dbContext = dbContext; }
public ActionResult <People> AddPeople([FromBody] People incomingPeople) { var db = new PhoneBookDbContext(); db.People.Add(incomingPeople); db.SaveChanges(); return(incomingPeople); }
public List <ContactDto> GetContacts() { using (var db = new PhoneBookDbContext()) { return(db.Contacts .Select(MappingExtensions.ToDto) .ToList()); } }
private async Task InitDatabase() { var dbConf = ViewModelLocator.Resolve <IDbConfiguration>(); using (var context = new PhoneBookDbContext(dbConf)) { await context.Database.EnsureCreatedAsync(); } }
public ActionResult Index(int page = 1, string successMessage = "") { if (!string.IsNullOrEmpty(successMessage)) { ViewData["successMessage"] = successMessage; } PhoneBookDbContext db = new PhoneBookDbContext(); return(View(db.spGetContacts(page).ToList())); }
public ActionResult <IEnumerable <People> > GetAction() { // query my database var db = new PhoneBookDbContext(); //SELECT * FROM People var results = db.People.OrderBy(people => people.FirstName); //return the results return(results.ToList()); }
public static void SeedHostDb(PhoneBookDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); }
public bool DeleteContact([FromBody] int id) { using (var db = new PhoneBookDbContext()) { var contact = db.Contacts.FirstOrDefault(c => c.Id == id); db.Contacts.Remove(contact); db.SaveChanges(); return(true); } }
protected MemoryDbContext() { _connection = new SqliteConnection(InMemoryConnectionString); _connection.Open(); var options = new DbContextOptionsBuilder <PhoneBookDbContext>() .UseSqlite(_connection) .Options; dbContext = new PhoneBookDbContext(options); dbContext.Database.EnsureCreated(); }
//delete a contact with id, given as a parameter public ActionResult DeleteContact(int citizenToDelId) { PhoneBookDbContext db = new PhoneBookDbContext(); Citizen citizenToDelete = db.tblCitizens.Single(c => c.CitizenId == citizenToDelId); if (citizenToDelete != null) { db.tblCitizens.Remove(citizenToDelete); db.SaveChanges(); } return(RedirectToAction("Index")); }
public EmployeeIdValidator(PhoneBookDbContext context, ILogger <EmployeeIdValidator> logger) { _context = context; _logger = logger; RuleSet("CheckExistingEmployeeIdValidation", () => { RuleFor(x => x) .MustAsync( (o, s, token) => CheckExistingEmployeeId(o) ).WithMessage("A employee with the Id not exists, check the Id!"); }); }
public async Task <Person> AddPerson(Person person) { using (var context = new PhoneBookDbContext(_dbConfiguration)) { person.Id = Guid.NewGuid(); await context.People.AddAsync(person); await context.SaveChangesAsync(); return(person); } }
protected override void Seed(PhoneBook.Data.PhoneBookDbContext context) { PhoneBookDbContext ctx = new PhoneBookDbContext(); ctx.PhoneNumbers.Add(new Models.PhoneNumber { Phone = "0893454345", UserName = "******", Information = "Lorem ipsun dolor sit amet", CreatedAt = DateTime.Now, }); ctx.SaveChanges(); }
public InMemoryDatabase() { connection = new SqliteConnection(InMemoryConnectionString); connection.CreateFunction("getdate", () => DateTime.Now); connection.Open(); options = new DbContextOptionsBuilder <PhoneBookDbContext>() .UseSqlite(connection) .Options; DbContext = new PhoneBookDbContext(options); DbContext.Database.EnsureCreated(); }
public bool CreateContact(ContactDto contact) { using (var db = new PhoneBookDbContext()) { db.Contacts.Add(new Contact { Name = contact.Name, Phone = contact.Phone }); db.SaveChanges(); return(true); } }
public async Task UpdatePerson(Person person) { using (var context = new PhoneBookDbContext(_dbConfiguration)) { var entity = await context.People.FirstOrDefaultAsync(p => p.Id == person.Id); entity.FirstName = person.FirstName; entity.LastName = person.LastName; entity.Phone = person.Phone; context.People.Update(entity); await context.SaveChangesAsync(); } }
public ActionResult DeleteGroupOfEmployees([FromBody] DeletePeopleViewModel vm) { var db = new PhoneBookDbContext(); var peopleIDsSelectedForDelete = db.People.Where(people => vm.PeopleIds.Contains(people.Id)); if (peopleIDsSelectedForDelete != null) { db.People.RemoveRange(peopleIDsSelectedForDelete); db.SaveChanges(); return(Ok()); } else { return(Ok(vm)); } }
public ActionResult <Object> DeletePeople([FromRoute] int id) { var db = new PhoneBookDbContext(); var peopleToDelete = db.People.FirstOrDefault(people => people.Id == id); if (peopleToDelete != null) { db.People.Remove(peopleToDelete); db.SaveChanges(); return(peopleToDelete); } else { return(new { message = "Person or people not found" }); } }
public PhoneBookDbContext GetDbContext() { return _dbContext ?? (_dbContext = new PhoneBookDbContext()); }