public void Subscribe(SubscribeEmailViewModel subscription) { if (Request.IsAjaxRequest()) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { // Add logic to add subscr var isCategory = subscription.SubscriptionType.Contains("category"); var id = subscription.Id; if (isCategory) { // get the category var cat = _categoryService.Get(id); if (cat != null) { // Create the notification var categoryNotification = new CategoryNotification { Category = cat, User = LoggedOnUser }; //save _categoryNotificationService.Add(categoryNotification); } } else { // get the category var topic = _topicService.Get(id); // check its not null if (topic != null) { // Create the notification var topicNotification = new TopicNotification { Topic = topic, User = LoggedOnUser }; //save _topicNotificationService.Add(topicNotification); } } unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } } } else { throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } }
public void Subscribe(EmailSubscriptionViewModel subscription) { if (Request.IsAjaxRequest()) { try { // Add logic to add subscr var isCategory = subscription.SubscriptionType.Contains("category"); var isTag = subscription.SubscriptionType.Contains("tag"); var id = subscription.Id; var dbUser = MembershipService.GetUser(User.Identity.Name); if (isCategory) { // get the category var cat = _categoryService.Get(id); if (cat != null) { // Create the notification var categoryNotification = new CategoryNotification { Category = cat, User = dbUser }; //save _categoryNotificationService.Add(categoryNotification); } } 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 _tagNotificationService.Add(tagNotification); } } else { // get the category var topic = _topicService.Get(id); // check its not null if (topic != null) { // Create the notification var topicNotification = new TopicNotification { Topic = topic, User = dbUser }; //save _topicNotificationService.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")); } }