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));
                }
            }
        }
Exemplo n.º 2
0
 public bool PersonExists(Guid personId)
 {
     using (var context = new PhoneBookDbContext(_dbConfiguration))
     {
         return(context.People.Any(p => p.Id == personId));
     }
 }
Exemplo n.º 3
0
 public async Task <Person> GetPersonById(Guid personId)
 {
     using (var context = new PhoneBookDbContext(_dbConfiguration))
     {
         return(await context.People.FirstOrDefaultAsync(p => p.Id == personId));
     }
 }
Exemplo n.º 4
0
 public async Task <IEnumerable <Person> > GetPeople()
 {
     using (var context = new PhoneBookDbContext(_dbConfiguration))
     {
         return(await context.People.ToListAsync());
     }
 }
Exemplo n.º 5
0
 public PhoneBookManager()
 {
     this.phoneBook          = new List <PhoneUser>();
     this.dbContext          = new PhoneBookDbContext();
     this.checkPhoneNormalBg = new PhoneNumberCheck();
     this.Load();
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void Delete(int contactId)
        {
            PhoneBookDbContext db = new PhoneBookDbContext();
            var contact           = GetById(contactId);

            db.Remove(contact);
            db.SaveChanges();
        }
Exemplo n.º 8
0
        public int Add(Entities.ContactEntity.Contact contact)
        {
            PhoneBookDbContext db = new PhoneBookDbContext();
            var result            = db.Add(contact);

            db.SaveChanges();
            return(result.Entity.ContactId);
        }
Exemplo n.º 9
0
 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;
 }
Exemplo n.º 11
0
        public Entities.ContactEntity.Contact Update(Entities.ContactEntity.Contact contact)
        {
            PhoneBookDbContext db = new PhoneBookDbContext();

            db.Contacts.Update(contact);
            db.SaveChanges();
            return(contact);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 15
0
 public List <ContactDto> GetContacts()
 {
     using (var db = new PhoneBookDbContext())
     {
         return(db.Contacts
                .Select(MappingExtensions.ToDto)
                .ToList());
     }
 }
Exemplo n.º 16
0
        private async Task InitDatabase()
        {
            var dbConf = ViewModelLocator.Resolve <IDbConfiguration>();

            using (var context = new PhoneBookDbContext(dbConf))
            {
                await context.Database.EnsureCreatedAsync();
            }
        }
Exemplo n.º 17
0
        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());
        }
Exemplo n.º 19
0
        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();
        }
Exemplo n.º 20
0
        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);
            }
        }
Exemplo n.º 21
0
        protected MemoryDbContext()
        {
            _connection = new SqliteConnection(InMemoryConnectionString);
            _connection.Open();

            var options = new DbContextOptionsBuilder <PhoneBookDbContext>()
                          .UseSqlite(_connection)
                          .Options;

            dbContext = new PhoneBookDbContext(options);
            dbContext.Database.EnsureCreated();
        }
Exemplo n.º 22
0
        //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"));
        }
Exemplo n.º 23
0
        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!");
            });
        }
Exemplo n.º 24
0
        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);
            }
        }
Exemplo n.º 25
0
        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();
        }
Exemplo n.º 26
0
        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();
        }
Exemplo n.º 27
0
        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);
            }
        }
Exemplo n.º 28
0
        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" });
            }
        }
Exemplo n.º 31
0
 public PhoneBookDbContext GetDbContext()
 {
     return _dbContext ?? (_dbContext = new PhoneBookDbContext());
 }