Ejemplo n.º 1
0
 /// <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;
         }
     }
 }
Ejemplo n.º 2
0
 /// <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);
 }
        public ActionResult editCampaign(int?id)
        {
            userID = GetUser();
            UpdateCampModel campaign = new UpdateCampModel();

            try
            {
                // campaign.Campaigns = dbContext.M_Campaigns.Find(id);
                campaign.Campaigns = M_Campaigns.FindCampaign(id);
                //campaign.Subscribers = dbContext.NewLists.Find(campaign.Campaigns.ListId).Subscribers.ToList();
                campaign.Subscribers = M_Campaigns.subscribersToCampaign(campaign.Campaigns.ListId);
                //WebUtility.HtmlDecode(campaign.Campaigns.EmailContent);
                ViewBag.campTypes        = new SelectList(S_CampaignTypes.GetCampTypes(), "CTId", "Name");
                ViewBag.List             = new SelectList(M_List.GetLists(userID), "ListID", "ListName");
                TempData["emailContent"] = campaign.Campaigns.EmailContent;
                return(View("UpdateCamp", campaign));
            }
            catch (M_CustomException ex)
            {
                if (ex.ErrorCode == 100)
                {
                    ModelState.AddModelError("error", ex.message);
                    return(RedirectToAction("Campaign"));
                }
                else if (ex.ErrorCode == 101)
                {
                    ModelState.AddModelError("Error", "logical exception");
                    return(RedirectToAction("Campaign"));
                }
            }
            catch (InvalidOperationException ex)
            {
                M_CustomException obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL());
                obj.LogException();
                ModelState.AddModelError("Error", "Invalid operation");
                return(RedirectToAction("Campaign"));
            }

            return(RedirectToAction("Campaign"));
        }
Ejemplo n.º 4
0
        /// <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");
            }
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }
Ejemplo n.º 7
0
 /// <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;
         }
     }
 }
Ejemplo n.º 8
0
 /// <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;
         }
     }
 }
Ejemplo n.º 9
0
 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;
         }
     }
 }
Ejemplo n.º 10
0
 /// <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;
         }
     }
 }
Ejemplo n.º 11
0
 /// <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;
         }
     }
 }
Ejemplo n.º 12
0
 /// <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;
         }
     }
 }
Ejemplo n.º 13
0
        /// <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;
                }
            }
        }
Ejemplo n.º 14
0
        /// <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;
            }
        }
Ejemplo n.º 15
0
        /// <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;
                    }
                }
            }
        }
Ejemplo n.º 16
0
 public static M_Profile ViewProfile(int?pid)
 {
     profile = new M_Profile();
     using (dbcontext = new ApplicationDbContext())
     {
         try
         {
             profile = dbcontext.M_Profiles.Find(pid);
         }
         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(profile);
 }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        /// <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);
        }
Ejemplo n.º 19
0
        /// <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
            }
        }
Ejemplo n.º 20
0
        /// <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;
            //}
        }
Ejemplo n.º 21
0
        /// <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);
        }
Ejemplo n.º 22
0
        /// <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);
        }
Ejemplo n.º 23
0
        /// <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);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Imports CSV data and saves to database
        /// </summary>
        /// <param name="UploadFile"></param>
        /// <param name="model"></param>
        public void ImportCSV(HttpPostedFileBase UploadFile, SubscribersViewModel model)
        {
            subscriber = new M_Subscriber();
            string filename = System.IO.Path.GetFileNameWithoutExtension(UploadFile.FileName);

            if (UploadFile.FileName.EndsWith(".csv"))
            {
                using (dbcontext = new ApplicationDbContext())
                {
                    Stream stream   = UploadFile.InputStream;
                    string thisFile = filename + "_" + model.ListID + ".csv";
                    // var path = System.IO.Path.Combine(Server.MapPath("~/CSVFiles"), thisFile);
                    DataTable csvTable = new DataTable();
                    using (CsvReader csvReader = new CsvReader(new StreamReader(stream), true))
                    {
                        csvTable.Load(csvReader);
                    }
                    model.dataTable = csvTable;
                    //read column headers
                    var columnHeaders = (from DataColumn dc in model.dataTable.Columns select dc.ColumnName).ToArray();
                    //save list to database
                    if (model.dataTable.Rows.Count > 0)
                    {
                        //UploadFile.SaveAs(path);
                        for (int i = 0; i < model.dataTable.Rows.Count; i++)
                        {
                            try
                            {
                                List <string> sub = new List <string>();
                                sub = dbcontext.M_Subscribers.Where(l => l.ListID == model.ListID).Select(m => m.EmailAddress).ToList();
                                bool ispresent = false;
                                try
                                {
                                    ispresent = sub.Any(s => s == model.dataTable.Rows[i]["EmailAddress"].ToString());
                                }
                                catch (ArgumentException ex)
                                {
                                    //ModelState.AddModelError("Fileerr", "Please see sample file format");
                                    //return View();
                                }
                                if (ispresent == false)
                                {
                                    ListSusbscriber lSub = new ListSusbscriber();
                                    lSub.ListID = model.ListID;
                                    using (var trans = dbcontext.Database.BeginTransaction())
                                    {
                                        // ObjectParameter objParam = new ObjectParameter("ID", typeof(int));
                                        try
                                        {
                                            subscriber.ListID                = Convert.ToInt32(model.ListID);
                                            subscriber.FirstName             = model.dataTable.Rows[i]["FirstName"].ToString();
                                            subscriber.LastName              = model.dataTable.Rows[i]["LastName"].ToString();
                                            subscriber.EmailAddress          = model.dataTable.Rows[i]["EmailAddress"].ToString();
                                            subscriber.AlternateEmailAddress = model.dataTable.Rows[i]["AlternateEmailAddress"].ToString();
                                            subscriber.Address               = model.dataTable.Rows[i]["Address"].ToString();
                                            subscriber.Country               = model.dataTable.Rows[i]["Country"].ToString();
                                            subscriber.City      = model.dataTable.Rows[i]["City"].ToString();
                                            subscriber.AddedDate = DateTime.Now;
                                            // subscriber.StatusID = 3;
                                            dbcontext.M_Subscribers.Add(subscriber);
                                            dbcontext.SaveChanges();
                                            //dbcontext.ImportSubscribers(Convert.ToInt32(model.ListID), model.dataTable.Rows[i]["FirstName"].ToString(),
                                            //      model.dataTable.Rows[i]["LastName"].ToString(), model.dataTable.Rows[i]["EmailAddress"].ToString(), model.dataTable.Rows[i]["AlternateEmailAddress"].ToString(),
                                            //      model.dataTable.Rows[i]["Address"].ToString(), model.dataTable.Rows[i]["Country"].ToString(), model.dataTable.Rows[i]["City"].ToString(),
                                            //      DateTime.Now.ToString(), objParam);

                                            //lSub.SubscribersID = Convert.ToInt32(objParam.Value);
                                            // lSub.SubscribersID = (int?)((SqlParameter)param[9]).Value;
                                            lSub.SubscribersID = subscriber.SubscriberID;
                                            dbcontext.ListSusbscribers.Add(lSub);
                                            dbcontext.SaveChanges();
                                            trans.Commit();
                                        }
                                        catch (SqlException)
                                        {
                                            trans.Rollback();
                                        }
                                        catch (Exception ex)
                                        {
                                            obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL());
                                            obj.LogException();
                                            throw obj;
                                        }
                                    }
                                }
                                else
                                {
                                    //   ModelState.AddModelError("present", "Some subscribers already present");
                                }
                            }
                            catch (ArgumentException ex)
                            {
                                //ModelState.AddModelError("Fileerr", "Please see sample file format");
                                //return View();
                            }
                            catch (Exception ex)
                            {
                                obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL());
                                obj.LogException();
                                throw obj;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 25
0
 /// <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);
 }
Ejemplo n.º 26
0
        /// <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);
        }
Ejemplo n.º 27
0
        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);
        }
Ejemplo n.º 28
0
        /// <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;
                }
            }
        }
Ejemplo n.º 29
0
 /// <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;
     }
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Get all campaign ids for perticular user
 /// </summary>
 /// <param name="userID"></param>
 /// <returns></returns>
 public List <int?> GetCampaignIDs(string userID)
 {
     campIds = new List <int?>();
     using (dbcontext = new ApplicationDbContext())
     {
         try
         {
             campIds = dbcontext.UsersCampaigns.Where(u => u.UsersID == userID).Select(c => c.CampaignID).ToList();
             return(campIds);
         }
         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;
         }
     }
 }