/// <summary> /// Adds a post to the database. /// </summary> /// <param name="posterId"></param> /// <param name="post"></param> /// <param name="tagIds"></param> public async Task <PostModel> Add(HttpRequest httpRequest, string token, string path) { try { PostModel post = CreatePost(httpRequest["Content"], httpRequest["IsPublic"]); List <TagDto> tags = GetTags(httpRequest); post.ImgUrl = await GetImageUrl(httpRequest.Files["Pic"], path); var userId = await _commonOperationsManager.VerifyToken(token).ConfigureAwait(false); post.Id = GenerateId(); post.WriterName = await GetFullName(token); var addedPost = await _postsRepository.Add(userId, post, tags); tags?.ForEach(async(tag) => { try { string myUsername = await GetFullName(token); await _commonOperationsManager.SendNotification(tag.Id, $"You were taged in a post by {myUsername}", token); } catch (Exception e) { //Log/Handle notification was not sent. Does not affect general state of like operation. } }); return(addedPost); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Addes user with the email specified. /// </summary> /// <param name="token"></param> /// <param name="email"></param> /// <returns></returns> public async Task Add(string token, string email, string name) { try { string userId = await _commonOperationsManager.VerifyToken(token); UserModel userToAdd = CreateUser(email, userId, name); await _usersRepository.Add(userToAdd); } catch (Exception) { throw; } }
/// <summary> /// Registers a new user to the notifications server. /// </summary> /// <param name="token"></param> /// <returns></returns> public async Task <NotificationsAuthDto> Register(string token) { try { string userId = await _commonOperationsManager.VerifyToken(token); var auth = new NotificationsAuthDto() { Username = userId, Password = userId }; await _notificationsHelper.Register(auth); return(auth); } catch (AuthenticationException) { throw new AuthenticationException(); } catch (Exception e) { throw new Exception(); } }