Esempio n. 1
0
 //for adding in the userdetail
 public void AddUser(UserDetail userDetail)
 {
     using (TransactionScope trans = new TransactionScope())
     {
         context.UserDetails.Add(userDetail);
         context.SaveChanges();
         trans.Complete();
         trans.Dispose();
     }
 }
 //for adding the data in the table
 public void AddAddress(Addressbook addressbook)
 {
     using (TransactionScope trans = new TransactionScope())
     {
         context.Addressbooks.Add(addressbook);
         context.SaveChanges();
         trans.Complete();
         trans.Dispose();
     }
 }
Esempio n. 3
0
 //for adding the data in the table
 public void AddState(State state)
 {
     using (TransactionScope trans = new TransactionScope())
     {
         context.States.Add(state);
         context.SaveChanges();
         trans.Complete();
         trans.Dispose();
     }
 }
 //for adding the data in the table
 public void AddCountry(Country country)
 {
     using (TransactionScope trans = new TransactionScope())
     {
         context.Countries.Add(country);
         context.SaveChanges();
         trans.Complete();
         trans.Dispose();
     }
 }
Esempio n. 5
0
 public HttpResponseMessage Put(int id, [FromBody] Contact updatedcontact)
 {
     try
     {
         using (AddressBookEntities entities = new AddressBookEntities())
         {
             var entity = entities.Contacts.FirstOrDefault(e => e.ID == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Contact with id " + id + " not found"));
             }
             else
             {
                 if (!ModelState.IsValid)
                 {
                     return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                 }
                 else
                 {
                     entity.Name     = updatedcontact.Name;
                     entity.Email    = updatedcontact.Email;
                     entity.Phone    = updatedcontact.Phone;
                     entity.Landline = updatedcontact.Landline;
                     entity.Url      = updatedcontact.Url;
                     entity.Address  = updatedcontact.Address;
                     entities.SaveChanges();
                     return(Request.CreateResponse(HttpStatusCode.OK));
                 }
             }
         }
     }catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Esempio n. 6
0
 public ActionResult AddContacts(Contact c)
 {
     if (ModelState.IsValid)
     {
         using (AddressBookEntities dc = new AddressBookEntities())
         {
             dc.Contacts.Add(c);
             try
             {
                 dc.SaveChanges();
             }
             catch (System.Data.Entity.Validation.DbEntityValidationException e)
             {
                 foreach (var eve in e.EntityValidationErrors)
                 {
                     Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                     foreach (var ve in eve.ValidationErrors)
                     {
                         Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                           ve.PropertyName, ve.ErrorMessage);
                     }
                 }
             }
         }
         return(RedirectToAction("AddressBook"));
     }
     else
     {
         return(RedirectToAction("AddressBook"));
     }
     //return View(c);
 }
        public string SaveEditContact(EditModalView viewModel)
        {
            string contactCheck = "";

            using (AddressBookEntities ab = new AddressBookEntities())
            {
                ContactDetail cd = ab.ContactDetails.Where(x => x.Id == viewModel.ContactID).Distinct().FirstOrDefault();
                if (cd != null)
                {
                    cd = new ContactDetail
                    {
                        Id             = viewModel.ContactID,
                        ContactName    = viewModel.ContactName,
                        ContactSurname = viewModel.ContactSurname,
                        ContactEmail   = viewModel.ContactEmail,
                        DateCreated    = DateTime.Now
                    };

                    ab.ContactDetails.AddOrUpdate(cd);
                    ab.SaveChanges();
                }
                else
                {
                    contactCheck = "There is no such !";
                }
            }
            return(contactCheck);
        }
        public string AddContact(string _contactName, string _contactSurname, string _contactEmail)
        {
            string contacttCheck = "";

            using (AddressBookEntities ab = new AddressBookEntities())
            {
                ContactDetail cd = ab.ContactDetails.Where(x => x.ContactName == _contactSurname || x.ContactEmail == _contactEmail).Distinct().FirstOrDefault();
                if (cd != null)
                {
                    contacttCheck = cd.ContactName.ToString() + "Already exists !";
                }
                else
                {
                    cd = new ContactDetail
                    {
                        Id             = Guid.NewGuid(),
                        ContactName    = _contactName,
                        ContactSurname = _contactSurname,
                        ContactEmail   = _contactEmail,
                        DateCreated    = DateTime.Now
                    };

                    ab.ContactDetails.AddOrUpdate(cd);
                    ab.SaveChanges();

                    contacttCheck = cd.ContactName.ToString() + "Added Succesfully";
                }
            }
            return(contacttCheck);
        }
Esempio n. 9
0
 public ActionResult EditContact(Contact c)
 {
     if (ModelState.IsValid)
     {
         using (AddressBookEntities dc = new AddressBookEntities())
         {
             var v = dc.Contacts.Where(a => a.Id.Equals(c.Id)).FirstOrDefault();
             if (v != null)
             {
                 v.Id          = c.Id;
                 v.FirstName   = c.FirstName;
                 v.LastName    = c.LastName;
                 v.PhoneNumber = c.PhoneNumber;
                 v.StreetName  = c.StreetName;
                 v.City        = c.City;
                 v.Province    = c.Province;
                 v.PostalCode  = c.PostalCode;
                 v.Country     = c.Country;
             }
             dc.SaveChanges();
         }
         return(RedirectToAction("AddressBook"));
     }
     else
     {
         List <Contact> contact = new List <Contact>();
         contact.Add(c);
         ViewBag.userdetails = contact;
         return(View());
     }
 }
        public Response Create([FromBody] CreateEntry contact)
        {
            if (contact.PhonebookId == null || contact.PhonebookId == Guid.Empty)
            {
                return(new Response
                {
                    Status = "Error",
                    Message = "Record Must Link to a Contact"
                });
            }

            if (contact.Id != null || contact.Id == Guid.Empty)
            {
                var ct = new entry()
                {
                    Name        = contact.Name,
                    PhoneNumber = contact.PhoneNumber,
                    PhonebookId = contact.PhonebookId,
                    Id          = Guid.NewGuid()
                };

                using (var dbCtx = new AddressBookEntities())
                {
                    dbCtx.entries.Add(ct);
                    dbCtx.SaveChanges();
                }

                return(new Response
                {
                    Status = "Success",
                    Message = "Record SuccessFully Added."
                });
            }
            else
            {
                using (var dbCtx = new AddressBookEntities())
                {
                    var pb = (from s in dbCtx.entries
                              where s.Id == contact.Id
                              select s).FirstOrDefault();

                    pb.Name        = contact.Name;
                    pb.PhoneNumber = contact.PhoneNumber;

                    dbCtx.SaveChanges();
                }

                return(new Response
                {
                    Status = "Success",
                    Message = "Record SuccessFully Updated."
                });
            }
        }
        //Add a business contact
        public void addData(DateTime date, string company, string website, string title, string fName, string lName, string address,
                            string city, string province, string postalCode, string email, string phone, string notes)
        {
            BusinessContact businessContact = new BusinessContact();

            businessContact.Date_Added  = date;
            businessContact.Company     = company;
            businessContact.Website     = website;
            businessContact.Title       = title;
            businessContact.First_Name  = fName;
            businessContact.Last_Name   = lName;
            businessContact.Address     = address;
            businessContact.City        = city;
            businessContact.Province    = province;
            businessContact.Postal_Code = postalCode;
            businessContact.Email       = email;
            businessContact.Phone       = phone;
            businessContact.Notes       = notes;

            _context.BusinessContacts.Add(businessContact); //Add businessContact object
            _context.SaveChanges();                         //Save the changes
        }
Esempio n. 12
0
        public int MaintainContactDetails(personObject.Contact contact)
        {
            if (string.IsNullOrWhiteSpace(contact.PhoneNumber))
            {
                return(0);
            }

            try
            {
                using (var context = new AddressBookEntities())
                {
                    //Update Contact
                    if (contact.Id > 0)
                    {
                        var contactObj = context.AddressBooks.Where(c => c.Id == contact.Id).First();

                        contactObj.EmailAddress = contact.EmailAddress;
                        contactObj.PhoneNumber  = contact.PhoneNumber;
                        contactObj.UserId       = contact.UserId;
                        return(context.SaveChanges());
                    }

                    //Add New Contact

                    context.AddressBooks.Add(new AddressBook()
                    {
                        EmailAddress = contact.EmailAddress,
                        PhoneNumber  = contact.PhoneNumber,
                        UserId       = contact.UserId
                    });

                    return(context.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 13
0
 public ActionResult DeleteContact(Contact c)
 {
     using (AddressBookEntities dc = new AddressBookEntities())
     {
         var v = dc.Contacts.Where(a => a.Id.Equals(c.Id)).FirstOrDefault();
         if (v != null)
         {
             dc.Contacts.Remove(v);
             dc.SaveChanges();
             return(RedirectToAction("AddressBook"));
         }
         else
         {
             return(HttpNotFound("contact not found"));
         }
     }
 }
Esempio n. 14
0
        public string DeleteContactDetails(Guid contactId)
        {
            string contactCheck = "";

            using (AddressBookEntities ab = new AddressBookEntities())
            {
                ContactDetail cd = ab.ContactDetails.Where(x => x.Id == contactId).Distinct().FirstOrDefault();
                if (cd != null)
                {
                    ab.ContactDetails.Remove(cd);
                    ab.SaveChanges();
                    contactCheck = "Contact Deleted !";
                }
                else
                {
                    contactCheck = "There is no such !";
                }
            }
            return(contactCheck);
        }
Esempio n. 15
0
 public HttpResponseMessage Post([FromBody] Contact contact)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
         }
         using (AddressBookEntities entities = new AddressBookEntities())
         {
             entities.Contacts.Add(contact);
             entities.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, contact);
             message.Headers.Location = new Uri(Request.RequestUri + contact.ID.ToString());
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Esempio n. 16
0
        public object Create([FromBody] CreatePhonebook contact)
        {
            if (contact.Id != null || contact.Id == Guid.Empty)
            {
                var ct = new phonebook();
                ct.Name = contact.Name;
                ct.Id   = Guid.NewGuid();

                using (var dbCtx = new AddressBookEntities())
                {
                    dbCtx.phonebooks.Add(ct);
                    dbCtx.SaveChanges();
                }

                return(new Response
                {
                    Status = "Success",
                    Message = "Record SuccessFully Added."
                });
            }
            else
            {
                using (var dbCtx = new AddressBookEntities())
                {
                    var pb = (from s in dbCtx.phonebooks
                              where s.Id == contact.Id
                              select s).FirstOrDefault();
                    pb.Name = contact.Name;

                    dbCtx.SaveChanges();
                }

                return(new Response
                {
                    Status = "Success",
                    Message = "Record SuccessFully Updated."
                });
            }
        }
Esempio n. 17
0
        public int DeleteContactDetails(personObject.Contact contact)
        {
            if (contact.Id == 0)
            {
                return(0);
            }

            try
            {
                using (var context = new AddressBookEntities())
                {
                    var contactObj = context.AddressBooks.Where(c => c.Id == contact.Id).First();

                    context.AddressBooks.Remove(contactObj);

                    return(context.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 18
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (AddressBookEntities entities = new AddressBookEntities())
         {
             var contact = entities.Contacts.FirstOrDefault(e => e.ID == id);
             if (contact == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Contact with id " + id + " not found"));
             }
             else
             {
                 entities.Contacts.Remove(contact);
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }