public async Task CreateAsync(Address adress)
 {
     if (_dbContext.Entry(adress).State == EntityState.Detached)
     {
         await _dbContext.Address.AddAsync(adress);
     }
     if (_dbContext.Entry(adress).State == EntityState.Added)
     {
         await _dbContext.SaveChangesAsync();
     }
 }
Example #2
0
 public async Task CreateAsync(Contact contact)
 {
     if (_dbContext.Entry(contact).State == EntityState.Detached)
     {
         await _dbContext.Contact.AddAsync(contact);
     }
     if (_dbContext.Entry(contact).State == EntityState.Added)
     {
         await _dbContext.SaveChangesAsync();
     }
 }
 public async Task CreateAsync(Enterprise enterprise)
 {
     if (_dbContext.Entry(enterprise).State == EntityState.Detached)
     {
         await _dbContext.Enterprise.AddAsync(enterprise);
     }
     if (_dbContext.Entry(enterprise).State == EntityState.Added)
     {
         await _dbContext.SaveChangesAsync();
     }
 }
        public async Task <int> AddContact(Contact contact)
        {
            if (db != null)
            {
                await db.Contact.AddAsync(contact);

                await db.SaveChangesAsync();

                return(contact.ContactId);
            }

            return(0);
        }
Example #5
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);
            }
        }
Example #6
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 #7
0
        public async Task <ActionResult <Contact> > PostContact(Contact contact)
        {
            _context.Contacts.Add(contact);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetContact", new { id = contact.Id }, contact));
        }
        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);
            }
        }
 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);
     }
 }
Example #10
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 #11
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);
     }
 }
 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);
     }
 }
        public async Task <IActionResult> PutContactDetails(int id, ContactDetails contactDetails)
        {
            contactDetails.id = id;
            _context.Entry(contactDetails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task Add(T model)
        {
            await _entities.AddAsync(model);

            await _contactDBContext.SaveChangesAsync(true);
        }
        public async Task Add(T entity)
        {
            await _dbContext.Set <T>().AddAsync(entity);

            await _dbContext.SaveChangesAsync();
        }