Example #1
0
        async Task <bool> ICustomerRepository.SaveCustomer(Model.Customer model)
        {
            using (ContactDBContext db = new ContactDBContext())
            {
                DataAccessLibrary.Models.Customer customer = db.Customer.Where(x => x.CustomerId == model.CustomerId).FirstOrDefault();
                if (customer == null)
                {
                    customer = new DataAccessLibrary.Models.Customer()
                    {
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        Phone     = model.Phone,
                        Gender    = model.Gender,
                        Email     = model.Email,
                        Birthday  = model.Birthday
                    };
                    db.Customer.Add(customer);
                }
                else
                {
                    customer.FirstName = model.FirstName;
                    customer.LastName  = model.LastName;
                    customer.Phone     = model.Phone;
                    customer.Gender    = model.Gender;
                    customer.Email     = model.Email;
                    customer.Birthday  = model.Birthday;
                }

                return(await db.SaveChangesAsync() >= 1);
            }
        }
Example #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ContactDBContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });


            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Contact Management Api V1");
            });

            dbContext.Database.Migrate();
        }
        async Task <bool> IEmployeeRepository.SaveEmployee(Model.Employee model)
        {
            using (ContactDBContext db = new ContactDBContext())
            {
                DataAccessLibrary.Models.Employee employee = db.Employee.Where(x => x.EmployeeId == model.EmployeeId).FirstOrDefault();
                if (employee == null)
                {
                    employee = new DataAccessLibrary.Models.Employee()
                    {
                        FirstName  = model.FirstName,
                        LastName   = model.LastName,
                        Gender     = model.Gender,
                        City       = model.City,
                        Department = model.Department,
                        Phone      = model.Phone
                    };
                    db.Employee.Add(employee);
                }
                else
                {
                    employee.FirstName  = model.FirstName;
                    employee.LastName   = model.LastName;
                    employee.Gender     = model.Gender;
                    employee.City       = model.City;
                    employee.Department = model.Department;
                    employee.Phone      = model.Phone;
                }

                return(await db.SaveChangesAsync() >= 1);
            }
        }
Example #4
0
        public async Task <bool> SaveContact(ContactModel contactModel)
        {
            using (ContactDBContext db = new ContactDBContext())
            {
                Contacts contact = db.Contacts.Where
                                       (x => x.ContactId == contactModel.ContactId).FirstOrDefault();
                if (contact == null)
                {
                    contact = new Contacts()
                    {
                        FirstName = contactModel.FirstName,
                        LastName  = contactModel.LastName,
                        Email     = contactModel.Email,
                        Phone     = contactModel.Phone
                    };
                    db.Contacts.Add(contact);
                }
                else
                {
                    contact.FirstName = contactModel.FirstName;
                    contact.LastName  = contactModel.LastName;
                    contact.Email     = contactModel.Email;
                    contact.Phone     = contactModel.Phone;
                }

                return(await db.SaveChangesAsync() >= 1);
            }
        }
 public ContactRepository(ContactDBContext contactDBContext)
 {
     if (contactDBContext == null)
     {
         throw new NullReferenceException();
     }
     _contactDBContext = contactDBContext;
 }
        public Boolean AuthenticateUser(string name, string password)
        {
            ContactDBContext contactDBContext = new ContactDBContext();
            User             user             = contactDBContext.Users.Where((u) => u.Name == name).Single();

            if (user.Name == name && user.Password == password)
            {
                return(true);
            }
            return(false);
        }
Example #7
0
 async Task <bool> ICustomerRepository.DeleteCustomerByID(int id)
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         DataAccessLibrary.Models.Customer customer = db.Customer.Where(x => x.CustomerId == id).FirstOrDefault();
         if (customer != null)
         {
             db.Customer.Remove(customer);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }
 public async Task <bool> DeleteContact(int contactId)
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         DataAccessLibrary.EntityModels.Contacts contact = db.Contacts.Where(x => x.ContactId == contactId).FirstOrDefault();
         if (contact != null)
         {
             db.Contacts.Remove(contact);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }
 public async Task <bool> DeleteEmployee(string code)
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         Employees employee = db.Employees.Where(x => x.Code == code).FirstOrDefault();
         if (employee != null)
         {
             db.Employees.Remove(employee);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }
 async Task <bool> IEmployeeRepository.DeleteEmployeeByID(int id)
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         DataAccessLibrary.Models.Employee employee = db.Employee.Where(x => x.EmployeeId == id).FirstOrDefault();
         if (employee != null)
         {
             db.Employee.Remove(employee);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }
Example #11
0
 public async Task <bool> DeleteContactByID(int id)
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         Contacts contact = db.Contacts.Where(x => x.ContactId == id).FirstOrDefault();
         if (contact != null)
         {
             db.Contacts.Remove(contact);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }
Example #12
0
 public async Task <List <Contact> > GetAllContact()
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         return(await(from a in db.Contacts
                      select new Contact
         {
             ContactId = a.ContactId,
             FirstName = a.FirstName,
             LastName = a.LastName,
             Email = a.Email,
             Phone = a.Phone
         }).ToListAsync());
     }
 }
 public async Task <List <Employee> > GetAllEmployees()
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         return(await(from e in db.Employees
                      select new Employee
         {
             Code = e.Code,
             Name = e.Name,
             Gender = e.Gender,
             AnnualSalary = e.AnnualSalary,
             DateOfBirth = e.DateOfBirth
         }).ToListAsync());
     }
 }
Example #14
0
 public async Task <List <ContactModel> > GetContacts()
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         return(await(from a in db.Contacts.AsNoTracking()
                      select new ContactModel
         {
             ContactId = a.ContactId,
             FirstName = a.FirstName,
             LastName = a.LastName,
             Email = a.Email,
             Phone = a.Phone
         }).ToListAsync());
     }
 }
 async Task <List <Model.Employee> > IEmployeeRepository.GetAllEmployee()
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         return(await(from a in db.Employee
                      select new Model.Employee
         {
             EmployeeId = a.EmployeeId,
             FirstName = a.FirstName,
             LastName = a.LastName,
             Gender = a.Gender,
             City = a.City,
             Department = a.Department,
             Phone = a.Phone
         }).ToListAsync());
     }
 }
Example #16
0
 async Task <List <Model.Customer> > ICustomerRepository.GetAllCustomer()
 {
     using (ContactDBContext db = new ContactDBContext())
     {
         return(await(from a in db.Customer
                      select new Model.Customer
         {
             CustomerId = a.CustomerId,
             FirstName = a.FirstName,
             LastName = a.LastName,
             Phone = a.Phone,
             Gender = a.Gender,
             Email = a.Email,
             Birthday = a.Birthday
         }).ToListAsync());
     }
 }
Example #17
0
 public ContactService(IContactRepository contactRepository, ContactDBContext dbContext)
 {
     _contactRepository = contactRepository;
 }
 public AddressRepository(ContactDBContext dbContext)
 {
     _dbContext = dbContext;
 }
 public ContactRepository(ContactDBContext _db)
 {
     db = _db;
 }
Example #20
0
 public ContactRepository(ContactDBContext contactDBContext)
 {
     _contactDBContext = contactDBContext;
 }
 public Repository(ContactDBContext contactDBContext)
 {
     _contactDBContext = contactDBContext;
     _entities         = _contactDBContext.Set <T>();
 }
 public ContactRepository()
 {
     _context = new ContactDBContext();
     contacts = _context.Set <Contact>();
 }
Example #23
0
 public ContactRepository(ContactDBContext db)
 {
     this.db = db;
 }
 public EnterpriseService(IEnterpriseRepository enterpriseRepository, ContactDBContext dbContext)
 {
     _enterpriseRepository = enterpriseRepository;
 }
Example #25
0
 public ContactRepository(ContactDBContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #26
0
        public ContactsAPIController()
        {
            var context = new ContactDBContext();

            this.contactService = new ContactService(context);
        }
Example #27
0
 public ContactService(ContactDBContext context)
 {
     this.context           = context;
     this.contactRepository = new Repository <Contacts>(context);
 }
 public BaseRepository(ContactDBContext contactDBContext)
 {
     _ctx = contactDBContext;
 }
Example #29
0
 public ContactController(/*UserManager<IdentityUser> um, SignInManager<IdentityUser> sm,*/ ContactDBContext context)
 {
     //userManager = um;
     //signInManager = sm;
     _context = context;
 }
Example #30
0
 public ContactsController(ContactDBContext context)
 {
     _context = context;
 }