/// <summary> /// Get subscriber to be edited /// </summary> /// <param name="sid"></param> /// <returns></returns> public M_Subscriber Edit(int?sid) { if (sid != null) { using (dbcontext = new ApplicationDbContext()) { try { subscriber = dbcontext.M_Subscribers.Find(sid); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, "Problem in saving data", ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } } return(subscriber); }
/// <summary> /// Gets list of campaign types from database /// </summary> /// <returns></returns> public static List <S_CampaignTypes> GetCampTypes() { campTypes = new List <S_CampaignTypes>(); using (dbcontext = new ApplicationDbContext()) { try { campTypes = dbcontext.S_CampaignTypes.ToList(); return(campTypes); } catch (SqlException ex) { M_CustomException obj = new M_CustomException((int)ErorrTypes.SqlExceptions, "Problem in saving data", ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// get collection of subscribers for perticular list /// </summary> /// <param name="listId">if listid is null display all subscribers for user and if listid is not null display subscriber /// for perticular list</param> /// <param name="userID"></param> /// <returns></returns> public List <M_Subscriber> GetsubscribersToList(int?listId, string userID) { if (listId != null) { using (dbcontext = new ApplicationDbContext()) { try { subscribersList = dbcontext.M_Lists.Find(listId).Subscribers.Where(s => s.Unsubscribe == false).ToList(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, ex.InnerException.Message, ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } return(subscribersList); } return(subscribersList); //else { // subscribersList = GetAllSubscribers(userID); // return subscribersList; //} }
/// <summary> /// Update list to database /// </summary> /// <returns>true or false</returns> public bool UpdateList() { this.LastUpdated = DateTime.Now; using (dbcontext = new ApplicationDbContext()) { try { dbcontext.Entry(this).State = System.Data.Entity.EntityState.Modified; dbcontext.SaveChanges(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } return(true); }
/// <summary> /// gets all lists /// </summary> /// <returns></returns> public static List <M_List> GetLists() { List <M_List> lists1 = new List <M_List>(); using (dbcontext = new ApplicationDbContext()) { try { lists1 = dbcontext.M_Lists.ToList(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } return(lists1); }
/// <summary> /// collection of emailaddress for peticular list /// </summary> /// <param name="userID">collection of list ids for perticular user</param> /// <returns></returns> public List <string> getSubscribers(string userID) { subscriberEmail = new List <string>(); listIds = new List <int?>(); listIds = M_List.GetListIds(userID); using (dbcontext = new ApplicationDbContext()) { foreach (var item in listIds) { try { subscriberEmail.Add(dbcontext.M_Subscribers.Where(l => l.ListID == item).Select(s => s.EmailAddress).FirstOrDefault()); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, ex.Message, ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } } return(subscriberEmail); }
/// <summary> /// enables campaign by hanging status id /// </summary> /// <param name="cid"></param> public static void EnableCampaign(int?cid) { campaign = new M_Campaigns(); using (dbcontext = new ApplicationDbContext()) { try { campaign = dbcontext.M_Campaigns.Find(cid); campaign.IsActive = true; dbcontext.SaveChanges(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// gets subscribers IDs for prticular campaign by campaignid /// </summary> /// <param name="campaignID"></param> public static List <int?> GetSubscribersForCampaign(int?campaignID) { subscribersID = new List <int?>(); using (dbcontext = new ApplicationDbContext()) { try { int lid = dbcontext.M_Campaigns.Where(c => c.Cid == campaignID).Select(c => c.ListId).FirstOrDefault(); subscribersID = dbcontext.ListSusbscribers.Where(l => l.ListID == lid).Select(l => l.SubscribersID).ToList(); return(subscribersID); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// get email template from database /// </summary> /// <param name="cid"></param> /// <returns>Email content</returns> public static string EditTemplate(int?cid) { using (dbcontext = new ApplicationDbContext()) { try { // campaign = new M_Campaigns(); string emailContent = null; emailContent = dbcontext.M_Campaigns.Where(c => c.Cid == cid).Select(e => e.EmailContent).FirstOrDefault(); return(emailContent); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// saves updated email template to database /// </summary> /// <param name="EmailContent"></param> /// <param name="cid"></param> public static void UpdateTemplate(string EmailContent, int?cid) { campaign = new M_Campaigns(); using (dbcontext = new ApplicationDbContext()) { try { campaign = dbcontext.M_Campaigns.SingleOrDefault(c => c.Cid == cid); if (campaign != null) { campaign.EmailContent = WebUtility.HtmlEncode(EmailContent); dbcontext.SaveChanges(); } } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// gets list of subscribers for prerticular campaign /// </summary> /// <param name="Lid"></param> /// <returns>List of subscribers</returns> public static List <M_Subscriber> subscribersToCampaign(int?Lid) { List <M_Subscriber> Subscribers = new List <M_Subscriber>(); using (dbcontext = new ApplicationDbContext()) { try { Subscribers = dbcontext.M_Lists.Find(Lid).Subscribers.ToList(); return(Subscribers); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// Serch for campaign by campaign ID /// </summary> /// <param name="cid"></param> /// <returns>Complete campaign information</returns> public static M_Campaigns FindCampaign(int?cid) { campaign = new M_Campaigns(); try { using (dbcontext = new ApplicationDbContext()) { campaign = dbcontext.M_Campaigns.Find(cid); //campaign = (from c in dbcontext.M_Campaigns // where c.Cid == cid // select new { c.Cid, c.CTypeId, c.EmailSubject, c.FromName, c.FromEmail, c.Name, c.ListId }).Single<M_Campaigns>(); return(campaign); } } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } }
/// <summary> /// Get list of campaigns created by perticular user /// </summary> /// <param name="userID"></param> /// <returns></returns> public static List <M_Campaigns> ViewCampaigns(string userID) { campaigns = new List <M_Campaigns>(); using (dbcontext = new ApplicationDbContext()) { try { campaigns = (from camp in dbcontext.M_Campaigns join user in dbcontext.UsersCampaigns on camp.Cid equals user.CampaignID where user.UsersID == userID select camp).ToList(); return(campaigns); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
public List <M_Subscriber> Unsubscriber(int?lid) { // listIds = list.GetListIds(userID); if (lid != null) { using (dbcontext = new ApplicationDbContext()) { try { subscribersList = new List <M_Subscriber>(); subscribersList = dbcontext.M_Subscribers.Where(l => l.ListID == lid && l.Unsubscribe == true).ToList(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, ex.Message, ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } } return(subscribersList); }
/// <summary> /// Saves campaign to database /// </summary> /// <param name="userID"></param> /// <returns></returns> public bool SaveCampaign(string userID) { UsersCampaign user = new UsersCampaign(); try { using (dbcontext = new ApplicationDbContext()) { if (!CheckCampaignExist(this.Name, userID, dbcontext)) { using (var trans = dbcontext.Database.BeginTransaction()) { try { dbcontext.M_Campaigns.Add(this); dbcontext.SaveChanges(); user.CampaignID = this.Cid; user.UsersID = userID; dbcontext.UsersCampaigns.Add(user); dbcontext.SaveChanges(); trans.Commit(); return(true); } catch (SqlException ex) { trans.Rollback(); obj = new M_CustomException((int)ErorrTypes.SqlExceptions, ex.InnerException.Message, ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), userID, Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { trans.Rollback(); obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), userID, Utlities.GetURL()); obj.LogException(); throw obj; } } }// else { return(false); } } } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), userID, Utlities.GetURL()); obj.LogException(); throw obj; } }
/// <summary> /// Function to save New List object,and add list id into userslist table /// </summary> /// <param name="obj">New List type object</param> /// <param name="userID">User for which list is created</param> /// <returns></returns> public string SaveList(string userID) { if (CheckListExist(this.ListName, userID) == false) { user.UsersID = userID; try { using (dbcontext = new ApplicationDbContext()) { //begin transaction using (var trans = dbcontext.Database.BeginTransaction()) { try { this.CreatedDate = DateTime.Now; dbcontext.M_Lists.Add(this); dbcontext.SaveChanges(); user.ListID = this.ListID; dbcontext.UsersList.Add(user); dbcontext.SaveChanges(); trans.Commit(); } catch (SqlException ex) { trans.Rollback(); obj = new M_CustomException((int)ErorrTypes.SqlExceptions, ex.Message, ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), userID, Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { trans.Rollback(); obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), userID, Utlities.GetURL()); obj.LogException(); throw obj; } } } return("Saved"); } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), userID, Utlities.GetURL()); obj.LogException(); throw obj; } } //if listname already exist else { return("List name already exist"); } }
/// <summary> /// Get lists to display for user /// </summary> /// <param name="userID"></param> /// <returns>return list view model which contains list information and count of its subcribers and unsubscribers</returns> public ListViewModel ViewList(string userID) { // NewList lst = null; //listIds = new List<int?>(); // listIds = GetListIds(userID); using (dbcontext = new ApplicationDbContext()) { try { LVmodel.lists = (from list in dbcontext.M_Lists join users in dbcontext.UsersList on list.ListID equals users.ListID where users.UsersID == userID select list).ToList(); foreach (var i in LVmodel.lists) { //int cnt = (from list in LVmodel.lists // join sub in dbcontext.Subscribers // on list.ListID equals sub.ListID // where sub.ListID == i.ListID // select sub).Count(); int cnt = (from list in LVmodel.lists join sub in dbcontext.ListSusbscribers on list.ListID equals sub.ListID where sub.ListID == i.ListID select list).Count(); LVmodel.NoOfSubscribers.Add(cnt); } //foreach (var item in listIds) //{ // lst = new NewList(); // lst = dbcontext.NewLists.Where(u => u.ListID == item).FirstOrDefault(); // LVmodel.lists.Add(lst); // var cnt = dbcontext.Subscribers.Where(l => l.ListID == item && l.Unsubscribe == false).Count(); // LVmodel.NoOfSubscribers.Add(cnt); //} } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } return(LVmodel); }
public static string AddSubscribersToTracking(int cid, string userID) { subIDs = M_Campaigns.GetSubscribersForCampaign(cid); string id = Guid.NewGuid().ToString(); if (subIDs.Count != 0) { using (dbcontext = new ApplicationDbContext()) { try { foreach (var item in subIDs) { track = new M_Tracking(); track.CampId = cid; track.SubsciberId = item; track.IsOpened = false; track.IdentifierSubscriber = Guid.NewGuid().ToString(); track.IdentifierCampaign = id; track.MailStatus = false; track.UserID = userID; dbcontext.M_Trackings.Add(track); dbcontext.SaveChanges(); } } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (InvalidOperationException ex) { obj = new M_CustomException((int)ErorrTypes.InvalidOperation, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } catch (ArgumentNullException ex) { obj = new M_CustomException((int)ErorrTypes.ArgumentNullExceptions, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } } return(track.IdentifierCampaign); }
/// <summary> /// Delete perticular subscriber from database /// </summary> /// <param name="sid"></param> public void Delete(int?sid) { if (sid != null) { using (dbcontext = new ApplicationDbContext()) { var ls = dbcontext.ListSusbscribers.SingleOrDefault(l => l.SubscribersID == sid); subscriber = dbcontext.M_Subscribers.Find(sid); int?lid = subscriber.ListID; if (ls != null) { try { dbcontext.ListSusbscribers.Remove(ls); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, "Problem in saving data", ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } try { dbcontext.M_Subscribers.Remove(subscriber); dbcontext.SaveChanges(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, "Problem in saving data", ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } } }
/// <summary> /// Save subscriber to database /// </summary> /// <param name="listID">list from which subscriber belogs</param> /// <param name="userID"></param> public void saveSubscriber(string userID) { ListSusbscriber lSub = new ListSusbscriber(); if (isSubscriberExist(this.EmailAddress, this.ListID, userID) == false) { lSub.ListID = this.ListID; // this.StatusID = 3; this.AddedDate = DateTime.Now; using (dbcontext = new ApplicationDbContext()) { using (var trans = dbcontext.Database.BeginTransaction()) { //Subscriber not present in list try { dbcontext.M_Subscribers.Add(this); dbcontext.SaveChanges(); lSub.SubscribersID = this.SubscriberID; dbcontext.ListSusbscribers.Add(lSub); dbcontext.SaveChanges(); trans.Commit(); } catch (SqlException ex) { //failed to save in subscriber or listsubscriber,clear model ans add model error trans.Rollback(); obj = new M_CustomException((int)ErorrTypes.SqlExceptions, "Problem in saving data", ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { trans.Rollback(); obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } } } else { //Subscriber already present in list,clear model ans add model error } }
/// <summary> /// Checks if campaign name already created by perticular user /// </summary> /// <param name="campaignName"></param> /// <param name="userID"></param> /// <returns></returns> public bool CheckCampaignExist(string campaignName, string userID, ApplicationDbContext dbcontext) { listIDs = new List <int?>(); bool res = false; // listIDs = GetCampaignIDs(userID); campaignNames = new List <string>(); //using (dbcontext = new ApplicationDbContext()) //{ try { var campaigndata = from camp in dbcontext.M_Campaigns join user in dbcontext.UsersCampaigns on camp.Cid equals user.CampaignID where user.UsersID == userID select new { camp.Name }; //where user.UsersID == userID); //select camp.Name.Any(); if (campaigndata != null) { res = campaigndata.Any(c => c.Name == campaignName); // res = true; } //foreach (var item in listIDs) //{ // campaignNames.Add(dbcontext.M_Campaigns.Where(c => c.Cid == item).Select(c => c.Name).FirstOrDefault()); //} //res= campaignNames.Any(c => c == campaignName); return(res); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } // } }
/// <summary> /// Save the subscriber with thier status , so that the Windows service can send mail to user /// </summary> /// <param name="usrId"></param> /// <param name="campId"></param> /// <param name="listId"></param> /// <param name="subId"></param> public void settingMail(string usrId, int campId, int listId, int subId) { dbContext = new ApplicationDbContext(); this.UserId = usrId; this.CampId = campId; this.ListId = listId; this.StatusId = 4; this.SubscriberId = subId; try { dbContext.M_MailStatus.Add(this); dbContext.SaveChanges(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, "Problem in saving data", ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), UserId, Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } }
/// <summary> /// Function to check if list name is already exist /// </summary> /// <param name="listName">user want to create list by this name</param> /// <param name="UserID">User for which list is created</param> /// <returns>true if listname is already exist and false if listname does not exist</returns> public bool CheckListExist(string listName, string userID) { listIds = new List <int?>(); // listIds = GetListIds(userID); bool res = false; using (dbcontext = new ApplicationDbContext()) { try { var listdata = from list in dbcontext.M_Lists join users in dbcontext.UsersList on list.ListID equals users.ListID where users.UsersID == userID select new { list.ListName }; //foreach (var item in listIds) //{ // ListNames.Add(dbcontext.NewLists.Where(l => l.ListID == item).Select(l => l.ListName).FirstOrDefault()); //} if (listdata != null) { res = listdata.Any(l => l.ListName == listName); } } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } // return ListNames.Any(l => l == listName); return(res); }
public static bool Unsub(string subid) { using (dbcontext = new ApplicationDbContext()) { subscriber = new M_Subscriber(); int?id; if (subid != null) { try { id = dbcontext.M_Trackings.Where(t => t.IdentifierSubscriber == subid).Select(t => t.SubsciberId).FirstOrDefault(); subscriber = dbcontext.M_Subscribers.Find(id); subscriber.Unsubscribe = true; dbcontext.M_Subscribers.Attach(subscriber); dbcontext.Entry(subscriber).Property(p => p.Unsubscribe).IsModified = true; dbcontext.SaveChanges(); return(true); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, ex.Message, ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } else { return(false); } } }
public void UpdateProfile() { using (dbcontext = new ApplicationDbContext()) { try { dbcontext.Entry(this).State = System.Data.Entity.EntityState.Modified; dbcontext.SaveChanges(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// add new campaign to database queue /// </summary> /// <param name="campaignId"></param> public static void EnqueueCampaign(MailerQueue que) { using (dbcontext = new ApplicationDbContext()) { try { dbcontext.MailerQueues.Add(que); dbcontext.SaveChanges(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// update subscribers information to database /// </summary> public void Update() { using (dbcontext = new ApplicationDbContext()) { try { dbcontext.Entry(this).State = System.Data.Entity.EntityState.Modified; dbcontext.SaveChanges(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, "Problem in saving data", ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, "Some problem occured while processing request", ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }
/// <summary> /// if listid is not null get subscribers by listid /// </summary> /// <param name="listID">is not null</param> /// <returns></returns> public List <M_Subscriber> GetSubscribersbyListID(int?listID) { using (dbcontext = new ApplicationDbContext()) { try { subscribersList = dbcontext.M_Lists.Find(listID).Subscribers.Where(s => s.Unsubscribe == false).ToList(); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.SqlExceptions, ex.Message, ex.StackTrace, ErorrTypes.SqlExceptions.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } return(subscribersList); }
/// <summary> /// Gets list information to be edited /// </summary> /// <param name="listID"></param> /// <returns>List obejct</returns> public M_List EditList(int?listID) { newList = new M_List(); using (dbcontext = new ApplicationDbContext()) { try { newList = dbcontext.M_Lists.Find(listID); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } return(newList); }
/// <summary> /// Get list ids collection for perticular user /// </summary> /// <param name="userID"></param> /// <returns>listids collection</returns> public static List <int?> GetListIds(string userID) { using (dbcontext = new ApplicationDbContext()) { try { listIds = new List <int?>(); listIds = dbcontext.UsersList.Where(u => u.UsersID == userID).Select(l => l.ListID).ToList(); return(listIds); } catch (SqlException ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber); obj.LogException(); throw obj; } catch (Exception ex) { obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL()); obj.LogException(); throw obj; } } }