/// <summary> /// Gets offers. /// </summary> /// <param name="customerCode">The customerCode.</param> /// <param name="storeCode">The storeCode.</param> /// <param name="programCode">The programCode.</param> /// <returns>List{GetAvailableOfferModel}.</returns> public IList <GetOfferModel> GetOffers(string customerCode, string storeCode, string programCode) { var offers = new List <GetOfferModel>(); try { using (var connection = new SqlConnection(_configuration.GetConnectionString("DefaultConnection"))) { var command = connection.CreateCommand(); command.CommandText = StoredProcedures.GetOffers; command.Parameters.AddWithValue(Parameters.CustomerCode, customerCode); command.Parameters.AddWithValue(Parameters.StoreCode, storeCode); command.Parameters.AddWithValue(Parameters.ProgramCode, programCode); command.CommandType = CommandType.StoredProcedure; connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var offer = new GetOfferModel(); offer.OfferId = DatabaseHelper.GetGuid(reader[FieldNames.OfferId]); offer.Name = DatabaseHelper.GetString(reader[FieldNames.OfferName]); offer.Description = DatabaseHelper.GetString(reader[FieldNames.Description]); offer.FullDescription = DatabaseHelper.GetString(reader[FieldNames.FullDescription]); offer.OfferCode = DatabaseHelper.GetString(reader[FieldNames.OfferCode]); offer.OfferSegment = DatabaseHelper.GetNullableInteger(reader[FieldNames.OfferSegment]); offer.OfferSegmentName = DatabaseHelper.GetString(reader[FieldNames.OfferSegmentName]); offer.AdCode = DatabaseHelper.GetNullableInteger(reader[FieldNames.FullDescription]); offer.AdCodeDescription = DatabaseHelper.GetString(reader[FieldNames.AdCodeDesc]); offer.ImageUrl = DatabaseHelper.GetString(reader[FieldNames.ImageUrl]); offer.OfferDiscountPricing = DatabaseHelper.GetString(reader[FieldNames.DiscountPricing]); offer.OfferSize = DatabaseHelper.GetString(reader[FieldNames.Size]); offer.OfferDisclaimer = DatabaseHelper.GetString(reader[FieldNames.Disclaimer]); offer.StartDate = DatabaseHelper.GetNullableDateTime(reader[FieldNames.StartDate]); offer.EndDate = DatabaseHelper.GetNullableDateTime(reader[FieldNames.EndDate]); offer.IsActive = DatabaseHelper.GetBoolean(reader[FieldNames.IsActive]); offer.MemberAccount = DatabaseHelper.GetNullableInteger(reader[FieldNames.MemberAccount]); offer.CustomerCode = DatabaseHelper.GetString(reader[FieldNames.CustomerCode]); offer.StoreCode = DatabaseHelper.GetString(reader[FieldNames.StoreCode]); offers.Add(offer); } connection.Close(); } } } catch (Exception ex) { _logger.LogError(ex, $"Call to {nameof(GetOffers)} failed."); } return(offers); }
public IEnumerable <GetOfferModel> GetManyByIds(bool activeOnly, int[] ids) { var allOffers = this._offersRepository.GetAllByIds(activeOnly, ids); List <GetOfferModel> result = new List <GetOfferModel>(); foreach (var offer in allOffers) { GetOfferModel mappedOffer = _mapper.Map <OfferDto, GetOfferModel>(offer); result.Add(mappedOffer); } return(result); }
public IEnumerable <GetOfferModel> GetAll(bool activeOnly) { IEnumerable <OfferDto> allOffers = _offersRepository.GetAll(activeOnly); List <GetOfferModel> result = new List <GetOfferModel>(); foreach (var offer in allOffers) { GetOfferModel mappedOffer = _mapper.Map <OfferDto, GetOfferModel>(offer); result.Add(mappedOffer); } return(result); }