Exemplo n.º 1
0
 public void PopulatePartial()
 {
     context.Contacts.AddRangeAsync(ContactEntityTypeConfiguration.ContactSeed.Take(1));
     context.InfoTypes.AddRangeAsync(InfoTypeEntityTypeConfiguration.InfoTypeSeed);
     context.Infos.AddRangeAsync(InfoEntityTypeConfiguration.InfoSeed.Take(2));
     context.ReportStates.AddRangeAsync(ReportStateEntityTypeConfiguration.ReportStateSeed);
     context.ReportRequests.AddRangeAsync(ReportRequestEntityTypeConfiguration.ReportRequestSeed.Take(1));
     context.Reports.AddRangeAsync(ReportEntityTypeConfiguration.ReportSeed.Take(1));
     context.SaveChanges();
 }
Exemplo n.º 2
0
        public IActionResult CreateContact([FromBody] Contact contact)
        {
            if (contact == null)
            {
                return(BadRequest());
            }

            _context.Contacts.Add(contact);
            _context.SaveChanges();
            return(CreatedAtRoute("contact", new { id = contact.Id }, contact));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ID,Name,Phone,Email,Birthday")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
 public ActionResult Index(HttpPostedFileBase postedFile)
 {
     if (postedFile == null)
     {
         ViewBag.Message = "Please choose a file to upload.";
         return(View("Upload"));
     }
     if (Path.GetExtension(postedFile.FileName) != ".csv")
     {
         ViewBag.Message = "Please select a file with a .csv extension.";
         return(View("Upload"));
     }
     try
     {
         using (var reader = new StreamReader(postedFile.InputStream))
         {
             reader.ReadLine();
             while (!reader.EndOfStream)
             {
                 string[] rows = reader.ReadLine().Split(';');
                 if (rows.Length <= 1)
                 {
                     rows = reader.ReadLine().Split(',');
                 }
                 db.Contacts.Add(new Contact()
                 {
                     Name        = rows[0],
                     DateOfBirth = rows[1],
                     Married     = Convert.ToBoolean(rows[2]),
                     Phone       = rows[3],
                     Salary      = Convert.ToSingle(rows[4])
                 });
             }
         }
         db.SaveChanges();
     }
     catch (FormatException e)
     {
         ViewBag.Message = e.Message + "\nPlease check tha data formats in the file";
         return(View("Upload"));
     }
     catch (Exception e)
     {
         ViewBag.Message = e.Message;
         return(View("Upload"));
     }
     return(View(db.Contacts.ToList()));
 }
Exemplo n.º 5
0
 public IActionResult Contact(contact uc)
 {
     _auc.Add(uc);
     _auc.SaveChanges();
     ViewBag.message = uc.FirstName + " your message has been recorded.";
     return(View());
 }
        public ContactService(ContactDbContext context)
        {
            _context = context;

            // Create a new Contact if collection is empty,
            if (_context.Contacts.Count() == 0)
            {
                _context.Contacts.Add(new Contact
                {
                    Name            = "Proof1",
                    Company         = "Organization X",
                    ProfileImageURL = "SomeURL",
                    Email           = "*****@*****.**",
                    BirthDate       = new DateTime(1991, 02, 28),
                    ContactPhone    = new ContactPhone
                    {
                        PersonalPhone = "2123244152",
                        WorkPhone     = "2123244153"
                    },
                    Address = new Address
                    {
                        AddressLine1 = "4321 Sesame Street",
                        AddressLine2 = "Suite 900",
                        City         = "Hollywood",
                        State        = "Los Angeles"
                    }
                });
                _context.SaveChanges();
            }
        }
        private static void Seed(ContactDbContext context)
        {
            var contacts = new [] { ContactFactory.GetContact() };

            context.AddRange(contacts);
            context.SaveChanges();
        }
 public static void AddContact(Contact contact)
 {
     using (var dbContext = new ContactDbContext())
     {
         dbContext.Contacts.Add(contact);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 9
0
        public static ContactDbContext Create()
        {
            var options = new DbContextOptionsBuilder <ContactDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new ContactDbContext(options);

            context.Database.EnsureCreated();

            var aquaman = new Contact
            {
                Id        = new Guid("735bdfd9-ffe5-4fdc-98bc-55ccdd078ec4"),
                FirstName = "Arthur",
                LastName  = "Curry",
                Email     = "*****@*****.**",
                ImageUrl  = "aquaman.jpg",
                Address   = new ContactAddress
                {
                    City    = "Atlantis City",
                    Street1 = "One Atlantis Way"
                }
            };
            var batman = new Contact
            {
                Id        = new Guid("d424facc-c58b-4cd5-bcc0-1550662fd8ef"),
                FirstName = "Bruce",
                LastName  = "Wayne",
                Email     = "*****@*****.**",
                ImageUrl  = "batman.jpg",
                Address   = new ContactAddress
                {
                    City    = "Gotham City",
                    Street1 = "The Batcave"
                }
            };
            var black_panther = new Contact
            {
                Id        = new Guid("cc0bc2ed-8c1a-4c70-8de6-e6149f099a25"),
                FirstName = "King",
                LastName  = "T'Challa",
                Email     = "*****@*****.**",
                ImageUrl  = "black_panther.jpg",
                Address   = new ContactAddress
                {
                    City    = "Central Wakanda",
                    Street1 = "The Royal Palace of Wakanda"
                }
            };

            context.Contacts.AddRange(aquaman, batman, black_panther);

            context.SaveChanges();

            return(context);
        }
Exemplo n.º 10
0
        public IHttpActionResult Post([FromBody] Organization organization)
        {
            using (var ctx = new ContactDbContext())
            {
                ctx.Organizations.Add(organization);
                ctx.SaveChanges();
            }

            return(Ok());
        }
Exemplo n.º 11
0
 public IHttpActionResult AddPerson([FromUri] int orgId, [FromBody] Person person)
 {
     using (var ctx = new ContactDbContext())
     {
         var organization = ctx.Organizations.Single(x => x.Id == orgId);
         person.Organization = organization;
         ctx.People.Add(person);
         ctx.SaveChanges();
     }
     return(Ok());
 }
Exemplo n.º 12
0
        public ContactController(ContactDbContext context)
        {
            _context = context;

            if (_context.Contacts.Count() == 0)
            {
                _context.Contacts.Add(new Contact {
                    Name = "Manoj Mohan", Phone = "9686569319", eMail = "*****@*****.**", ZipCode = "134109"
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 13
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            Contact contact = ReadForm();

            using (_context = new ContactDbContext())
            {
                _context.Contact.Add(contact);
                _context.Address.AddRange(contact.Address);
                _context.Date.AddRange(contact.Date);
                _context.Phone.AddRange(contact.Phone);
                _context.SaveChanges();
            }
        }
Exemplo n.º 14
0
        public static void Main()
        {
            var random = RandomDataGenerator.Instance;
            var db = new ContactDbContext();

            var contacts = new ContactInfoGenerator(random, db, 20);

            contacts.Generate();

            db.SaveChanges();

            Console.WriteLine(db.Contacts.Count());
        }
Exemplo n.º 15
0
        public void AddPerson()
        {
            using (var db = new ContactDbContext())
            {
                db.Add(new Person()
                {
                    FirstName = this.FirstName,
                    LastName  = this.LastName
                });

                db.SaveChanges();
            }
        }
Exemplo n.º 16
0
        public IActionResult PutContact([FromRoute] int id, [FromBody] ContactModel contact)
        {
            if (contact == null || contact.Id != id)
            {
                return(BadRequest());
            }

            var singleContact = _context.Contacts.Find(id);

            if (singleContact == null)
            {
                return(NotFound());
            }

            singleContact.FirstName   = contact.FirstName;
            singleContact.LastName    = contact.LastName;
            singleContact.Email       = contact.Email;
            singleContact.PhoneNumber = contact.PhoneNumber;
            singleContact.Status      = contact.Status;

            _context.Contacts.Update(singleContact);
            _context.SaveChanges();
            return(NoContent());
        }
Exemplo n.º 17
0
        public IActionResult AddContact(Contact contact)
        {
            if (ModelState.IsValid)
            {
                _dbContext.Add(new Contact()
                {
                    FirstName   = contact.FirstName,
                    LastName    = contact.LastName,
                    Email       = contact.Email,
                    MobilePhone = contact.MobilePhone,
                    Address     = contact.Address
                });
                _dbContext.SaveChanges();
            }

            return(Ok());
        }
Exemplo n.º 18
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (lstSearchResults.SelectedItems.Count == 0)
            {
                return;
            }
            Contact contact = ReadForm();

            using (_context = new ContactDbContext())
            {
                _context.Contact.Update(contact);
                _context.Address.UpdateRange(contact.Address);
                _context.Phone.UpdateRange(contact.Phone);
                _context.Date.UpdateRange(contact.Date);
                _context.SaveChanges();
            }
        }
Exemplo n.º 19
0
        public ActionResult DeleteConfirm(int id)
        {
            using (var dbContext = new ContactDbContext())
            {
                var contact = dbContext.Contacts.Where(c => c.ContactId == id).FirstOrDefault();

                if (contact != null)
                {
                    dbContext.Contacts.Remove(contact);
                    dbContext.SaveChanges();

                    return(RedirectToAction("AllContacts", "Home"));
                }
                else
                {
                    return(HttpNotFound("Contact Not Found"));
                }
            }
        }
Exemplo n.º 20
0
        public void ShouldThrowCreatedAtActionResultWhenEmailIsNotInUse()
        {
            var contact = new Contact()
            {
                Email = "*****@*****.**"
            };

            List <Contact> contactList = new List <Contact>()
            {
                new Contact()
                {
                    Email = "*****@*****.**"
                },
                new Contact()
                {
                    Email = "*****@*****.**"
                },
                new Contact()
                {
                    Email = "*****@*****.**"
                }
            };

            var options = new DbContextOptionsBuilder <ContactDbContext>()
                          .UseInMemoryDatabase(databaseName: "ContactListDatabase")
                          .Options;

            var context = new ContactDbContext(options);

            context.Contacts.AddRange(contactList);
            context.SaveChanges();

            ContactService cs = new ContactService(context);

            ContactController cc = new ContactController(cs);

            var x = cc.PostContact(contact);

            Assert.IsInstanceOfType(x.Result.Result, typeof(Microsoft.AspNetCore.Mvc.CreatedAtActionResult));
        }
Exemplo n.º 21
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstSearchResults.SelectedItems.Count == 0)
            {
                return;
            }

            string  curItem    = lstSearchResults.SelectedItems[0].Text;
            Contact curContact = _contacts.Find(delegate(Contact contact) { return(curItem == contact.GetFullName()); });

            using (_context = new ContactDbContext())
            {
                _context.Address.RemoveRange(curContact.Address);
                _context.Phone.RemoveRange(curContact.Phone);
                _context.Date.RemoveRange(curContact.Date);
                _context.Contact.Remove(curContact);
                _context.SaveChanges();
            }

            lstSearchResults.Refresh();
            ClearForm();
        }
        public static void UpdateContact(Contact contact, HttpPostedFileBase file)
        {
            using (var dbContext = new ContactDbContext())
            {
                var selectedContactFromDataBase = dbContext.Contacts.Where(c => c.ContactId.Equals(contact.ContactId)).FirstOrDefault();

                if (selectedContactFromDataBase != null)
                {
                    selectedContactFromDataBase.ContactFName   = contact.ContactFName;
                    selectedContactFromDataBase.ContactLName   = contact.ContactLName;
                    selectedContactFromDataBase.EmailAddress   = contact.EmailAddress;
                    selectedContactFromDataBase.ContactNumber1 = contact.ContactNumber1;
                    selectedContactFromDataBase.ContactNumber2 = contact.ContactNumber2;
                    selectedContactFromDataBase.CountryId      = contact.CountryId;
                    selectedContactFromDataBase.StateId        = contact.StateId;
                    if (file != null)
                    {
                        selectedContactFromDataBase.ImagePath = contact.ImagePath;
                    }
                }

                dbContext.SaveChanges();
            }
        }
Exemplo n.º 23
0
 protected void Save() => _context.SaveChanges();
Exemplo n.º 24
0
 void IContactRepository.AddContact(Contact c)
 {
     contactDB.Contacts.Add(c);
     contactDB.SaveChanges();
 }
Exemplo n.º 25
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }
Exemplo n.º 26
0
 public void Save()
 {
     _db.SaveChanges();
 }
Exemplo n.º 27
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            ContactDbContext context = app.ApplicationServices
                                       .GetRequiredService <ContactDbContext>();

            context.Database.Migrate();
            if (!context.Contacts.Any())
            {
                context.Contacts.AddRange(
                    new Contact
                {
                    Name            = "Bob Johnson",
                    Company         = "Microsoft",
                    Email           = "*****@*****.**",
                    BirthDay        = new DateTime(1981, 1, 11),
                    PhoneNumberWork = "1191234111",
                    PhoneNumberHome = "4241111",
                    Address         = "3412 Washington Avenue Phoenix",
                },
                    new Contact
                {
                    Name            = "Albert D. Avans",
                    Company         = "Microsoft",
                    Email           = "*****@*****.**",
                    BirthDay        = new DateTime(1978, 2, 5),
                    PhoneNumberWork = "1191234222",
                    PhoneNumberHome = "4242222",
                    Address         = "2599 Bell Street Phoenix",
                },
                    new Contact
                {
                    Name            = "Tyler L. Tramel",
                    Company         = "Github",
                    Email           = "[email protected]",
                    BirthDay        = new DateTime(1959, 10, 9),
                    PhoneNumberWork = "1191234333",
                    PhoneNumberHome = "4243333",
                    Address         = "2022 Hannah Street Asheville",
                },
                    new Contact
                {
                    Name            = "Theodore O. Jones",
                    Company         = "Github",
                    Email           = "[email protected]",
                    BirthDay        = new DateTime(1921, 1, 11),
                    PhoneNumberWork = "1191234444",
                    PhoneNumberHome = "4244444",
                    Address         = "1921 Fire Access Road Asheville",
                },
                    new Contact
                {
                    Name            = "Madelyn T. Johnson",
                    Company         = "Google",
                    Email           = "[email protected]",
                    BirthDay        = new DateTime(1981, 1, 11),
                    PhoneNumberWork = "1191234555",
                    PhoneNumberHome = "4245555",
                    Address         = "2354 Rockford Mountain Lane Morrisville",
                },
                    new Contact
                {
                    Name            = "Ollie D. Saunders",
                    Company         = "Google",
                    Email           = "*****@*****.**",
                    BirthDay        = new DateTime(1949, 1, 8),
                    PhoneNumberWork = "1191234666",
                    PhoneNumberHome = "4246666",
                    Address         = "1561 Still Pastures Drive North Morrisville",
                },
                    new Contact
                {
                    Name            = "Sheila D. Schaller",
                    Company         = "Solstice",
                    Email           = "[email protected]",
                    BirthDay        = new DateTime(1991, 5, 16),
                    PhoneNumberWork = "1191234777",
                    PhoneNumberHome = "4247777",
                    Address         = "3694 Thomas Street Morrisville",
                },
                    new Contact
                {
                    Name            = "Heather D. Baker",
                    Company         = "Solstice",
                    Email           = "[email protected]",
                    BirthDay        = new DateTime(1981, 5, 22),
                    PhoneNumberWork = "1191234888",
                    PhoneNumberHome = "4248888",
                    Address         = "1446 McDonald Avenue Albany",
                },
                    new Contact
                {
                    Name            = "Carlos K. Manley",
                    Company         = "Solstice",
                    Email           = "[email protected]",
                    BirthDay        = new DateTime(1951, 2, 10),
                    PhoneNumberWork = "1191234999",
                    PhoneNumberHome = "4249999",
                    Address         = "1392 Joes Road Albany",
                });

                context.SaveChanges();
            }
        }
Exemplo n.º 28
0
 public void DeleteContact(Contact contact)
 {
     context.Remove(contact);
     context.SaveChanges();
 }
Exemplo n.º 29
0
        public static void Seed(this ContactDbContext contactBbContext)
        {
            contactBbContext.Contacts.Add(new Contact()
            {
                ContactId      = 20,
                FirstName      = "Thabiso",
                Surname        = "Zuma",
                BirthDate      = new DateTime(2000, 5, 23),
                UpdatedDate    = DateTime.Now,
                ContactDetails = new List <ContactDetail>(3)
                {
                    new ContactDetail()
                    {
                        ContactDetailId = 15,
                        Description     = "Description one",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238391",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    },
                    new ContactDetail()
                    {
                        ContactDetailId = 16,
                        Description     = "Description two",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238392",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    },
                    new ContactDetail()
                    {
                        ContactDetailId = 17,
                        Description     = "Description three",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238393",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    }
                }
            });

            contactBbContext.Contacts.Add(new Contact()
            {
                ContactId      = 21,
                FirstName      = "Tshepi",
                Surname        = "Boipelo",
                BirthDate      = new DateTime(1993, 2, 27),
                UpdatedDate    = DateTime.Now,
                ContactDetails = new List <ContactDetail>(3)
                {
                    new ContactDetail()
                    {
                        ContactDetailId = 18,
                        Description     = "Description one",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238391",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    },
                    new ContactDetail()
                    {
                        ContactDetailId = 19,
                        Description     = "Description two",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238392",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    },
                    new ContactDetail()
                    {
                        ContactDetailId = 20,
                        Description     = "Description three",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238393",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    }
                }
            });

            contactBbContext.Contacts.Add(new Contact()
            {
                ContactId      = 22,
                FirstName      = "Thabo",
                Surname        = "Mbheki",
                BirthDate      = new DateTime(1998, 3, 14),
                UpdatedDate    = DateTime.Now,
                ContactDetails = new List <ContactDetail>(3)
                {
                    new ContactDetail()
                    {
                        ContactDetailId = 21,
                        Description     = "Description one",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238391",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    },
                    new ContactDetail()
                    {
                        ContactDetailId = 22,
                        Description     = "Description two",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238392",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    },
                    new ContactDetail()
                    {
                        ContactDetailId = 23,
                        Description     = "Description three",
                        Address         = "129 Barbra Street",
                        Cell            = "0818238393",
                        Email           = "*****@*****.**",
                        Telephone       = "0129223491"
                    }
                }
            });

            contactBbContext.Contacts.Add(new Contact()
            {
                ContactId      = 23,
                FirstName      = "Nelson",
                Surname        = "Mandela",
                BirthDate      = new DateTime(1918, 7, 18),
                UpdatedDate    = DateTime.Now,
                ContactDetails = null
            });

            contactBbContext.SaveChanges();
        }
Exemplo n.º 30
0
 public void AddContact(Contact c)
 {
     contactDB.Contacts.Add(c);
     contactDB.SaveChanges();
 }
 public void Save()
 {
     //throw new NotImplementedException();
     _db.SaveChanges();
 }