Exemplo n.º 1
0
        //================ ON FORM LOAD EVENT =======================================================
        private void frmAddContact_Load(object sender, EventArgs e)
        {
            try
            {
                //Loads contact types into the form when the form first opens
                DataTable dataTable = ContactDb.GetAllContactTypes();
                System.Diagnostics.Debug.WriteLine(dataTable.Columns);

                //allows user input to list states that begin wtih the input
                cboContactType.AutoCompleteSource = AutoCompleteSource.ListItems;
                cboContactType.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;

                // fill state combo box with state names from database
                var lst = new List <String>();
                foreach (DataRow row in dataTable.Rows)
                {
                    lst.Add(row["ContactType"].ToString());
                }
                cboContactType.Items.Clear();
                cboContactType.DataSource = lst;
                //sets intial values of state combo box and state SP pararamter to "" so defalut
                // value is null if no state is selected by the user.
                cboContactType.Text = "";
            }
            catch
            {
                MessageBox.Show("Database Error, contact types are not available.  " +
                                "Contact administrator");
            }
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsValidData())
                {
                    //If the data is valid, then initialize fields to string or int and instanciate Customer object
                    contactType = (txtContactType.Text.ToUpper());

                    try
                    {
                        DataTable dataTable = ContactDb.GetAllContactTypes();

                        // get list of all contact types
                        var lst = new List <String>();

                        foreach (DataRow row in dataTable.Rows)  // Check to see if the contact type entered already exists
                        {
                            if (row["ContactType"].ToString() == contactType)
                            {
                                MessageBox.Show("Contact Type " + contactType + " already exists, please re-enter.");
                                txtContactType.Text = "";
                                txtContactType.Focus();
                                return;
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Database Error, contact types are not available.  " +
                                        "Contact administrator");
                        txtContactType.Text = "";
                        txtContactType.Focus();
                    }

                    //Attempt to add new contact type to database
                    dbUpdateSuccessful = ContactDb.AddContactType(contactType);

                    if (dbUpdateSuccessful == 0)
                    {
                        txtContactType.Text = "";
                        txtContactType.Focus();
                        MessageBox.Show("Database exception, contact type has " +
                                        "not been added. Contact administrator.");
                    }
                    else
                    {
                        txtContactType.Text = "";
                        txtContactType.Focus();
                        MessageBox.Show("Contact Type Added.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" +
                                ex.GetType().ToString() + "/n" +
                                ex.StackTrace, "Exception");
            }
        }
Exemplo n.º 3
0
 public ContactRepo(ContactDb context,
                    IPropertyMappingService propertyMappingService)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     _propertyMappingService = propertyMappingService ??
                               throw new ArgumentNullException(nameof(propertyMappingService));
 }
Exemplo n.º 4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //capture selected item of contact type highlighted to be deleted

            string selectedContactType = "";

            selectedContactType = lstContactType.GetItemText(lstContactType.SelectedItem);
            if (selectedContactType == "")
            {
                MessageBox.Show("No Contact Type selected.");
                return;
            }

            //check to see if contact type is currently being used and, therefore, cannot be delelted
            try
            {
                CkContactTypeExits = ContactDb.GetContactTypes(selectedContactType);
                if (CkContactTypeExits != 0)
                {
                    MessageBox.Show("Cannot delete '" + selectedContactType + "' contact type because " +
                                    "it is currently assigned to a contact.");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Database Error, contact types are not available.  " +
                                "Contact administrator");
                return;
            }

            //Attempt to delete contact type from database
            try
            {
                dbDeleteSuccessful = ContactDb.DeleteContactType(selectedContactType);

                if (dbDeleteSuccessful == 0)
                {
                    MessageBox.Show("Database exception, contact type has " +
                                    "not been deleted. Contact administrator.");
                    return;
                }
                else
                {
                    MessageBox.Show("Contact Type Deleted.");
                    loadFormData();
                }
            }
            catch
            {
                MessageBox.Show("Database Error, contact types are not available.  " +
                                "Contact administrator");
                return;
            }
        }
Exemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            bool   result = false;
            string action = context.Request["action"] ?? "";

            try
            {
                if (action == "select")
                {
                    string con = ContactDb.GetSingle("2");
                    context.Response.Write(con);
                    return;
                }
                string title   = context.Request["title"] ?? "";
                string id      = context.Request["id"] ?? "";
                string content = context.Request["content"] ?? "";

                Contact contact = new Contact()
                {
                    Title      = title,
                    Id         = id,
                    Content    = content,
                    CreateTime = DateTime.Now,
                    ModifyTime = DateTime.Now
                };
                if (action == "update")
                {
                    result = ContactDb.Update(contact);
                }
                else
                {
                    result = ContactDb.Add(contact);
                }
            }
            catch (Exception ex)
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write(ex.Message);
            }

            String message = result == true ? "操作成功" : "操作失败";

            context.Response.ContentType = "text/plain";
            context.Response.Write(message);
        }
Exemplo n.º 6
0
 private void loadFormData()
 {
     try
     {
         var dataTable = ContactDb.GetAllContactTypes();  // GET ALL CONTACTS
         var lst       = new List <String>();
         foreach (DataRow row in dataTable.Rows)
         {
             lst.Add(row["ContactType"].ToString());
         }
         lstContactType.DataSource = lst;
     }
     catch
     {
         MessageBox.Show("Database Error, contact types are not available.  " +
                         "Contact administrator");
     }
 }
Exemplo n.º 7
0
//=====================================================================================

//=========== ON SUBMIT BUTTON CLICKED =====================================================
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsValidData())
                {
                    //If the data is valid, then initialize fields to string or int and instanciate Customer object
                    contactFirstName = (txtContactFirstName.Text);
                    contactLastName  = (txtContactLastName.Text);
                    contactType      = (cboContactType.Text);
                    contactNote      = (txtContactNote.Text);
                    contactStreet    = (txtStreet.Text);
                    contactCity      = (txtCity.Text);
                    contactState     = (txtState.Text);

                    //Instantiate Contact Object
                    Contact contact = new Contact(contactFirstName, contactLastName, contactType,
                                                  contactNote, contactStreet, contactCity, contactState);

                    //Invoke AddContact Db stored procedure and pass in contact object
                    dbUpdateSuccessful = ContactDb.AddContact(contact);

                    if (dbUpdateSuccessful == 0)
                    {
                        ClearAllFields();
                        MessageBox.Show("Database exception, contact administrator.");
                    }
                    else
                    {
                        ClearAllFields();
                        MessageBox.Show("Contact Added.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" +
                                ex.GetType().ToString() + "/n" +
                                ex.StackTrace, "Exception");
            }
        } // end btn click
Exemplo n.º 8
0
        public async Task CreateContact([FromBody] CreateEntityRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var userId = User.Claims.GetUserId();

            var contactDb = new ContactDb
            {
                Name              = request.Name,
                UserId            = userId,
                Notes             = "[]",
                Gender            = Gender.Undefined,
                AddressCategories = DefaultAddressCategories(),
                PhoneCategories   = DefaultPhoneCategories()
            };

            await _dbService.Insert(contactDb);
        }
        public ActionResult CreateContact()
        {
            //DateTime myDateTime = DateTime.Now;
            //string sqlformattedDate = myDateTime.ToString("yyyy-MM-dd hh:mm:ss.fff");

            var batchName = getBatchName();

            ContactBatch batch = new ContactBatch
            {
                BatchName   = batchName,
                CreatedBy   = "System",
                DateCreated = DateTime.Now
                              //DateCreated = Convert.ToDateTime(sqlformattedDate)
            };
            int batchId = ContactBatchDB.GetBatchID(batch);
            List <ContactVM> contacts = new List <ContactVM>();

            contacts = (List <ContactVM>)Session["Upload"];
            ContactDb.PostToDatabase(contacts, batchId);
            return(View(contacts));
        }
Exemplo n.º 10
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            srchLastName = txtSrchLastName.Text;

            try
            {
                var dataTable = ContactDb.GetContactXLastName(srchLastName);  // GET ALL CONTACTS
                var lst       = new List <String>();
                foreach (DataRow row in dataTable.Rows)
                {
                    lst.Add(row["ContactFirstName"].ToString() + ", " + row["ContactLastName"].ToString() +
                            row["ContactCoName"].ToString() + ", " + row["ContactJobTitle"].ToString() + ", " +
                            row["ContactType"].ToString());
                }
                lstSrchResults.DataSource = lst;
            }
            catch
            {
                MessageBox.Show("Database Error, contact types are not available.  " +
                                "Contact administrator");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// By submitting ID of the user in the body of the request, you can attempt to "Friend" them
        /// </summary>
        /// <param name="contactID">returns 200 if successfull, or will reply if unsuccessfull</param>
        public async Task <dynamic> Post([FromBody] long contactID)
        {
            var UserId = long.Parse(User.Identity.GetUserId());

            bool exists = await db.Contacts.AnyAsync(
                p => (p.Person1Id == UserId && p.Person2Id == contactID) ||
                (p.Person1Id == contactID && p.Person2Id == UserId));

            if (exists)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.CantOverrite));
            }

            if (!await db.Users.AnyAsync(u => u.Id == contactID))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.DoesntExist));
            }

            ContactDb newContact = new ContactDb
            {
                State     = ContactDb.StatePendingP2,
                Person1Id = UserId,
                Person2Id = contactID
            };

            db.Contacts.Add(newContact);
            await db.SaveChangesAsync();

            var parties = await db.Users.Where(p => p.Id == contactID || p.Id == UserId).ToArrayAsync();

            long   phone     = parties.First(p => p.Id == contactID).PhoneNumber;
            string actorName = parties.First(p => p.Id == UserId).FirstName + " " + parties.First(p => p.Id == UserId).LastName;
            string message   = "Hive: " + String.Format("{0} has sent you a friend request!", actorName);

            SMSService.SendMessage(phone.ToString(), message); //We don;t want to await an SMS, really

            return(Ok(newContact.ToContact(UserId)));
        }
Exemplo n.º 12
0
        public TestSaveContact()
        {
            var contacts = new[]
            {
                new Contact
                {
                    Id          = 1,
                    FirstName   = "First",
                    LastName    = "Last",
                    Email       = "*****@*****.**",
                    PhoneNumber = "555-1212"
                },
            }.ToDbSet();

            _db = A.Fake <ContactDb>();
            A.CallTo(() => _db.Contacts).Returns(contacts);

            _appContext = A.Fake <AppContext>();
            _queue      = A.Fake <IQueueService>();
            _mediator   = A.Fake <IMediator>();

            _handler = new SaveContact.Handler(_db, _appContext, _queue, _mediator);
        }
 public ActionResult GetFileById(int id)
 {
     return(View(ContactDb.GetContactsByBatchId(id)));
 }