public bool Add(Offer info) { bool result = false; try { result = WriteOffer(ProceduresNames.OfferAdd, info, true); } catch (Exception error) { throw error; } return result; }
private void ReadOffersList(SqlDataReader reader, List<Offer> infoList, bool? IsArabic) { try { Offer info = null; if (!IsArabic.HasValue) { while (reader.Read()) { info = new Offer(); info.ID = Convert.ToInt32(reader[Offer.CommonColumns.ID]); info.CategoryID = Convert.ToInt32(reader[Offer.TableColumns.CategoryID]); info.SupplierID = Convert.ToInt32(reader[Offer.TableColumns.SupplierID]); info.CurrencyInfo.ID = Convert.ToInt32(reader[Offer.TableColumns.CurrencyID]); info.Image = Convert.ToString(reader[Offer.TableColumns.Image]); info.IsProduct = Convert.ToBoolean(reader[Offer.TableColumns.IsProduct]); info.IsSale = Convert.ToBoolean(reader[Offer.TableColumns.IsSale]); info.IsPackage = Convert.ToBoolean(reader[Offer.TableColumns.IsPackage]); info.IsBestDeal = Convert.ToBoolean(reader[Offer.TableColumns.IsBestDeal]); info.IsFeaturedOffer = Convert.ToBoolean(reader[Offer.TableColumns.IsFeaturedOffer]); info.Rate = Convert.ToInt32(reader[Offer.TableColumns.Rate]); info.RateCount = Convert.ToInt32(reader[Offer.TableColumns.RateCount]); info.RateTotal = Convert.ToInt32(reader[Offer.TableColumns.RateTotal]); info.Likes = Convert.ToInt32(reader[Offer.TableColumns.Likes]); info.Views = Convert.ToInt32(reader[Offer.TableColumns.Views]); info.IsActive = Convert.ToBoolean(reader[Offer.TableColumns.IsActive]); info.NameAr = Convert.ToString(reader[Offer.TableColumns.NameAr]); info.NameEn = Convert.ToString(reader[Offer.TableColumns.NameEn]); info.TitleAr = Convert.ToString(reader[Offer.TableColumns.TitleAr]); info.TitleEn = Convert.ToString(reader[Offer.TableColumns.TitleEn]); info.ShortDescriptionAr = Convert.ToString(reader[Offer.TableColumns.ShortDescriptionAr]); info.ShortDescriptionEn = Convert.ToString(reader[Offer.TableColumns.ShortDescriptionEn]); info.CreationDate = Convert.ToDateTime(reader[Offer.CommonColumns.CreationDate]); if (reader[Offer.TableColumns.BrandID] != DBNull.Value) info.BrandID = Convert.ToInt32(reader[Offer.TableColumns.BrandID]); else info.BrandID = null; if (reader[Offer.TableColumns.StartDate] != DBNull.Value) info.StartDate = Convert.ToDateTime(reader[Offer.TableColumns.StartDate]); else info.StartDate = null; if (reader[Offer.TableColumns.EndDate] != DBNull.Value) info.EndDate = Convert.ToDateTime(reader[Offer.TableColumns.EndDate]); else info.EndDate = null; if (reader[Offer.TableColumns.OldPrice] != DBNull.Value) info.OldPrice = Convert.ToDecimal(reader[Offer.TableColumns.OldPrice]); else info.OldPrice = null; if (reader[Offer.TableColumns.NewPrice] != DBNull.Value) info.NewPrice = Convert.ToDecimal(reader[Offer.TableColumns.NewPrice]); else info.NewPrice = null; if (reader[Offer.TableColumns.DiscountPercentage] != DBNull.Value) info.DiscountPercentage = Convert.ToInt32(reader[Offer.TableColumns.DiscountPercentage]); else info.DiscountPercentage = null; if (reader[Offer.TableColumns.SaleUpTo] != DBNull.Value) info.SaleUpTo = Convert.ToInt32(reader[Offer.TableColumns.SaleUpTo]); else info.SaleUpTo = null; if (reader[Offer.TableColumns.PackageDescriptionAr] != DBNull.Value) info.PackageDescriptionAr = Convert.ToString(reader[Offer.TableColumns.PackageDescriptionAr]); if (reader[Offer.TableColumns.PackageDescriptionEn] != DBNull.Value) info.PackageDescriptionEn = Convert.ToString(reader[Offer.TableColumns.PackageDescriptionEn]); if (reader[Offer.TableColumns.DescriptionAr] != DBNull.Value) info.DescriptionAr = Convert.ToString(reader[Offer.TableColumns.DescriptionAr]); if (reader[Offer.TableColumns.DescriptionEn] != DBNull.Value) info.DescriptionEn = Convert.ToString(reader[Offer.TableColumns.DescriptionEn]); if (reader[Currency.TableColumns.UnitAr] != DBNull.Value) info.CurrencyInfo.UnitAr = Convert.ToString(reader[Currency.TableColumns.UnitAr]); if (reader[Currency.TableColumns.UnitEn] != DBNull.Value) info.CurrencyInfo.UnitEn = Convert.ToString(reader[Currency.TableColumns.UnitEn]); if (reader[Offer.TableColumns.ActivationDate] != DBNull.Value) info.ActivationDate = Convert.ToDateTime(reader[Offer.TableColumns.ActivationDate]); else info.ActivationDate = null; if (reader[Offer.TableColumns.ActivatedBy] != DBNull.Value) info.ActivatedBy = (Guid)reader[Offer.TableColumns.ActivatedBy]; else info.ActivatedBy = null; if (reader[Offer.TableColumns.DeactivationDate] != DBNull.Value) info.DeactivationDate = Convert.ToDateTime(reader[Offer.TableColumns.DeactivationDate]); else info.DeactivationDate = null; if (reader[Offer.TableColumns.DeactivatedBy] != DBNull.Value) info.DeactivatedBy = (Guid)reader[Offer.TableColumns.DeactivatedBy]; else info.DeactivatedBy = null; if (reader[Offer.CommonColumns.CreatedBy] != DBNull.Value) info.CreatedBy = (Guid)reader[Offer.CommonColumns.CreatedBy]; else info.CreatedBy = null; if (reader[Offer.CommonColumns.ModificationDate] != DBNull.Value) info.ModificationDate = Convert.ToDateTime(reader[Offer.CommonColumns.ModificationDate]); else info.ModificationDate = null; if (reader[Offer.CommonColumns.ModifiedBy] != DBNull.Value) info.ModifiedBy = (Guid)reader[Offer.CommonColumns.ModifiedBy]; else info.ModifiedBy = null; infoList.Add(info); } } else { if (IsArabic.Value) { while (reader.Read()) { info = new Offer(); info.ID = Convert.ToInt32(reader[Offer.CommonColumns.ID]); info.CategoryID = Convert.ToInt32(reader[Offer.TableColumns.CategoryID]); info.SupplierID = Convert.ToInt32(reader[Offer.TableColumns.SupplierID]); info.CurrencyInfo.ID = Convert.ToInt32(reader[Offer.TableColumns.CurrencyID]); info.Image = Convert.ToString(reader[Offer.TableColumns.Image]); info.IsProduct = Convert.ToBoolean(reader[Offer.TableColumns.IsProduct]); info.IsSale = Convert.ToBoolean(reader[Offer.TableColumns.IsSale]); info.IsPackage = Convert.ToBoolean(reader[Offer.TableColumns.IsPackage]); info.IsBestDeal = Convert.ToBoolean(reader[Offer.TableColumns.IsBestDeal]); info.IsFeaturedOffer = Convert.ToBoolean(reader[Offer.TableColumns.IsFeaturedOffer]); info.Rate = Convert.ToInt32(reader[Offer.TableColumns.Rate]); info.RateCount = Convert.ToInt32(reader[Offer.TableColumns.RateCount]); info.RateTotal = Convert.ToInt32(reader[Offer.TableColumns.RateTotal]); info.Likes = Convert.ToInt32(reader[Offer.TableColumns.Likes]); info.Views = Convert.ToInt32(reader[Offer.TableColumns.Views]); info.IsActive = Convert.ToBoolean(reader[Offer.TableColumns.IsActive]); info.NameAr = Convert.ToString(reader[Offer.TableColumns.NameAr]); info.TitleAr = Convert.ToString(reader[Offer.TableColumns.TitleAr]); info.ShortDescriptionAr = Convert.ToString(reader[Offer.TableColumns.ShortDescriptionAr]); info.CreationDate = Convert.ToDateTime(reader[Offer.CommonColumns.CreationDate]); if (reader[Offer.TableColumns.BrandID] != DBNull.Value) info.BrandID = Convert.ToInt32(reader[Offer.TableColumns.BrandID]); else info.BrandID = null; if (reader[Offer.TableColumns.StartDate] != DBNull.Value) info.StartDate = Convert.ToDateTime(reader[Offer.TableColumns.StartDate]); else info.StartDate = null; if (reader[Offer.TableColumns.EndDate] != DBNull.Value) info.EndDate = Convert.ToDateTime(reader[Offer.TableColumns.EndDate]); else info.EndDate = null; if (reader[Offer.TableColumns.OldPrice] != DBNull.Value) info.OldPrice = Convert.ToDecimal(reader[Offer.TableColumns.OldPrice]); else info.OldPrice = null; if (reader[Offer.TableColumns.NewPrice] != DBNull.Value) info.NewPrice = Convert.ToDecimal(reader[Offer.TableColumns.NewPrice]); else info.NewPrice = null; if (reader[Offer.TableColumns.DiscountPercentage] != DBNull.Value) info.DiscountPercentage = Convert.ToInt32(reader[Offer.TableColumns.DiscountPercentage]); else info.DiscountPercentage = null; if (reader[Offer.TableColumns.SaleUpTo] != DBNull.Value) info.SaleUpTo = Convert.ToInt32(reader[Offer.TableColumns.SaleUpTo]); else info.SaleUpTo = null; if (reader[Offer.TableColumns.PackageDescriptionAr] != DBNull.Value) info.PackageDescriptionAr = Convert.ToString(reader[Offer.TableColumns.PackageDescriptionAr]); if (reader[Offer.TableColumns.DescriptionAr] != DBNull.Value) info.DescriptionAr = Convert.ToString(reader[Offer.TableColumns.DescriptionAr]); if (reader[Currency.TableColumns.UnitAr] != DBNull.Value) info.CurrencyInfo.UnitAr = Convert.ToString(reader[Currency.TableColumns.UnitAr]); infoList.Add(info); } } else { while (reader.Read()) { info = new Offer(); info.ID = Convert.ToInt32(reader[Offer.CommonColumns.ID]); info.CategoryID = Convert.ToInt32(reader[Offer.TableColumns.CategoryID]); info.SupplierID = Convert.ToInt32(reader[Offer.TableColumns.SupplierID]); info.CurrencyInfo.ID = Convert.ToInt32(reader[Offer.TableColumns.CurrencyID]); info.Image = Convert.ToString(reader[Offer.TableColumns.Image]); info.IsProduct = Convert.ToBoolean(reader[Offer.TableColumns.IsProduct]); info.IsSale = Convert.ToBoolean(reader[Offer.TableColumns.IsSale]); info.IsPackage = Convert.ToBoolean(reader[Offer.TableColumns.IsPackage]); info.IsBestDeal = Convert.ToBoolean(reader[Offer.TableColumns.IsBestDeal]); info.IsFeaturedOffer = Convert.ToBoolean(reader[Offer.TableColumns.IsFeaturedOffer]); info.Rate = Convert.ToInt32(reader[Offer.TableColumns.Rate]); info.RateCount = Convert.ToInt32(reader[Offer.TableColumns.RateCount]); info.RateTotal = Convert.ToInt32(reader[Offer.TableColumns.RateTotal]); info.Likes = Convert.ToInt32(reader[Offer.TableColumns.Likes]); info.Views = Convert.ToInt32(reader[Offer.TableColumns.Views]); info.IsActive = Convert.ToBoolean(reader[Offer.TableColumns.IsActive]); info.NameEn = Convert.ToString(reader[Offer.TableColumns.NameEn]); info.TitleEn = Convert.ToString(reader[Offer.TableColumns.TitleEn]); info.ShortDescriptionEn = Convert.ToString(reader[Offer.TableColumns.ShortDescriptionEn]); info.CreationDate = Convert.ToDateTime(reader[Offer.CommonColumns.CreationDate]); if (reader[Offer.TableColumns.BrandID] != DBNull.Value) info.BrandID = Convert.ToInt32(reader[Offer.TableColumns.BrandID]); else info.BrandID = null; if (reader[Offer.TableColumns.StartDate] != DBNull.Value) info.StartDate = Convert.ToDateTime(reader[Offer.TableColumns.StartDate]); else info.StartDate = null; if (reader[Offer.TableColumns.EndDate] != DBNull.Value) info.EndDate = Convert.ToDateTime(reader[Offer.TableColumns.EndDate]); else info.EndDate = null; if (reader[Offer.TableColumns.OldPrice] != DBNull.Value) info.OldPrice = Convert.ToDecimal(reader[Offer.TableColumns.OldPrice]); else info.OldPrice = null; if (reader[Offer.TableColumns.NewPrice] != DBNull.Value) info.NewPrice = Convert.ToDecimal(reader[Offer.TableColumns.NewPrice]); else info.NewPrice = null; if (reader[Offer.TableColumns.DiscountPercentage] != DBNull.Value) info.DiscountPercentage = Convert.ToInt32(reader[Offer.TableColumns.DiscountPercentage]); else info.DiscountPercentage = null; if (reader[Offer.TableColumns.SaleUpTo] != DBNull.Value) info.SaleUpTo = Convert.ToInt32(reader[Offer.TableColumns.SaleUpTo]); else info.SaleUpTo = null; if (reader[Offer.TableColumns.PackageDescriptionEn] != DBNull.Value) info.PackageDescriptionEn = Convert.ToString(reader[Offer.TableColumns.PackageDescriptionEn]); if (reader[Offer.TableColumns.DescriptionEn] != DBNull.Value) info.DescriptionEn = Convert.ToString(reader[Offer.TableColumns.DescriptionEn]); if (reader[Currency.TableColumns.UnitEn] != DBNull.Value) info.CurrencyInfo.UnitEn = Convert.ToString(reader[Currency.TableColumns.UnitEn]); infoList.Add(info); } } } } catch (Exception error) { throw error; } }
private bool WriteOffer(string ProcedureName, Offer 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, Offer.TableColumns.CategoryID), info.CategoryID); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.SupplierID), info.SupplierID); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.CurrencyID), info.CurrencyInfo.ID); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.NameAr), info.NameAr); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.NameEn), info.NameEn); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.TitleAr), info.TitleAr); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.TitleEn), info.TitleEn); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.ShortDescriptionAr), info.ShortDescriptionAr); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.ShortDescriptionEn), info.ShortDescriptionEn); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.Image), info.Image); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.IsProduct), info.IsProduct); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.IsSale), info.IsSale); command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.IsPackage), info.IsPackage); if (info.BrandID.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.BrandID), info.BrandID.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.BrandID), DBNull.Value); if (!string.IsNullOrEmpty(info.DescriptionAr)) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.DescriptionAr), info.DescriptionAr); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.DescriptionAr), DBNull.Value); if (!string.IsNullOrEmpty(info.DescriptionEn)) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.DescriptionEn), info.DescriptionEn); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.DescriptionEn), DBNull.Value); if (!string.IsNullOrEmpty(info.PackageDescriptionAr)) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.PackageDescriptionAr), info.PackageDescriptionAr); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.PackageDescriptionAr), DBNull.Value); if (!string.IsNullOrEmpty(info.PackageDescriptionEn)) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.PackageDescriptionEn), info.PackageDescriptionEn); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.PackageDescriptionEn), DBNull.Value); if (info.StartDate.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.StartDate), info.StartDate.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.StartDate), DBNull.Value); if (info.EndDate.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.EndDate), info.EndDate.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.EndDate), DBNull.Value); if (info.OldPrice.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.OldPrice), info.OldPrice.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.OldPrice), DBNull.Value); if (info.NewPrice.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.NewPrice), info.NewPrice.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.NewPrice), DBNull.Value); if (info.DiscountPercentage.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.DiscountPercentage), info.DiscountPercentage.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.DiscountPercentage), DBNull.Value); if (info.SaleUpTo.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.SaleUpTo), info.SaleUpTo.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.TableColumns.SaleUpTo), DBNull.Value); if (IsNew) { command.Parameters.Add(string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.ID), SqlDbType.Int); command.Parameters[string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.ID)].Direction = ParameterDirection.Output; if (info.CreatedBy.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.CreatedBy), info.CreatedBy.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.CreatedBy), DBNull.Value); } else { command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.ID), info.ID); if (info.ModifiedBy.HasValue) command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.ModifiedBy), info.ModifiedBy.Value); else command.Parameters.AddWithValue(string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.ModifiedBy), DBNull.Value); } this.OpenConnection(); command.ExecuteNonQuery(); if (IsNew) { info.ID = Convert.ToInt32(command.Parameters[string.Concat(CommonStrings.AtSymbol, Offer.CommonColumns.ID)].Value); } result = true; } catch (Exception error) { throw error; } finally { this.CloseConnection(); } return result; }
public bool Update(Offer info) { bool result = false; try { result = WriteOffer(ProceduresNames.OfferUpdate, info, false); } catch (Exception error) { throw error; } return result; }