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); }
public bool RegisterDevice(PersistantDevice device) { try { GetConnection(); SqlCommand cmd = new SqlCommand("insert into Device values(@id,@EmailId,@Name,@GcmToken,@Clubcard,@Mobile);", _conn); cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@id", device.Id); cmd.Parameters.AddWithValue("@EmailId", device.EmailId); cmd.Parameters.AddWithValue("@Name", device.Name); cmd.Parameters.AddWithValue("@GcmToken", device.GcmToken); cmd.Parameters.AddWithValue("@Clubcard", device.Clubcard); cmd.Parameters.AddWithValue("@Mobile", device.Mobile); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { _conn.Close(); } return(true); }
public void UpdateDevice_Test() { Device _device = new Device() { Name = "Test Name", Id = "Device ID", GcmToken = "Test GCM Token", Mobile = "9999999999", EmailId = "*****@*****.**", Clubcard = "2345677765" }; PersistantDevice persistantDevice = new PersistantDevice() { Clubcard = "222222222", EmailId = "*****@*****.**", GcmToken = "TR000001", Id = "1234555", Mobile = "9999999999", Name = "Test" }; _persist.Setup(r => r.GetDeviceDetailsByDeviceId(It.IsAny <string>())).Returns(persistantDevice); _persist.Setup(r => r.RegisterDevice(It.IsAny <PersistantDevice>())).Returns(true); IP2PBusinessLogic business = new P2PBusinessLogic(_persist.Object); var result = business.RegisterDevice(_device); Assert.IsTrue(result); }
public bool UpdateDeviceDetails(PersistantDevice device) { try { GetConnection(); SqlCommand cmd = new SqlCommand("update Device set EmailId = @EmailId,Name = @Name,GcmToken = @GcmToken,Clubcard = @Clubcard,Mobile = @Mobile where id = @id", _conn); cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@id", device.Id); cmd.Parameters.AddWithValue("@EmailId", device.EmailId); cmd.Parameters.AddWithValue("@Name", device.Name); cmd.Parameters.AddWithValue("@GcmToken", device.GcmToken); cmd.Parameters.AddWithValue("@Clubcard", device.Clubcard); cmd.Parameters.AddWithValue("@Mobile", device.Mobile); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { _conn.Close(); } return(true); }
/// <summary> /// Sending Notification and updating Notification status in DB /// </summary> /// <param name="deviceId"> Device ID</param> /// <param name="offers">List Of Offers</param> private void SendNotification(string deviceId, List <PersistantOffer> offers) { //to to check notification is send or not PersistantDevice deviceDetails = persist.GetDeviceDetailsByDeviceId(deviceId); foreach (var _offer in offers) { AndroidPush(deviceDetails.GcmToken, deviceDetails.Id, _offer.Description); } }
/// <summary> /// Save or update device to database /// </summary> /// <param name="device">Device object that need to update or save</param> /// <returns></returns> public bool RegisterDevice(P2P.Model.Device device) { //check if device already exist PersistantDevice _device = persist.GetDeviceDetailsByDeviceId(device.Id); if (_device == null) { //if exist then update else insert new record persist.RegisterDevice(ConvertModelToPersistant(device)); } else { //if exist then update else insert new record persist.UpdateDeviceDetails(ConvertModelToPersistant(device)); } return(true); }
public List <Promotions> GetOffers(string deviceId, string storeId, bool refresh) { if (string.IsNullOrEmpty(storeId)) { storeId = "0"; } else { storeId += ",0"; } //get device details by deviceid PersistantDevice device = persist.GetDeviceDetailsByDeviceId(deviceId); //todo: Wish list offers can be implemented by calling dotcom API List <PersistantOffer> offers = persist.GetOffers(device != null ? device.Clubcard : string.Empty, storeId); //todo: Wish list offers can be implemented by calling dotcom API //todo: Engine to identify the top offers to be showed in the notification if (!refresh) { if (!persist.NotificationStatusForDevice(deviceId)) { // below code need to be uncommented after GCM implementation // SendNotification(device.Id, offers); persist.UpdateNotificationStatus(deviceId, DateTime.Now); } else { // we are not sending the message as push notification now instead we are popping the message //for this we ae making offer null offers = null; } } return(ConvertToPromotion(offers)); }
public PersistantDevice GetDeviceDetailsByDeviceId(string deviceId) { try { GetConnection(); SqlCommand cmd = new SqlCommand("Select * from device where id = @id", _conn); cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@id", deviceId); PersistantDevice _device = null; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { _device = new PersistantDevice() { Id = reader["id"].ToString(), Name = reader["Name"].ToString(), GcmToken = reader["GcmToken"].ToString(), Clubcard = reader["Clubcard"].ToString(), EmailId = reader["EmailId"].ToString(), Mobile = reader["Mobile"].ToString() }; } } return(_device); } catch (Exception) { throw; } finally { _conn.Close(); } }