public async Task AddAsync(Guid groupId, GroupMemberSubscriptionModel model) { var groupMember = GetNewGroupMember(groupId, model); await _groupMemberRepository.AddAsync(groupMember); await _memberCacheService.UpdateMemberCacheAsync(groupMember.MemberId); }
public async Task SaveAsync(IEnumerable <PermissionUpdateModel> permissions) { var entities = permissions.Select(CreateEntity); await _permissionsRepository.AddAsync(entities); CurrentCache = null; }
public async Task <Guid> CreateAsync(GroupDocument document) { document.Id = Guid.NewGuid(); await _repository.AddAsync(document); return(document.Id); }
public async Task CreateAsync(Guid id, string name, string description, IFormFile file, decimal price, string language) { var article = await _articleSqlRepository.GetAsync(a => a.Name == name); if (article != null) { throw new JppcException(Codes.ArticleAlreadyExists, $"Article: '{name}' already exists."); } byte[] content = null; using (Stream stream = file.OpenReadStream()) { using (MemoryStream mStream = new MemoryStream()) { await stream.CopyToAsync(mStream); content = mStream.ToArray(); } } article = new Article(id, name, description, file.FileName, content, price, language); await _articleSqlRepository.AddAsync(article); }
public async Task AddLinkPreviewAsync(Guid activityId, int previewId) { var entity = new ActivityToLinkPreviewEntity { ActivityId = activityId, LinkPreviewId = previewId }; await _previewRelationRepository.AddAsync(entity); }
public async Task AddLinkPreviewAsync(Guid commentId, int previewId) { var entity = new CommentToLinkPreviewEntity { CommentId = commentId, LinkPreviewId = previewId }; await _previewRelationRepository.AddAsync(entity); }
public async Task NotifyAsync(NotifierData data) { var identity = GetSettingsIdentity(data); var settings = _notificationSettingsService.Get <EmailNotifierTemplate>(identity); if (settings != null && settings.IsEnabled) { var receivers = (await _intranetMemberService.GetManyAsync(data.ReceiverIds)).ToList(); foreach (var receiverId in data.ReceiverIds) { var user = receivers.Find(receiver => receiver.Id == receiverId); var message = _notificationModelMapper.Map(data.Value, settings.Template, user); _mailService.SendAsync(message); _notificationRepository.AddAsync(new Sql.Notification { Id = Guid.NewGuid(), Date = DateTime.UtcNow, IsNotified = true, IsViewed = false, Type = data.NotificationType.ToInt(), NotifierType = NotifierTypeEnum.EmailNotifier.ToInt(), Value = new { message }.ToJson(), ReceiverId = receiverId }); } } }
public async Task CreateAsync(IntranetActivityEntity entity) { entity.Id = Guid.NewGuid(); entity.ModifyDate = DateTime.UtcNow; entity.CreatedDate = DateTime.UtcNow; await _sqlRepository.AddAsync(entity); }
public virtual async Task<CommentModel> CreateAsync(CommentCreateDto dto) { var entity = Map(dto); entity.CreatedDate = entity.ModifyDate = DateTime.UtcNow; await _commentsRepository.AddAsync(entity); if (dto.LinkPreviewId.HasValue) { await _commentLinkPreviewService.AddLinkPreviewAsync(entity.Id, dto.LinkPreviewId.Value); } return entity.Map<CommentModel>(); }
public async Task AddAsync(Guid userId) { var user = await _userRepository.GetAsync(userId); if (user == null) { throw new JppcException(Codes.UserNotFound, $"User: '******' was not found."); } await _refreshTokenRepository.AddAsync(new RefreshToken(user, _passwordHasher)); }
public async Task ArticlePaymentAsync(Guid id, Guid userId, Guid articleId) { var article = await _articleSqlRepository.GetAsync(articleId); if (article == null) { throw new JppcException(Codes.ArticleNotFound, $"Article: '{articleId}' doesn't exists."); } var user = await _userSqlRepository.GetAsync(userId); if (user == null) { throw new JppcException(Codes.UserNotFound, $"User: '******' doesn't exists."); } //var domainShippingAddress = await _shippingAddressSqlRepository.GetAsync(sa => sa.UserId == userId); //if (domainShippingAddress == null) //{ // throw new JppcException(Codes.ShippingAddressNotFound, // $"Shipping address for user: '******' doesn't exists."); //} var paypalItem = new PayPalItem() { Name = article.Name, Price = article.Price.ToString(), Quantity = "1", Currency = "RON", Description = "JPPC Article" }; var paypalAmount = new PayPalAmount() { Total = article.Price.ToString(), Currency = "RON" }; //var paypalShippingAddress = new PayPalShippingAddress() //{ // City = domainShippingAddress.City, // PostalCode = domainShippingAddress.PostalCode, // State = domainShippingAddress.State, // Line1 = domainShippingAddress.Street + " " + domainShippingAddress.Country, // Phone = "", // user.Phone // RecipientName = user.FirstName + " " + user.LastName //}; await _paymentSqlRepository.AddAsync(new DomainPayment(id, articleId, userId)); await _paypalClient.CreatePaymentAsync(paypalAmount, null, paypalItem); }
public async Task AddRelationAsync(Guid groupId, Guid activityId) { var relation = new GroupActivityRelation { ActivityId = activityId, GroupId = groupId, Id = Guid.NewGuid() }; await _groupActivityRepository.AddAsync(relation); }
public async Task CreateAsync(Guid entityId, string mediaIds) { if (!string.IsNullOrEmpty(mediaIds) && !string.IsNullOrWhiteSpace(mediaIds)) { await _sqlRepository.AddAsync(new IntranetMediaEntity { Id = Guid.NewGuid(), EntityId = entityId, MediaIds = mediaIds }); } }
public virtual async Task <ActivitySubscribeSetting> CreateAsync(ActivitySubscribeSettingDto setting) { var createSetting = new ActivitySubscribeSetting { ActivityId = setting.ActivityId, CanSubscribe = setting.CanSubscribe, SubscribeNotes = setting.SubscribeNotes }; await _activitySubscribeSettingRepository.AddAsync(createSetting); return(createSetting); }
public async Task AddAsync(Guid userId, Guid entityId) { if (await CanAddAsync(userId, entityId)) { var like = new Like { Id = Guid.NewGuid(), EntityId = entityId, UserId = userId, CreatedDate = DateTime.UtcNow }; await _likesRepository.AddAsync(like); } }
public async Task <Guid> CreateAsync(GroupModel groupModel) { var date = DateTime.UtcNow; var group = groupModel.Map <Group>(); group.CreatedDate = date; group.UpdatedDate = date; group.Id = Guid.NewGuid(); await _groupRepository.AddAsync(group); await UpdateCacheAsync(); return(group.Id); }
public async Task <Guid> CreateAsync(MyLinkDTO model) { var entity = new MyLink { Id = Guid.NewGuid(), UserId = model.UserId, ContentId = model.ContentId, QueryString = model.QueryString.Trim('?'), CreatedDate = DateTime.UtcNow, ActivityId = model.ActivityId }; await _myLinksRepository.AddAsync(entity); return(entity.Id); }
public async Task NotifyAsync(IEnumerable <PopupNotificationMessage> messages) { var notifications = messages .Select(el => new Sql.Notification { Id = Guid.NewGuid(), Date = DateTime.UtcNow, IsNotified = true, IsViewed = false, Type = el.NotificationType.ToInt(), NotifierType = NotifierTypeEnum.PopupNotifier.ToInt(), Value = new { el.Message }.ToJson(), ReceiverId = el.ReceiverId }); await _notificationRepository.AddAsync(notifications); }
public async Task SignUpAsync(Guid id, string email, string firstName, string lastName, string password, string role = null) { var user = await _userRepository.GetAsync(u => u.Email == email); if (user != null) { throw new JppcException(Codes.EmailInUse, $"Email: '{email}' is already in use."); } if (string.IsNullOrWhiteSpace(role)) { role = Role.User; } user = new User(id, email, firstName, lastName, role); user.SetPassword(password, _passwordHasher); await _userRepository.AddAsync(user); }
public async Task SaveAsync <T>(NotifierSettingModel <T> settingModel) where T : INotifierTemplate { var identity = new ActivityEventIdentity(settingModel.ActivityType, settingModel.NotificationType) .AddNotifierIdentity(settingModel.NotifierType); var(setting, isCreated) = await FindOrCreateSettingAsync <T>(identity); var updatedSetting = GetUpdatedSetting(setting, settingModel); if (isCreated) { await _repository.AddAsync(updatedSetting); } else { await _repository.UpdateAsync(updatedSetting); } }
public async Task <JsonWebToken> SignInAsync(string email, string password) { var user = await _userRepository.GetAsync(u => u.Email == email); if (user == null || !user.ValidatePassword(password, _passwordHasher)) { throw new JppcException(Codes.InvalidCredentials, "Invalid credentials."); } var refreshToken = new RefreshToken(user, _passwordHasher); var claims = await _claimsProvider.GetAsync(user.Id); var jwt = _jwtHandler.CreateToken(user.Id.ToString("N"), claims); jwt.RefreshToken = refreshToken.Token; await _refreshTokenRepository.AddAsync(refreshToken); return(jwt); }
public async Task NotifyAsync(IEnumerable <UiNotificationMessage> messages) { var notifications = messages .Select(el => new Sql.Notification { Id = Guid.NewGuid(), Date = DateTime.UtcNow, IsNotified = false, NotifierType = NotifierTypeEnum.UiNotifier.ToInt(), IsViewed = false, Type = el.NotificationType.ToInt(), Value = new { el.Message, el.Url, el.NotifierId, el.IsPinned, el.IsPinActual, el.DesktopMessage, el.DesktopTitle, el.IsDesktopNotificationEnabled }.ToJson(), ReceiverId = el.ReceiverId }).ToList(); await _notificationRepository.AddAsync(notifications); var notNotifiedNotifications = notifications.SelectMany(i => GetNotNotifiedNotifications(i.ReceiverId)); SendNewUiNotificationsArrived(notNotifiedNotifications); }
public async Task SetAsync(Guid activityId, ActivityLocation location) { var oldLocation = await _locationRepository .AsQueryable() .SingleOrDefaultAsync(l => l.ActivityId == activityId); if (oldLocation is null) { if (location is null) { return; } var newLocation = new ActivityLocationEntity() { ActivityId = activityId, Address = location.Address, ShortAddress = location.ShortAddress }; await _locationRepository.AddAsync(newLocation); } else { if (location?.Address == null || location.ShortAddress == null) { await _locationRepository.DeleteAsync(oldLocation.Id); } else { oldLocation.Address = location.Address; oldLocation.ShortAddress = location.ShortAddress; await _locationRepository.UpdateAsync(oldLocation); } } }
public async Task AddAsync(Guid entityId, IEnumerable <Guid> tagIds) { var entities = tagIds.Select(tagId => MapToEntity(entityId, tagId)); await _relationRepository.AddAsync(entities); }