示例#1
0
 //brisanje kontakta iz baze
 public string deleteContact(int ConId)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var mailsById = contactsData.Emails.Where(x => x.PersonId == ConId).ToList();
         foreach (var mail in mailsById)
         {
             contactsData.Emails.Remove(mail);
         }
         var telsById = contactsData.Telephones.Where(x => x.PersonId == ConId).ToList();
         foreach (var tel in telsById)
         {
             contactsData.Telephones.Remove(tel);
         }
         var tagsById = contactsData.Tags.Where(x => x.PersonId == ConId).ToList();
         foreach (var tag in tagsById)
         {
             contactsData.Tags.Remove(tag);
         }
         var contactById = contactsData.Contacts.Where(x => x.Id == ConId).Single();
         if (contactById != null)
         {
             contactsData.Contacts.Remove(contactById);
             contactsData.SaveChanges();
             return("Contact deleted.");
         }
         else
         {
             return("Contact not in database");
         }
     }
 }
        public IHttpActionResult PutContact(Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var ctx = new ContactsDBEntities())
            {
                var existingContact = ctx.Contacts.Where(s => s.ID == contact.ID).FirstOrDefault();

                if (existingContact != null)
                {
                    existingContact.FirstName   = contact.FirstName;
                    existingContact.LastName    = contact.LastName;
                    existingContact.Email       = contact.Email;
                    existingContact.PhoneNumber = contact.PhoneNumber;
                    existingContact.Status      = contact.Status;
                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            return(Ok());
        }
示例#3
0
        //trazi kontakte po imenu, prezimenu i tagovima te vracaju filtriranu listu
        //onih kontakata koji kao substring imena/prezimena/tagova imaju searchString
        public JsonResult search(string searchString)
        {
            using (ContactsDBEntities contactsData = new ContactsDBEntities())
            {
                List <Contact_Info> filteredList = new List <Contact_Info>();

                //prvo gledamo u tablicu "Contacts" i vadimo sve unose koji kao substring imena ili prezimena
                //imaju searchString
                var filteredList1 = contactsData.Contacts.Where(x => x.Name.IndexOf(searchString) > -1).ToList();
                var filteredList2 = contactsData.Contacts.Where(x => x.Surname.IndexOf(searchString) > -1).ToList();
                filteredList1.AddRange(filteredList2);

                //za svaki takav naden unos u tablici funkcijom getContactInfoById u listu filteredList
                //unosimo Contact_Info tog kontakta
                foreach (var contact in filteredList1)
                {
                    filteredList.Add(getContactInfoById(contact.Id));
                }

                //istu stvar radimo na tablici "Tags"
                var filteredList3 = contactsData.Tags.Where(x => x.Tag1.IndexOf(searchString) > -1).ToList();
                foreach (var tag in filteredList3)
                {
                    filteredList.Add(getContactInfoById(tag.PersonId));
                }

                return(Json(filteredList, JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
        public static bool Login(string username, string password)
        {
            // Verify the credentials against the information in the Users table.
            ContactsDBEntities contactsDBEntities = new ContactsDBEntities();

            return(contactsDBEntities.Users.Any(user => user.Username.Equals(username, StringComparison.OrdinalIgnoreCase) && user.Password == password));
        }
示例#5
0
 //dodavanje telefonskog broja u bazu
 public int addTelephone(Telephone Tel)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         contactsData.Telephones.Add(Tel);
         contactsData.SaveChanges();
         return(Tel.EntryId);
     }
 }
示例#6
0
 //dodavanje taga u bazu
 public int addTag(Tag Tag)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         contactsData.Tags.Add(Tag);
         contactsData.SaveChanges();
         return(Tag.EntryId);
     }
 }
示例#7
0
 //dodavanje emaila u bazu
 public int addEmail(Email Em)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         contactsData.Emails.Add(Em);
         contactsData.SaveChanges();
         return(Em.EntryId);
     }
 }
示例#8
0
 public string updateTag(Tag Tag)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var toBeUpdated = contactsData.Tags.Where(x => x.EntryId == Tag.EntryId).Single();
         toBeUpdated.Tag1 = Tag.Tag1;
         contactsData.SaveChanges();
         return("Tag updated.");
     }
 }
示例#9
0
 //funckcije primaju instancu klase Email/Telephone/Tag i po EntryIdu nalaze redak tablice koji treba osvjeziti
 //te stari unos zamijenjuju novodobivenim
 public string updateEmail(Email Em)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var toBeUpdated = contactsData.Emails.Where(x => x.EntryId == Em.EntryId).Single();
         toBeUpdated.Email1 = Em.Email1;
         contactsData.SaveChanges();
         return("Email updated.");
     }
 }
示例#10
0
 public string updateTelephone(Telephone Tel)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var toBeUpdated = contactsData.Telephones.Where(x => x.EntryId == Tel.EntryId).Single();
         toBeUpdated.Telephone1 = Tel.Telephone1;
         contactsData.SaveChanges();
         return("Telephone updated.");
     }
 }
示例#11
0
 //osobi s id-em Id ime postavljamo na novodobiveni string Name
 public string updateName(int Id, string Name)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var toBeUpdated = contactsData.Contacts.Where(x => x.Id == Id).Single();
         toBeUpdated.Name = Name;
         contactsData.SaveChanges();
         return("Name updated.");
     }
 }
示例#12
0
 //analogno fji updateName
 public string updateAddress(int Id, string Address)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         Debug.WriteLine(Id);
         Debug.WriteLine(Address);
         var toBeUpdated = contactsData.Contacts.Where(x => x.Id == Id).Single();
         toBeUpdated.Address = Address;
         contactsData.SaveChanges();
         return("Address updated.");
     }
 }
示例#13
0
 //analogno fji updateName
 public string updateSurname(int Id, string Surname)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         Debug.WriteLine(Id);
         Debug.WriteLine(Surname);
         var toBeUpdated = contactsData.Contacts.Where(x => x.Id == Id).Single();
         toBeUpdated.Surname = Surname;
         contactsData.SaveChanges();
         return("Surname updated.");
     }
 }
        public IHttpActionResult PostContact(Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model validation failed."));
            }

            using (var ctx = new ContactsDBEntities())
            {
                ctx.Contacts.Add(contact);
                ctx.SaveChanges();
            }
            return(Ok());
        }
        public IHttpActionResult GetContactById(int id)
        {
            Contact contact = null;

            using (var ctx = new ContactsDBEntities())
            {
                contact = ctx.Contacts.Where(c => c.ID == id).FirstOrDefault();
                if (contact == null)
                {
                    return(NotFound());
                }
            }

            return(Ok(contact));
        }
        public IHttpActionResult GetAllContacts()
        {
            IList <Contact> listContacts = null;

            using (var ctx = new ContactsDBEntities())
            {
                listContacts = ctx.Contacts.ToList();
            }
            if (listContacts.Count() == 0)
            {
                return(NotFound());
            }

            return(Ok(listContacts));
        }
示例#17
0
 //dodavnja osnovnih informacija kontakta (ime, prezime, adresa) u Contacts tablicu
 public int addContact(Contact Con)
 {
     if (Con != null)
     {
         using (ContactsDBEntities contactsData = new ContactsDBEntities())
         {
             contactsData.Contacts.Add(Con);
             contactsData.SaveChanges();
         }
         return(Con.Id);
     }
     else
     {
         return(0);
     }
 }
示例#18
0
 public string deleteTelephone(Telephone Tel)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var telephoneById = contactsData.Telephones.Where(x => x.EntryId == Tel.EntryId).Single();
         if (telephoneById != null)
         {
             contactsData.Telephones.Remove(telephoneById);
             contactsData.SaveChanges();
             return("Telephone deleted");
         }
         else
         {
             return("Telephone not in database.");
         }
     }
 }
示例#19
0
 //fje za brisanje emaila/telefonskog broja/taga iz baze
 public string deleteEmail(Email Em)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var emailById = contactsData.Emails.Where(x => x.EntryId == Em.EntryId).Single();
         if (emailById != null)
         {
             contactsData.Emails.Remove(emailById);
             contactsData.SaveChanges();
             return("Email deleted");
         }
         else
         {
             return("Email not in database.");
         }
     }
 }
        public IHttpActionResult DeleteContact(int id)
        {
            Contact contact = null;

            using (var ctx = new ContactsDBEntities())
            {
                contact = ctx.Contacts.Find(id);
                if (contact == null)
                {
                    return(NotFound());
                }

                ctx.Contacts.Remove(contact);
                ctx.SaveChanges();
            }
            return(Ok(contact));
        }
示例#21
0
 public string deleteTag(Tag Tag)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         var tagById = contactsData.Tags.Where(x => x.EntryId == Tag.EntryId).Single();
         if (tagById != null)
         {
             contactsData.Tags.Remove(tagById);
             contactsData.SaveChanges();
             return("Tag deleted");
         }
         else
         {
             return("Tag not in database.");
         }
     }
 }
示例#22
0
 public ActionResult Edit(int id, Employee employee)
 {
     try
     {
         // TODO: Add update logic here
         using (ContactsDBEntities db = new ContactsDBEntities())
         {
             db.Entry(employee).State = EntityState.Modified;
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#23
0
 public ActionResult Create(Employee employee)
 {
     try
     {
         // TODO: Add insert logic here
         using (ContactsDBEntities db = new ContactsDBEntities())
         {
             db.Employees.Add(employee);
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#24
0
        public ActionResult Delete(int id, Employee employee)
        {
            try
            {
                // TODO: Add delete logic here
                using (ContactsDBEntities db = new ContactsDBEntities())
                {
                    employee = db.Employees.Where(x => x.EmployeeId == id).FirstOrDefault();
                    db.Employees.Remove(employee);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
示例#25
0
        //vraca iz baze sve informacije o kontaktu sa zadanim id-em u obliku instance Contact_Info klase
        public Contact_Info getContactInfoById(int ConId)
        {
            using (ContactsDBEntities contactsData = new ContactsDBEntities())
            {
                //stvara se i puni temp, instanca klase Contact_Info
                Contact_Info temp = new Contact_Info();

                //id, ime, prezime i adresu vade se iz tablice "Contacts"
                var tempContact = contactsData.Contacts.Where(x => x.Id == ConId).Single();
                temp.Id      = ConId;
                temp.Name    = tempContact.Name;
                temp.Surname = tempContact.Surname;
                temp.Address = tempContact.Address;

                //lista emailova/telefonskih brojeva/tagova
                //(instanci klase Email/Telephone/Tag koja sadrzi id osobe, id unosa i sam email/broj/tag)
                //dohvaca se iz tablice "Emails"/"Telephones"/"Tags"
                var tempEmail = contactsData.Emails.Where(x => x.PersonId == ConId).ToList();
                foreach (var mail in tempEmail)
                {
                    temp.Emails.Add(mail);
                }

                var tempTelephone = contactsData.Telephones.Where(x => x.PersonId == ConId).ToList();
                foreach (var tel in tempTelephone)
                {
                    temp.Telephones.Add(tel);
                }

                var tempTag = contactsData.Tags.Where(x => x.PersonId == ConId).ToList();
                foreach (var tag in tempTag)
                {
                    temp.Tags.Add(tag);
                }

                //vracanje popunjene instance klase "Contact_Info"
                return(temp);
            }
        }
示例#26
0
        //funkcija dodaje novi kontakt u bazu, sa svim podacima (ime, prezime, adresa, emailovi, tel.brojevi, tagovi)
        public int addFullContact(Contact_Info Con)
        {
            if (Con != null)
            {
                using (ContactsDBEntities contactsData = new ContactsDBEntities())
                {
                    //prvo se dodaju osnovni podaci (ime, prezime i adresa) u tablicu "Contacts"
                    Contact ConBasic = new Contact(Con.Name, Con.Surname, Con.Address);
                    contactsData.Contacts.Add(ConBasic);
                    contactsData.SaveChanges();

                    //s dobivenim id-em osobe, dodaju se njeni mailovi, telefonski brojevi i tagovi,
                    //sve u svoje tablice
                    foreach (var em in Con.Emails)
                    {
                        Email Em = new Email(ConBasic.Id, em.Email1);
                        addEmail(Em);
                    }
                    foreach (var tel in Con.Telephones)
                    {
                        Telephone Tel = new Telephone(ConBasic.Id, tel.Telephone1);
                        addTelephone(Tel);
                    }
                    foreach (var tag in Con.Tags)
                    {
                        Tag Tag = new Tag(ConBasic.Id, tag.Tag1);
                        addTag(Tag);
                    }
                }
                return(1);
            }
            else
            {
                return(0);
            }
        }
示例#27
0
 public EntityBaseRepository(ContactsDBEntities contactsDBEntities)
 {
     _contactsDBEntities = contactsDBEntities;
     this.dbSet          = contactsDBEntities.Set <T>();
 }
示例#28
0
        // GET: Contacts/Delete/5
        public ActionResult Delete(int id)
        {
            using (ContactsDBEntities db = new ContactsDBEntities())

                return(View(db.Employees.Where(x => x.EmployeeId == id).FirstOrDefault())); ;
        }
示例#29
0
 // GET: Contacts/Index
 public ActionResult Index()
 {
     using (ContactsDBEntities db = new ContactsDBEntities())
         return(View(db.Employees.ToList()));
 }
示例#30
0
        //funkcija popunjava bazu
        //ne koristi se, potrebna je samo za pocetno popunjavanje baze (pristup unosom URL-a /Home/fillDB)
        public string fillDB()
        {
            using (ContactsDBEntities contactsData = new ContactsDBEntities())
            {
                contactsData.Database.ExecuteSqlCommand("TRUNCATE TABLE [Contacts]");
                contactsData.Database.ExecuteSqlCommand("TRUNCATE TABLE [Emails]");
                contactsData.Database.ExecuteSqlCommand("TRUNCATE TABLE [Telephones]");
                contactsData.Database.ExecuteSqlCommand("TRUNCATE TABLE [Tags]");
            }

            Contact   Con1        = new Contact("Ana", "Anić", "Amruševa 99");
            int       Id1         = addContact(Con1);
            Email     Email11     = new Email(Id1, "*****@*****.**");
            Email     Email12     = new Email(Id1, "*****@*****.**");
            Telephone Telephone11 = new Telephone(Id1, "098/9790-858");
            Telephone Telephone12 = new Telephone(Id1, "01/2990-512");
            Tag       Tag1        = new Tag(Id1, "srednja");

            addEmail(Email11);
            addEmail(Email11);
            addTelephone(Telephone11);
            addTelephone(Telephone12);
            addTag(Tag1);

            Contact   Con2        = new Contact("Berislav", "Borić", "Borska 12");
            int       Id2         = addContact(Con2);
            Email     Email21     = new Email(Id2, "*****@*****.**");
            Email     Email22     = new Email(Id2, "*****@*****.**");
            Telephone Telephone21 = new Telephone(Id2, "091/5525-552");
            Telephone Telephone22 = new Telephone(Id2, "01/4741-444");
            Tag       Tag2        = new Tag(Id2, "posao_ekipa");

            addEmail(Email21);
            addEmail(Email22);
            addTelephone(Telephone21);
            addTelephone(Telephone22);
            addTag(Tag2);

            Contact   Con3        = new Contact("Cvijeta", "Cavrić", "Ulica ciklama 52");
            int       Id3         = addContact(Con3);
            Email     Email31     = new Email(Id3, "*****@*****.**");
            Email     Email32     = new Email(Id3, "*****@*****.**");
            Telephone Telephone31 = new Telephone(Id3, "095/833-9077");
            Telephone Telephone32 = new Telephone(Id3, "091/5082-190");
            Telephone Telephone33 = new Telephone(Id3, "01/7172-121");
            Tag       Tag3        = new Tag(Id3, "faks");

            addEmail(Email31);
            addEmail(Email32);
            addTelephone(Telephone31);
            addTelephone(Telephone32);
            addTelephone(Telephone33);
            addTag(Tag3);

            Contact   Con4        = new Contact("Doris", "Denić", "Dobri dol 18");
            int       Id4         = addContact(Con4);
            Email     Email41     = new Email(Id4, "*****@*****.**");
            Telephone Telephone41 = new Telephone(Id4, "099/2716-520");
            Tag       Tag4        = new Tag(Id4, "obitelj");

            addEmail(Email41);
            addTelephone(Telephone41);
            addTag(Tag4);

            Contact   Con5        = new Contact("Ela", "Elezović", "Eugena Kvaternika 11");
            int       Id5         = addContact(Con5);
            Email     Email51     = new Email(Id5, "*****@*****.**");
            Email     Email52     = new Email(Id5, "*****@*****.**");
            Telephone Telephone51 = new Telephone(Id5, "091/5534-551");
            Tag       Tag5        = new Tag(Id5, "srednja");

            addEmail(Email51);
            addEmail(Email52);
            addTelephone(Telephone51);
            addTag(Tag3);

            Contact   Con6       = new Contact("Franko", "Favrić", "Francuske revolucije 8, Split");
            int       Id6        = addContact(Con6);
            Email     Email6     = new Email(Id6, "*****@*****.**");
            Telephone Telephone6 = new Telephone(Id6, "099/1986-111");
            Tag       Tag6       = new Tag(Id6, "posao_kontakti");

            addEmail(Email6);
            addTelephone(Telephone6);
            addTag(Tag6);

            Contact   Con7        = new Contact("Goran", "Golubić", "Grižanska 19");
            int       Id7         = addContact(Con7);
            Email     Email71     = new Email(Id7, "*****@*****.**");
            Telephone Telephone71 = new Telephone(Id7, "095 76 848 76");
            Telephone Telephone72 = new Telephone(Id7, "01 2987 187");
            Tag       Tag7        = new Tag(Id7, "osnovna");

            addEmail(Email71);
            addTelephone(Telephone71);
            addTelephone(Telephone72);
            addTag(Tag7);

            Contact   Con8        = new Contact("Hrvoje", "Hrenović", "Heinzelova 21");
            int       Id8         = addContact(Con8);
            Email     Email81     = new Email(Id8, "*****@*****.**");
            Email     Email82     = new Email(Id8, "*****@*****.**");
            Telephone Telephone81 = new Telephone(Id8, "091 1234 987");
            Telephone Telephone82 = new Telephone(Id8, "01 4660 555");
            Tag       Tag8        = new Tag(Id8, "posao_kontakti");

            addEmail(Email81);
            addEmail(Email82);
            addTelephone(Telephone81);
            addTelephone(Telephone82);
            addTag(Tag8);

            Contact   Con9        = new Contact("Irena", "Iljazović", "Iblerov trg 8");
            int       Id9         = addContact(Con9);
            Email     Email91     = new Email(Id9, "*****@*****.**");
            Email     Email92     = new Email(Id9, "*****@*****.**");
            Telephone Telephone91 = new Telephone(Id9, "092 881 9921");
            Tag       Tag9        = new Tag(Id9, "faks");

            addEmail(Email91);
            addEmail(Email92);
            addTelephone(Telephone91);
            addTag(Tag9);

            Contact   Con10       = new Contact("Janja", "Jakić", "Josipa Hamma 12");
            int       Id10        = addContact(Con10);
            Telephone Telephone10 = new Telephone(Id10, "098 8128 818");
            Tag       Tag10       = new Tag(Id10, "osnovna");

            addTelephone(Telephone10);
            addTag(Tag10);

            return("OK");
        }