Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override async Task<bool> UpdateAsync(NotificationSettingModel model)
- {
- //// 1 2
- /// 1 2 null
- /// [] []
- /// [] [] []
- var entity = await _repository.GetAsync((long)model.Id);
- if (entity == null)
- {
- throw new ArgumentNullException(nameof(entity));
- }
- entity.NotificationEnabled = model.NotificationEnabled;
- entity.EmailNotificationEnabled = model.EmailNotificationEnabled;
- entity.PushNotificationEnabled = model.PushNotificationEnabled;
- entity.SubscriptionItems = model.SelectedSettingsItems.Where(b => b.Id != 0)
- .Select(_ => new NotificationSettingsItem
- {
- Id = (long)_.Id,
- NotificationSetting = entity,
- ProjectId = _.TargetType == NotificationSettingType.Project ? _.ProjectId : default(long?),
- PersonId = _.TargetType == NotificationSettingType.Person ? _.UserId : string.Empty
- }).ToList();
- entity.BranchSubscriptions = model.SelectedBranches.Where(b => b.Id != 0)
- .Select(_ => new NotificationBranchSubscription { Id = (long)_.Id, ProjectId = _.ProjectId, Name = _.Name })
- .ToList();
- //Deleted -> Pass to the Update and delete from DB manually
- var deletedId = entity.SubscriptionItems
- .Where(c => !model.SelectedSettingsItems.Select(ssi => ssi.Id).Contains(c.Id));
- // Added (List of notificationSettingItems )-> Pass to the Update method in repo and save them to the db, add them to the entity and save the changes
- var addedEntities = entity.SubscriptionItems
- .Where(c => !model.SelectedSettingsItems.Select(ssi => ssi.Id).Contains(c.Id));
- _repository.Update(entity,deltedIds, addedEntities);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement