Ejemplo n.º 1
0
        public void GetOfferForDevice_Test()
        {
            PersistantDevice persistantDevice = new PersistantDevice()
            {
                Clubcard = "222222222",
                EmailId  = "*****@*****.**",
                GcmToken = "TR000001",
                Id       = "1234555",
                Mobile   = "9999999999",
                Name     = "Test"
            };

            PersistantOffer offer = new PersistantOffer()
            {
                Name        = "test Offer",
                Description = "Test Offer Description",
                ImagePath   = "Image test path",
                OfferCode   = "Offer Code"
            };
            List <PersistantOffer> lstPersistantOffer = new List <PersistantOffer>();

            lstPersistantOffer.Add(offer);

            _persist.Setup(r => r.GetDeviceDetailsByDeviceId(It.IsAny <string>())).Returns(persistantDevice);
            _persist.Setup(r => r.GetOffers(It.IsAny <string>(), It.IsAny <string>())).Returns(lstPersistantOffer);
            IP2PBusinessLogic business = new P2PBusinessLogic(_persist.Object);
            var result = business.GetOffers("test device id", "test store id", true);

            Assert.IsNotNull(result);
        }
Ejemplo n.º 2
0
        public List <PersistantOffer> GetOffers(string clubcard, string storeId)
        {
            List <PersistantOffer> persistantOffers = new List <PersistantOffer>();

            try
            {
                GetConnection();

                // Get valid record from offer table
                string query = "select OfferCode,Name,OfferDescription,ImagePath from offer where storeid in (" + storeId + ") and startDate <='" + DateTime.Now.ToString("MM/dd/yyyy") + "' and EndDate >= '" + DateTime.Now.ToString("MM/dd/yyyy") + "'";

                // if user has a clubcard number merge coupon records also
                if (clubcard != string.Empty)
                {
                    query += " union select CouponCode as 'OfferCode',Name,CouponDescription as 'OfferDescription',ImagePath from coupon where CouponAvailed = 0 and startDate <= '" + DateTime.Now.ToString("MM/dd/yyyy") + "' and EndDate >= '" + DateTime.Now.ToString("MM/dd/yyyy") + "';";
                }


                SqlCommand cmd = new SqlCommand(query, _conn);

                cmd.CommandType = System.Data.CommandType.Text;

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        PersistantOffer _PersistantOffer = new PersistantOffer()
                        {
                            OfferCode   = reader["OfferCode"].ToString(),
                            Name        = reader["Name"].ToString(),
                            Description = reader["OfferDescription"].ToString(),
                            ImagePath   = reader["ImagePath"].ToString()
                        };
                        persistantOffers.Add(_PersistantOffer);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                _conn.Close();
            }

            return(persistantOffers);
        }