public void Update(CategoryNotification item) { // Check there's not an object with same identifier already in context if (_context.CategoryNotification.Local.Select(x => x.Id == item.Id).Any()) { throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit"); } _context.Entry(item).State = EntityState.Modified; }
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 isTag = subscription.SubscriptionType.Contains("tag"); var id = subscription.Id; var dbUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id); 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); } } 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 Delete(CategoryNotification categoryNotification) { _context.CategoryNotification.Remove(categoryNotification); }
public CategoryNotification Add(CategoryNotification category) { return _context.CategoryNotification.Add(category); }
/// <summary> /// Add a new category notification /// </summary> /// <param name="category"></param> public void Add(CategoryNotification category) { _categoryNotificationRepository.Add(category); }
/// <summary> /// Delete a notification /// </summary> /// <param name="notification"></param> public void Delete(CategoryNotification notification) { _categoryNotificationRepository.Delete(notification); }