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());
        }
示例#2
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");
         }
     }
 }
示例#3
0
 //dodavanje taga u bazu
 public int addTag(Tag Tag)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         contactsData.Tags.Add(Tag);
         contactsData.SaveChanges();
         return(Tag.EntryId);
     }
 }
示例#4
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);
     }
 }
示例#5
0
 //dodavanje emaila u bazu
 public int addEmail(Email Em)
 {
     using (ContactsDBEntities contactsData = new ContactsDBEntities())
     {
         contactsData.Emails.Add(Em);
         contactsData.SaveChanges();
         return(Em.EntryId);
     }
 }
示例#6
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.");
     }
 }
示例#7
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.");
     }
 }
示例#8
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.");
     }
 }
示例#9
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.");
     }
 }
示例#10
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.");
     }
 }
示例#11
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());
        }
示例#13
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);
     }
 }
示例#14
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());
     }
 }
示例#15
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());
     }
 }
示例#16
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.");
         }
     }
 }
示例#17
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.");
         }
     }
 }
示例#18
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));
        }
示例#20
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());
            }
        }
示例#21
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);
            }
        }
示例#22
0
 public Contact AddContact(Contact _contact)
 {
     _contact = DBContext.Contacts.Add(_contact);
     DBContext.SaveChanges();
     return(_contact);
 }
示例#23
0
 public void Insert(T entity)
 {
     _contactsDBEntities.Set <T>().Add(entity);
     _contactsDBEntities.SaveChanges();
 }
示例#24
0
 public IHttpActionResult ContactsInsert(tblContact contact)
 {
     contactsDBEntities.tblContacts.Add(contact);
     contactsDBEntities.SaveChanges();
     return(Ok());
 }