Beispiel #1
0
        public bool AddPoll(Poll info)
        {
            bool result = false;
            try
            {
                result = WritePoll(ProceduresNames.PollAdd, info, true);

                foreach (PollOption option in info.Options)
                {
                    if (result)
                    {
                        option.PollID = info.ID;
                        result = AddOption(option);
                    }
                    else
                    {
                        throw new Exception("Not All Options Added");
                    }
                }
            }
            catch (Exception error)
            {
                throw error;
            }
            return result;
        }
Beispiel #2
0
        private bool WritePoll(string ProcedureName, Poll info, bool IsNew)
        {
            bool result = false;
            try
            {
                SqlCommand command = new SqlCommand(ProcedureName, this.Connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Poll.TableColumns.TitleAr), info.TitleAr);
                command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Poll.TableColumns.TitleEn), info.TitleEn);

                if (IsNew)
                {
                    command.Parameters.Add(string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.ID), SqlDbType.Int);
                    command.Parameters[string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.ID)].Direction = ParameterDirection.Output;

                    if (info.CreatedBy.HasValue)
                        command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.CreatedBy), info.CreatedBy.Value);
                    else
                        command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.CreatedBy), DBNull.Value);
                }
                else
                {
                    command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.ID), info.ID);

                    if (info.ModifiedBy.HasValue)
                        command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.ModifiedBy), info.ModifiedBy.Value);
                    else
                        command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.ModifiedBy), DBNull.Value);
                }

                this.OpenConnection();

                command.ExecuteNonQuery();

                if (IsNew)
                {
                    info.ID = Convert.ToInt32(command.Parameters[string.Concat(CommonStrings.AtSymbol, Poll.CommonColumns.ID)].Value);
                }

                result = true;
            }
            catch (Exception error)
            {
                throw error;
            }
            finally
            {
                this.CloseConnection();
            }
            return result;
        }
Beispiel #3
0
        private void ReadPollList(SqlDataReader reader, List<Poll> infoList, bool? IsArabic)
        {
            try
            {
                Poll info = null;

                if (!IsArabic.HasValue)
                {
                    while (reader.Read())
                    {
                        info = new Poll();

                        info.ID = Convert.ToInt32(reader[Poll.CommonColumns.ID]);
                        info.TitleAr = Convert.ToString(reader[Poll.TableColumns.TitleAr]);
                        info.TitleEn = Convert.ToString(reader[Poll.TableColumns.TitleEn]);
                        info.TotalVotes = Convert.ToInt32(reader[Poll.TableColumns.TotalVotes]);
                        info.IsNew = Convert.ToBoolean(reader[Poll.TableColumns.IsNew]);
                        info.IsCurrent = Convert.ToBoolean(reader[Poll.TableColumns.IsCurrent]);
                        info.IsArchived = Convert.ToBoolean(reader[Poll.TableColumns.IsArchived]);
                        info.CreationDate = Convert.ToDateTime(reader[Poll.CommonColumns.CreationDate]);

                        if (reader[Poll.CommonColumns.CreatedBy] != DBNull.Value)
                            info.CreatedBy = (Guid)reader[Poll.CommonColumns.CreatedBy];
                        else
                            info.CreatedBy = null;

                        if (reader[Poll.TableColumns.CurrentBy] != DBNull.Value)
                            info.CurrentBy = (Guid)reader[Poll.TableColumns.CurrentBy];
                        else
                            info.CurrentBy = null;

                        if (reader[Poll.TableColumns.CurrentDate] != DBNull.Value)
                            info.CurrentDate = Convert.ToDateTime(reader[Poll.TableColumns.CurrentDate]);
                        else
                            info.CurrentDate = null;

                        if (reader[Poll.TableColumns.ArchiveDate] != DBNull.Value)
                            info.ArchiveDate = Convert.ToDateTime(reader[Poll.TableColumns.ArchiveDate]);
                        else
                            info.ArchiveDate = null;

                        if (reader[Poll.TableColumns.ArchivedBy] != DBNull.Value)
                            info.ArchivedBy = (Guid)reader[Poll.TableColumns.ArchivedBy];
                        else
                            info.ArchivedBy = null;

                        if (reader[Poll.CommonColumns.ModificationDate] != DBNull.Value)
                            info.ModificationDate = Convert.ToDateTime(reader[Poll.CommonColumns.ModificationDate]);
                        else
                            info.ModificationDate = null;

                        if (reader[Poll.CommonColumns.ModifiedBy] != DBNull.Value)
                            info.ModifiedBy = (Guid)reader[Poll.CommonColumns.ModifiedBy];
                        else
                            info.ModifiedBy = null;

                        infoList.Add(info);
                    }
                }
                else
                {
                    if (IsArabic.Value)
                    {
                        while (reader.Read())
                        {
                            info = new Poll();

                            info.ID = Convert.ToInt32(reader[Poll.CommonColumns.ID]);
                            info.TitleAr = Convert.ToString(reader[Poll.TableColumns.TitleAr]);
                            info.TotalVotes = Convert.ToInt32(reader[Poll.TableColumns.TotalVotes]);
                            info.IsNew = Convert.ToBoolean(reader[Poll.TableColumns.IsNew]);
                            info.IsCurrent = Convert.ToBoolean(reader[Poll.TableColumns.IsCurrent]);
                            info.IsArchived = Convert.ToBoolean(reader[Poll.TableColumns.IsArchived]);
                            info.CreationDate = Convert.ToDateTime(reader[Poll.CommonColumns.CreationDate]);

                            if (reader[Poll.TableColumns.CurrentDate] != DBNull.Value)
                                info.CurrentDate = Convert.ToDateTime(reader[Poll.TableColumns.CurrentDate]);
                            else
                                info.CurrentDate = null;

                            if (reader[Poll.TableColumns.ArchiveDate] != DBNull.Value)
                                info.ArchiveDate = Convert.ToDateTime(reader[Poll.TableColumns.ArchiveDate]);
                            else
                                info.ArchiveDate = null;

                            infoList.Add(info);
                        }
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            info = new Poll();

                            info.ID = Convert.ToInt32(reader[Poll.CommonColumns.ID]);
                            info.TitleEn = Convert.ToString(reader[Poll.TableColumns.TitleEn]);
                            info.TotalVotes = Convert.ToInt32(reader[Poll.TableColumns.TotalVotes]);
                            info.IsNew = Convert.ToBoolean(reader[Poll.TableColumns.IsNew]);
                            info.IsCurrent = Convert.ToBoolean(reader[Poll.TableColumns.IsCurrent]);
                            info.IsArchived = Convert.ToBoolean(reader[Poll.TableColumns.IsArchived]);
                            info.CreationDate = Convert.ToDateTime(reader[Poll.CommonColumns.CreationDate]);

                            if (reader[Poll.TableColumns.CurrentDate] != DBNull.Value)
                                info.CurrentDate = Convert.ToDateTime(reader[Poll.TableColumns.CurrentDate]);
                            else
                                info.CurrentDate = null;

                            if (reader[Poll.TableColumns.ArchiveDate] != DBNull.Value)
                                info.ArchiveDate = Convert.ToDateTime(reader[Poll.TableColumns.ArchiveDate]);
                            else
                                info.ArchiveDate = null;

                            infoList.Add(info);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                throw error;
            }
        }
Beispiel #4
0
 public bool UpdatePoll(Poll info)
 {
     bool result = false;
     try
     {
         result = WritePoll(ProceduresNames.PollUpdate, info, false);
     }
     catch (Exception error)
     {
         throw error;
     }
     return result;
 }