public JsonResult SaveAbbonementEmail(string NewsLetterGroupId, string Email) { NewsletterSubscriber Subscriber; Guid NewsletterGroupID = Guid.Parse(NewsLetterGroupId); NewsletterGroup CurrentNewsletterGroup = NewsletterGroup.GetById <NewsletterGroup>(NewsletterGroupID); //BaseCollection<NewsletterSubscriber> SubScribers = BaseCollection<NewsletterSubscriber>.Get("EmailAdres = '" + Email + "'"); BaseCollection <NewsletterSubscriber> SubScribers = BaseCollection <NewsletterSubscriber> .Get("Name = '" + Email + "'"); if (SubScribers.Count >= 1) { Subscriber = SubScribers[0]; if (Subscriber.SubscribedGroups.Where(c => c.ID == NewsletterGroupID).Count() >= 1) { return(JsonResult.CreateResult(false, "Dit emailadres is al toegekend aan deze nieuwsbrief groep.")); } else { Subscriber.SubscribedGroups.Add(CurrentNewsletterGroup); Subscriber.Save(); } } else { Subscriber = new BitPlate.Domain.Newsletters.NewsletterSubscriber(); Subscriber.Email = Email; Subscriber.SubscribedGroups.Add(CurrentNewsletterGroup); Subscriber.Save(); } return(JsonResult.CreateResult(true, CurrentNewsletterGroup.Subscribers)); }
public JsonResult DeleteAbbonementFromGroup(string NewsLetterGroupId, string SubscriberId) { Guid NewsletterGroupID = Guid.Parse(NewsLetterGroupId); Guid SubscriberID = Guid.Parse(SubscriberId); NewsletterSubscriber Subscriber = NewsletterSubscriber.GetById <NewsletterSubscriber>(SubscriberID); NewsletterGroup SubscriberGroup = NewsletterGroup.GetById <NewsletterGroup>(NewsletterGroupID); if (Subscriber.SubscribedGroups.Count > 1) { Subscriber.SubscribedGroups.Remove(SubscriberGroup); Subscriber.Save(); } else { Subscriber.Delete(); } return(JsonResult.CreateResult(true, SubscriberGroup.Subscribers)); }