public Contact EditContact(Contact contactToEdit)
 {
     var originalContact = GetContact(contactToEdit.Id);
     _entities.ApplyPropertyChanges(originalContact.EntityKey.EntitySetName, contactToEdit);
     _entities.SaveChanges();
     return contactToEdit;
 }
        public Contact Put(int id, Contact contact)
        {
            repository.Get(id);
            repository.Update(contact);

            return contact;
        }
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     if (_selectedContact == null && _contacts.Count > 0)
     {
         _selectedContact = _contacts[0];
         MasterListView.SelectedIndex = 0;
     }
     // If the app starts in narrow mode - showing only the Master listView - 
     // it is necessary to set the commands and the selection mode.
     if (PageSizeStatesGroup.CurrentState == NarrowState)
     {
         VisualStateManager.GoToState(this, MasterState.Name, true);
     }
     else if (PageSizeStatesGroup.CurrentState == WideState)
     {
         // In this case, the app starts is wide mode, Master/Details view, 
         // so it is necessary to set the commands and the selection mode.
         VisualStateManager.GoToState(this, MasterDetailsState.Name, true);
         MasterListView.SelectionMode = ListViewSelectionMode.Extended;
         MasterListView.SelectedItem = _selectedContact;
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
 public void Put(string id, Contact value)
 {
     if (!_contacts.UpdateContact(id, value))
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
Exemplo n.º 5
0
        public ActionResult Create(Contact contact)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!String.IsNullOrEmpty(contact.Address))
                    {
                        var coordinate = GetCoordinate(contact.Address);
                        contact.Latitude = coordinate.Item1;
                        contact.Longitude = coordinate.Item2;
                    }

                    contactsDb.Contacts.Add(contact);
                    contactsDb.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (RetryLimitExceededException)
            {
                //Log the error
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return View(contact);
        }
Exemplo n.º 6
0
        public IHttpActionResult PutContact(int id, Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != contact.ContactId)
            {
                return BadRequest();
            }

            db.Entry(contact).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public Contact AddContact(Contact item)
 {
     item.Id = ObjectId.GenerateNewId().ToString();
     item.LastModified = DateTime.UtcNow;
     _contacts.Insert(item);
     return item;
 }
Exemplo n.º 8
0
 public ActionResult Edit(int groupId, Contact contactToEdit)
 {
     if (_service.EditContact(groupId, contactToEdit))
         return RedirectToAction("Index", new {id=groupId });
     AddGroupsToViewData(groupId);
     return View("Edit");
 }
        public void updateContact(int id, string username, string lat, string lon)
        {
            var ctx = HttpContext.Current;
            var currentData = ((Contact[])ctx.Cache[CacheKey]).ToList();
            bool isFound = false;
            if (username != null)
            {

                foreach (var x in currentData)
                {
                    if (x.Name == username)
                    {
                        //Found
                        x.Lat = lat.Replace(",",".");
                        x.Long = lon.Replace(",", ".");
                        isFound = true;
                    }

                }

                if (isFound == false)
                {
                    //New user
                    Contact tempContact = new Contact();
                    tempContact.Id = 0;
                    tempContact.Name = username;
                    tempContact.Lat = lat.Replace(",", ".");
                    tempContact.Long = lon.Replace(",", ".");
                    currentData.Add(tempContact);
                }
                ctx.Cache[CacheKey] = currentData.ToArray();
            }
        }
Exemplo n.º 10
0
        public HttpResponseMessage Post(Contact contact)
        {
            this.contactRepository.SaveContact(contact);

            var response = Request.CreateResponse<Contact>(System.Net.HttpStatusCode.Created, contact);

            return response;
        }
Exemplo n.º 11
0
 public ActionResult Create(Contact contact)
 {
     if (ModelState.IsValid) {
         _contactService.CreateContact(contact);
         return RedirectToAction("Index");
     }
     return View();
 }
Exemplo n.º 12
0
        public void TestRandomContactGenerator()
        {

            var contactArray = new Contact[100];
            contactArray = RandomContactGenerator.ContactGenerator();
            Assert.AreEqual("John4", contactArray[4].FirstName);

         
        }
        public void Add(Contact contact)
        {
            if (_contacts.Any(x => x.ContactId == contact.ContactId))
            {
                throw new InvalidOperationException(string.Format("Contact with id '{0}' already exists", contact.ContactId));
            }

            _contacts.Add(contact);
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            SelectedContact = e.Parameter as Contact;
            // Register for hardware and software back request from the system
            SystemNavigationManager systemNavigationManager = SystemNavigationManager.GetForCurrentView();
            systemNavigationManager.BackRequested += OnBackRequested;
            systemNavigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
        }
Exemplo n.º 15
0
        public IHttpActionResult PostContact(Contact contact)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            db.Contacts.Add(contact);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = contact.ContactId }, contact);
        }
 public int Add(Contact contact)
 {
     using (var session = NHibernateHelper.OpenSession())
     using (var transaction = session.BeginTransaction())
     {
         var id = (int)session.Save(contact);
         transaction.Commit();
         return id;
     }
 }
        public Contact CreateContact(int groupId, Contact contactToCreate)
        {
            // Associate group with contact
            contactToCreate.Group = GetGroup(groupId);

            // Save new contact
            _entities.AddToContactSet(contactToCreate);
            _entities.SaveChanges();
            return contactToCreate;
        }
 private void WriteContact(Contact contact, Stream stream)
 {
     var writer = new StreamWriter(stream);
     writer.WriteLine("BEGIN:VCARD");
     writer.WriteLine(string.Format("FN:{0}", contact.Name));
     writer.WriteLine(string.Format("ADR;TYPE=HOME;{0};{1};{2}", contact.Address, contact.City, contact.Zip));
     writer.WriteLine(string.Format("EMAIL;TYPE=PREF,INTERNET:{0}", contact.Email));
     writer.WriteLine("END:VCARD");
     writer.Flush();
 }
Exemplo n.º 19
0
 public ActionResult Create(Contact contact)
 {
     if (ModelState.IsValid)
     {
         _repo.Add<Contact>(contact);
         _repo.SaveChanges();
         return RedirectToAction("Index");
     }
     return View();
 }
Exemplo n.º 20
0
 /// <summary>
 /// Add a new contact.
 /// </summary>
 /// <param name="contact">Contact to add.</param>
 /// <returns>The added contact</returns>
 public HttpResponseMessage Post(Contact contact)
 {
     if (this.ModelState.IsValid)
     {
         this.repository.Post(contact);
         var response = Request.CreateResponse<Contact>(HttpStatusCode.Created, contact);
         response.Headers.Location = GetContactLocation(contact.ContactId);
         return response;
     }
     return Request.CreateResponse(HttpStatusCode.BadRequest);
 }
 public void Update(Contact updatedContact)
 {
     var contact = this.Get(updatedContact.ContactId);
     contact.Name = updatedContact.Name;
     contact.Address = updatedContact.Address;
     contact.City = updatedContact.City;
     contact.State = updatedContact.State;
     contact.Zip = updatedContact.Zip;
     contact.Email = updatedContact.Email;
     contact.Twitter = updatedContact.Twitter;
 }
Exemplo n.º 22
0
        public ActionResult Create(Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(contact);
        }
        public void When_add_a_contact()
        {
            IRepository repository = new ContactRepository();
            string name = Guid.NewGuid().ToString();
            var contact = new Contact(name, "11111111", "Archway, London");
            var contactId = repository.Add(contact);

            var contactRetrieved = repository.Get(contactId);

            repository.Remove(contactId);
            Assert.That(contactRetrieved.Name, Is.EqualTo(name));
        }
Exemplo n.º 24
0
 public bool DeleteContact(Contact contactToDelete)
 {
     try
     {
         _repository.DeleteContact(contactToDelete);
     }
     catch
     {
         return false;
     }
     return true;
 }
 public bool UpdateContact(string id, Contact item)
 {
     IMongoQuery query = Query.EQ("_id", id);
     item.LastModified = DateTime.UtcNow;
     IMongoUpdate update = Update
        .Set("Email", item.Email)
        .Set("LastModified", DateTime.UtcNow)
        .Set("Name", item.Name)
        .Set("Phone", item.Phone);
     SafeModeResult result = _contacts.Update(query, update);
     return result.UpdatedExisting;
 }
       public static Contact[] ContactGenerator()
       {
        
           var contactArray = new Contact[100];
           
           for (int i = 0; i < 100; i++)
			{
                contactArray[i] = new Contact { FirstName = "John" + i.ToString(), LastName = "Doe" + i.ToString(), Phone = "425-245-3000" };
			}
      
          return contactArray; 
        }
 public HttpResponseMessage<Contact> Post(Contact contact)
 {            
     repository.Post(contact);
     
     var response = new HttpResponseMessage<Contact>(contact)
                     {
                         StatusCode = HttpStatusCode.Created
                     };
     response.Headers.Location = new Uri(
         ControllerContext.Request.RequestUri.LocalPath + "/" + contact.Id.ToString(CultureInfo.InvariantCulture), UriKind.Relative);
     
     return response;
 }
        public Contact EditContact(int groupId, Contact contactToEdit)
        {
            // Get original contact
            var originalContact = GetContact(contactToEdit.Id);

            // Update with new group
            originalContact.Group = GetGroup(groupId);

            // Save changes
            _entities.ApplyPropertyChanges(originalContact.EntityKey.EntitySetName, contactToEdit);
            _entities.SaveChanges();
            return contactToEdit;
        }
        public void CreateValidContact()
        {
            // Arrange
            var contact = new Contact();
            _service.Setup(s => s.CreateContact(contact)).Returns(true);
            var controller = new ContactController(_service.Object);

            // Act
            var result = (RedirectToRouteResult)controller.Create(contact);

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
Exemplo n.º 30
0
 public ActionResult Edit(Contact contact)
 {
     if (ModelState.IsValid)
     {
         var original = _repo.Find<Contact>(contact.Id);
         original.FirstName = contact.FirstName;
         original.LastName = contact.LastName;
         original.Birthday = contact.Birthday;
         original.PhoneNumber = contact.PhoneNumber;
         _repo.SaveChanges();
         return RedirectToAction("Index");
     }
     return View();
 }