Exemple #1
0
 public ActionResult categorysubscriber(EmailSubscriptionViewModel model)
 {
     if (ModelState.IsValid)
     {
         string id   = User.Identity.GetUserId();
         var    subQ = from s in db.EmailSubscriptions
                       where s.Email.ToLower() == model.Email.ToLower() && s.CategoryId == model.GroupId
                       select s;
         var sub = subQ.FirstOrDefault();
         if (sub != null)
         {
             if (!String.IsNullOrEmpty(model.Choice) && model.Choice.ToLower() == "unsubscribe")
             {
                 db.EmailSubscriptions.Remove(sub);
                 db.SaveChanges();
                 ViewBag.Message = "Successfully updated your subsciption.";
             }
             else
             {
                 sub.Period = model.Cycle;
                 sub.Name   = model.Name;
                 if (!String.IsNullOrEmpty(id))
                 {
                     sub.UserId = id;
                 }
                 sub.Updated = DateTime.Now;
                 db.SaveChanges();
                 ViewBag.Message = "Successfully updated your subsciption.";
             }
         }
         else
         {
             sub = new EmailSubscriptions();
             if (!String.IsNullOrEmpty(id))
             {
                 sub.UserId = id;
             }
             sub.Email      = model.Email;
             sub.CategoryId = model.GroupId;
             sub.Name       = model.Name;
             sub.Period     = model.Cycle;
             sub.Started    = DateTime.Now;
             db.EmailSubscriptions.Add(sub);
             db.SaveChanges();
             ViewBag.Message = "Successfully updated your subsciption.";
         }
     }
     return(View(model));
 }
Exemple #2
0
        public virtual void Subscribe(EmailSubscriptionViewModel subscription)
        {
            if (Request.IsAjaxRequest())
            {
                try
                {
                    // Add logic to add subscr
                    var isGroup = subscription.SubscriptionType.Contains("Group");
                    var isTag   = subscription.SubscriptionType.Contains("tag");
                    var id      = subscription.Id;
                    var dbUser  = MembershipService.GetUser(User.Identity.Name);

                    if (isGroup)
                    {
                        // get the Group
                        var cat = _groupService.Get(id);

                        if (cat != null)
                        {
                            // Create the notification
                            var GroupNotification = new GroupNotification
                            {
                                Group = cat,
                                User  = dbUser
                            };
                            //save

                            _notificationService.Add(GroupNotification);
                        }
                    }
                    else if (isTag)
                    {
                        // get the tag
                        var tag = _topicTagService.Get(id);

                        if (tag != null)
                        {
                            // Create the notification
                            var tagNotification = new TagNotification
                            {
                                Tag  = tag,
                                User = dbUser
                            };
                            //save

                            _notificationService.Add(tagNotification);
                        }
                    }
                    else
                    {
                        // get the Group
                        var topic = _topicService.Get(id);

                        // check its not null
                        if (topic != null)
                        {
                            // Create the notification
                            var topicNotification = new TopicNotification
                            {
                                Topic = topic,
                                User  = dbUser
                            };
                            //save

                            _notificationService.Add(topicNotification);
                        }
                    }

                    Context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Context.RollBack();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }
            }
            else
            {
                throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
            }
        }
Exemple #3
0
        public virtual void UnSubscribe(EmailSubscriptionViewModel subscription)
        {
            if (Request.IsAjaxRequest())
            {
                try
                {
                    // Add logic to add subscr
                    var isGroup = subscription.SubscriptionType.Contains("Group");
                    var isTag   = subscription.SubscriptionType.Contains("tag");
                    var id      = subscription.Id;
                    var dbUser  = MembershipService.GetUser(User.Identity.Name);
                    if (isGroup)
                    {
                        // get the Group
                        var cat = _groupService.Get(id);

                        if (cat != null)
                        {
                            // get the notifications by user
                            var notifications =
                                _notificationService.GetGroupNotificationsByUserAndGroup(dbUser, cat, true);

                            if (notifications.Any())
                            {
                                foreach (var GroupNotification in notifications)
                                {
                                    // Delete
                                    _notificationService.Delete(GroupNotification);
                                }
                            }
                        }
                    }
                    else if (isTag)
                    {
                        // get the tag
                        var tag = _topicTagService.Get(id);

                        if (tag != null)
                        {
                            // get the notifications by user
                            var notifications =
                                _notificationService.GetTagNotificationsByUserAndTag(dbUser, tag, true);

                            if (notifications.Any())
                            {
                                foreach (var n in notifications)
                                {
                                    // Delete
                                    _notificationService.Delete(n);
                                }
                            }
                        }
                    }
                    else
                    {
                        // get the topic
                        var topic = _topicService.Get(id);

                        if (topic != null)
                        {
                            // get the notifications by user
                            var notifications =
                                _notificationService.GetTopicNotificationsByUserAndTopic(dbUser, topic, true);

                            if (notifications.Any())
                            {
                                foreach (var topicNotification in notifications)
                                {
                                    // Delete
                                    _notificationService.Delete(topicNotification);
                                }
                            }
                        }
                    }

                    Context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Context.RollBack();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }
            }
            else
            {
                throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
            }
        }
        public ActionResult EmailSubscriber()
        {
            var model = new EmailSubscriptionViewModel();

            return(PartialView("~/Views/Shared/Widgets/_EmailSubscriber.cshtml", model));
        }