コード例 #1
0
        public void Delete(Contact contactToDelete)
        {
            var originalContact = Get(contactToDelete.Id);
            _entities.DeleteObject(originalContact);
            _entities.SaveChanges();

        }
コード例 #2
0
        public Contact Create(Contact contactToCreate)
        {
            _entities.AddToContactSet(contactToCreate);
            _entities.SaveChanges();
            return contactToCreate;

        }
コード例 #3
0
        public ContactViewModel(Contact contact)
        {
            //creating the elements for contact status and contact priority drop down lists
            var statuses = Enum.GetNames(typeof(ContactStatus));

            Contact = contact;
            Statuses = new SelectList(statuses, Contact.Status);
        }
コード例 #4
0
        public Contact Update(Contact contactToUpdate)
        {
            var originalContact = Get(contactToUpdate.Id);
            _entities.ApplyCurrentValues(originalContact.EntityKey.EntitySetName, contactToUpdate);
            _entities.SaveChanges();
            return contactToUpdate;

        }
コード例 #5
0
        public bool EditContact(Contact contactToEdit)
        {
            // Validation logic
            if (!ValidateContact(contactToEdit))
                return false;

            // Database logic
            try
            {
                _repository.Update(contactToEdit);
            }
            catch
            {
                return false;
            }
            return true;
        }
コード例 #6
0
        public bool CreateContact(Contact contactToCreate)
        {
            // Validation logic
            if (!ValidateContact(contactToCreate))
                return false;

            // Database logic
            try
            {
                _repository.Create(contactToCreate);
            }
            catch
            {
                return false;
            }
            return true;
        }
コード例 #7
0
        public bool ValidateContact(Contact contactToValidate)
        {
            //convert null values to empty strings
            contactToValidate.FirstName = contactToValidate.FirstName ?? "";
            contactToValidate.LastName = contactToValidate.LastName ?? "";
            contactToValidate.Address = contactToValidate.Address ?? "";
            contactToValidate.Email = contactToValidate.Email ?? "";

            if (contactToValidate.FirstName.Trim().Length == 0)
                _validationDictionary.AddError("Contact.FirstName", "First name is required.");
            if (contactToValidate.LastName.Trim().Length == 0)
                _validationDictionary.AddError("Contact.LastName", "Last name is required.");
            if (contactToValidate.Address.Trim().Length == 0)
                _validationDictionary.AddError("Contact.Address", "Address is required.");
            if (contactToValidate.Email.Length > 0 && !Regex.IsMatch(contactToValidate.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
                _validationDictionary.AddError("Contact.Email", "Invalid email address.");

            return _validationDictionary.IsValid;
        }
コード例 #8
0
 public ActionResult Delete(Contact contact)
 {
     if (!_contactService.DeleteContact(contact))
         return View(contact);
     return RedirectToAction("Index");
 }
コード例 #9
0
 /// <summary>
 /// Create a new Contact object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 public static Contact CreateContact(global::System.Int32 id, global::System.String lastName, global::System.String firstName, global::System.String address, global::System.String status, global::System.String email)
 {
     Contact contact = new Contact();
     contact.Id = id;
     contact.LastName = lastName;
     contact.FirstName = firstName;
     contact.Address = address;
     contact.Status = status;
     contact.Email = email;
     return contact;
 }
コード例 #10
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ContactSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToContactSet(Contact contact)
 {
     base.AddObject("ContactSet", contact);
 }
コード例 #11
0
 public bool DeleteContact(Contact contactToDelete)
 {
     try
     {
         _repository.Delete(contactToDelete);
     }
     catch
     {
         return false;
     }
     return true;
 }