Exemple #1
0
 public bool Add(Category info)
 {
     bool result = false;
     try
     {
         result = WriteCategory(ProceduresNames.CategoryAdd, info, true);
     }
     catch (Exception error)
     {
         throw error;
     }
     return result;
 }
Exemple #2
0
        private bool WriteCategory(string ProcedureName, Category 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, Category.TableColumns.NameAr), info.NameAr);
                command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Category.TableColumns.NameEn), info.NameEn);
                command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Category.TableColumns.CanHaveOffers), info.CanHaveOffers);

                if (info.ParentID.HasValue)
                    command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Category.TableColumns.ParentID), info.ParentID);
                else
                    command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Category.TableColumns.ParentID), DBNull.Value);

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

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

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

                this.OpenConnection();

                command.ExecuteNonQuery();

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

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

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

                        info.ID = Convert.ToInt32(reader[Category.CommonColumns.ID]);
                        info.NameAr = Convert.ToString(reader[Category.TableColumns.NameAr]);
                        info.NameEn = Convert.ToString(reader[Category.TableColumns.NameEn]);
                        info.HasChildren = Convert.ToBoolean(reader[Category.TableColumns.HasChildren]);
                        info.HasOffers = Convert.ToBoolean(reader[Category.TableColumns.HasOffers]);
                        info.CanHaveOffers = Convert.ToBoolean(reader[Category.TableColumns.CanHaveOffers]);
                        info.CreationDate = Convert.ToDateTime(reader[Category.CommonColumns.CreationDate]);

                        if (reader[Category.TableColumns.ParentID] != DBNull.Value)
                            info.ParentID = Convert.ToInt32(reader[Category.TableColumns.ParentID]);
                        else
                            info.ParentID = null;

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

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

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

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

                            info.ID = Convert.ToInt32(reader[Category.CommonColumns.ID]);
                            info.NameAr = Convert.ToString(reader[Category.TableColumns.NameAr]);
                            info.HasChildren = Convert.ToBoolean(reader[Category.TableColumns.HasChildren]);
                            info.HasOffers = Convert.ToBoolean(reader[Category.TableColumns.HasOffers]);
                            info.CanHaveOffers = Convert.ToBoolean(reader[Category.TableColumns.CanHaveOffers]);

                            if (reader[Category.TableColumns.ParentID] != DBNull.Value)
                                info.ParentID = Convert.ToInt32(reader[Category.TableColumns.ParentID]);
                            else
                                info.ParentID = null;

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

                            info.ID = Convert.ToInt32(reader[Category.CommonColumns.ID]);
                            info.NameEn = Convert.ToString(reader[Category.TableColumns.NameEn]);
                            info.HasChildren = Convert.ToBoolean(reader[Category.TableColumns.HasChildren]);
                            info.HasOffers = Convert.ToBoolean(reader[Category.TableColumns.HasOffers]);
                            info.CanHaveOffers = Convert.ToBoolean(reader[Category.TableColumns.CanHaveOffers]);

                            if (reader[Category.TableColumns.ParentID] != DBNull.Value)
                                info.ParentID = Convert.ToInt32(reader[Category.TableColumns.ParentID]);
                            else
                                info.ParentID = null;

                            infoList.Add(info);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                throw error;
            }
        }