Esempio n. 1
0
        public async Task <CollaboratorResponseDto> AddCollaborator(string email, int userId, CollaboratorRequestDto collaborator)
        {
            try
            {
                Collaborator modelCollaborator = _mapper.Map <Collaborator>(collaborator);
                if (email == modelCollaborator.email)
                {
                    throw new FundooException(ExceptionMessages.SELF_COLLABORATE);
                }
                Collaborator collaboratorWithSameUser = await _collaboratorRepository.GetCollaboratorByEmail(modelCollaborator.email, modelCollaborator.NoteId);

                if (collaboratorWithSameUser != null)
                {
                    throw new FundooException(ExceptionMessages.ALREADY_COLLABORATER);
                }
                Note note = await _noteRepository.GetNote(modelCollaborator.NoteId, userId);

                if (note == null)
                {
                    throw new FundooException(ExceptionMessages.NO_SUCH_NOTE);
                }
                Message message = new EmailService.Message(new string[] { modelCollaborator.email },
                                                           "Added as collaborator",
                                                           $"<h2>You have been added as collaborated by <p style='color:red'>" + email + "</p> To note <p style='color:green'>" + note.Title + "</p><h2>");
                _mqServices.AddToQueue(message);
                return(_mapper.Map <CollaboratorResponseDto>(await _collaboratorRepository.AddCollaborator(email, modelCollaborator)));
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateException)
            {
                throw new FundooException(ExceptionMessages.NO_SUCH_USER);
            }
        }
Esempio n. 2
0
        public void callback(List <OrderResponseDto> orders, List <CartResponseDto> cartItems, string guid, int userId)
        {
            string emailHtmlMessage = "";

            orders.ForEach(item =>
                           emailHtmlMessage += _emailItems.ItemDetailHtml(item.Book.Title, item.Book.Author, item.Book.Image, item.Book.Price, item.Quantity)
                           );
            int total = cartItems.Aggregate(0, (sum, item) =>
                                            sum + (item.Book.Price * item.ItemQuantity)
                                            );
            string  orderDetails = _emailItems.OrderDetailHtml(guid, orders[0].OrderedDate, total);
            Message message      = new Message(new string[] { orders[0].User.Email },
                                               "Order successfully placed!",
                                               $"{emailHtmlMessage + orderDetails}");

            cartItems.ForEach(item => _cacheRepository.DeleteAsync(userId.ToString(), item.Book.Id));
            _mqservice.AddToQueue(message);
        }
Esempio n. 3
0
        public async Task ForgotPassword(string email, string currentUrl)
        {
            Account user = await _repository.Get(email);

            if (user == null)
            {
                throw new FundooException(ExceptionMessages.NO_SUCH_USER, 404);
            }
            byte[]  secretKey  = Encoding.ASCII.GetBytes(_configuration.GetSection("Jwt")["ResetPasswordSecretKey"]);
            int     expiryTime = Convert.ToInt32(_configuration.GetSection("Jwt")["ExpiryTime"]);
            string  jwt        = _tokenManager.Encode(user, expiryTime, secretKey);
            string  url        = "https://" + currentUrl + "/html/reset.html?" + jwt;
            Message message    = new Message(new string[] { user.Email },
                                             "Password Reset Email",
                                             $"<h6>Click on the link to reset password<h6><a href='{url}'>{jwt}</a>");

            _mqServices.AddToQueue(message);
        }
Esempio n. 4
0
        public async Task ForgotPassword(string email, string currentUrl)
        {
            var(user, password) = await _repository.AuthenticateUser(email);

            if (user == null)
            {
                throw new BookstoreException(ExceptionMessages.INVALID_USER, 404);
            }
            byte[]  secretKey  = Encoding.ASCII.GetBytes(_configuration.GetSection("Jwt")["ResetPasswordSecretKey"]);
            int     expiryTime = Convert.ToInt32(_configuration.GetSection("Jwt")["ExpiryTime"]);
            string  jwt        = _tokenManager.Encode(user, expiryTime, secretKey);
            string  url        = "https://" + currentUrl + "/html/reset.html?token=" + jwt;
            Message message    = new Message(new string[] { user.Email },
                                             "Password Reset Email",
                                             $"<h6>Click on the link to reset password<h6><a href='{url}'>{"click me"}</a>");

            _mqServices.AddToQueue(message);
            await _caching.CacheResponseAsync(jwt, email, TimeSpan.FromSeconds(expiryTime));
        }
Esempio n. 5
0
        public async Task <OrderResponseDto> Add(OrderRequestDto orderRequest, int userId)
        {
            try {
                var guid = Guid.NewGuid();
                OrderResponseDto order = await _repository.Add(userId, orderRequest.bookId, orderRequest.quantity, orderRequest.addressId, guid.ToString());

                await _cacheRepository.DeleteAsync(userId.ToString(), orderRequest.bookId);

                Message message = new Message(new string[] { order.User.Email },
                                              "Order successfully placed!",
                                              $"{_emailItems.ItemDetailHtml(order.Book.Title, order.Book.Author, order.Book.Image, order.Book.Price, order.Book.Quantity)+ _emailItems.OrderDetailHtml(order.OrderId, order.OrderedDate, order.Book.Price)}");
                _mqServices.AddToQueue(message);
                return(order);
            }
            catch (SqlException e) when(e.Number == SqlErrorNumbers.CONSTRAINT_VOILATION)
            {
                throw new BookstoreException("Invalid user!");
            }
        }