コード例 #1
0
        private static bool ValidateEmail(EmailAddress emailToValidate, ref BrokenRuleCollection brokenRules)
        {
            //set default return value to true
            bool returnValue = true;

            //Validate email address
            if (emailToValidate != null)
            {
                if (!string.IsNullOrEmpty(emailToValidate.EmailAddressName))
                {
                    if (!EmailValidator.IsValid(emailToValidate.EmailAddressName.Trim()))
                    {
                        //email was not in a valid format
                        brokenRules.Add("Email Address", emailToValidate.EmailAddressName.Trim() + " is an invalid email format.");
                        returnValue = false;
                    }
                }
                else
                {
                    //email is required
                    brokenRules.Add("Email Address", "Email is Required.");
                    returnValue = false;
                }
            }
            else
            {
                brokenRules.Add("Email Address", "Email class was not instantiated");
                returnValue = false;
            }
            return returnValue;
        }
コード例 #2
0
        public static int SAVE(int personId, EmailAddress emailToSave)
        {
            BrokenRuleCollection saveBrokenRules = new BrokenRuleCollection();

            if (personId <= 0)
                saveBrokenRules.Add("Person", "Invalid ID.");

            //make sure Email is in the correct format
            ValidateEmail(emailToSave, ref saveBrokenRules);

            //email type is required
            if(emailToSave.EmailType.EntityTypeId <=0)
            {
                saveBrokenRules.Add("Email Address Type", "Type is Required.");
            }

            //check for validation errors
            if(saveBrokenRules.Count() > 0)
            {
                throw new BLLException("There was an error saving Email.", saveBrokenRules);
            }
            else 
            {
                //validation success - call DAL to save
                return EmailAddressDAL.Save(personId, emailToSave);
            }
        }
コード例 #3
0
        public static int Save(int employeeId, EmailAddress emailToSave)
        {
            int result = 0;
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;

            //Checks for valid personId - if exsitis, UPDATE else INSERT
            //10 Insert
            //20 Update
            if (emailToSave.EmailId > 0)
                queryId = ExecuteTypeEnum.UpdateItem;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_ExecuteEmail", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@QueryId", queryId);
                    myCommand.Parameters.AddWithValue("@EmployeeId", employeeId);


                    if (emailToSave.EmailId > 0)
                        myCommand.Parameters.AddWithValue("@EmailId", emailToSave.EmailId);

                    if (emailToSave.EmailAddressName != null)
                        myCommand.Parameters.AddWithValue("@EmailAddress", emailToSave.EmailAddressName);

                    if (emailToSave.EmailType != null)
                        myCommand.Parameters.AddWithValue("@EntityTypeId", emailToSave.EmailType.EntityTypeId);

                    //add return parameter to command object
                    myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("returnValue"));

                    myConnection.Open();
                    myCommand.ExecuteNonQuery();

                    //get returned Value from stored procedure and return Id
                    result = (int)myCommand.Parameters["@returnValue"].Value;
                }
                myConnection.Close();
            }
            return result;
        }
コード例 #4
0
        private void BindEmailType()
        {
            #region Notes
            //ListItemCollection emailTypeList = new ListItemCollection();
            //ListItem emailTypeItem;

            //emailTypeItem = new ListItem();
            //emailTypeItem.Text = "Code Behind Option 01";
            //emailTypeItem.Value = "1";
            //emailTypeList.Add(emailTypeItem);

            //emailTypeItem = new ListItem();
            //emailTypeItem.Text = "Code Behind Option 02";
            //emailTypeItem.Value = "2";
            //emailTypeList.Add(emailTypeItem);

            //emailTypeItem = new ListItem();
            //emailTypeItem.Text = "Code Behind Option 03";
            //emailTypeItem.Value = "3";
            //emailTypeList.Add(emailTypeItem);

            //EmailTypeList.DataSource = emailTypeList;
            //EmailTypeList.DataBind();
            #endregion
            EntityTypeCollection emailTypeList = EntityTypeManager.GetCollection(EntityEnum.Email);

            EmailTypeList.DataSource = emailTypeList;
            EmailTypeList.DataBind();

            //add defalut item
            EmailTypeList.Items.Insert(0, new ListItem { Text = "Select Email Type", Value = "0" });

            EmailAddress testEmail = new EmailAddress();
            testEmail.EmailType.EntityTypeId = 1;
            testEmail.EmailType.EntityTypeValue = "test";

        }
コード例 #5
0
        private void ProcessEmail()
        {
            EmailAddress emailToSave = new EmailAddress(EmailTypeList.SelectedItem.Value.ToInt(), EmailaddressFeild.Text);

            //set EmailId property for Update
            emailToSave.EmailId = EmailId.Value.ToInt();
            try
            {
                //Call middle tier to save
                EmailAddressManager.SAVE(base.EmployeeId, emailToSave);

                Response.Redirect("Email.aspx?EmployeeId=" + base.EmployeeId.ToString());
            }
            catch(BLLException ex)
            {
                //display message and any broken rules if they exist
                if (ex.BrokenRules != null && ex.BrokenRules.Count() > 0)
                    this.DisplayLocalMessage(ex.Message, ex.BrokenRules);
                else
                    this.DisplayLocalMessage(ex.Message);
            }
        }
コード例 #6
0
        private static EmailAddress FillDataRecord(IDataRecord myDataRecord)
        {
            EmailAddress myObject = new EmailAddress();

            myObject.EmailId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("EmailId"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("EmailValue")))
                myObject.EmailAddressName = myDataRecord.GetString(myDataRecord.GetOrdinal("EmailValue"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("EntityTypeId")))
            {
                myObject.EmailType.EntityTypeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("EntityTypeId"));

                if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("EntityTypeValue")))
                    myObject.EmailType.EntityTypeValue = myDataRecord.GetString(myDataRecord.GetOrdinal("EntityTypeValue"));
            }

            return myObject;
        }