Exemplo n.º 1
0
        public async Task <OperationResult> RecoverPassword(string email)
        {
            var result = new OperationResult();

            var user = await userRepository.GetUserByEmail(email);

            if (user == null)
            {
                result.IsSuccessful = false;
                result.Message      = "Nie ma takiego adresu w bazie !";
                return(result);
            }

            user.RecoveryAddress = GetSalt().Substring(0, 32);

            var text = string.Format(
                @"Witaj. </br> Wysłana została prośba o zresetowanie hasła. Oto twój <a href=""http://localhost:8080/password/change?recoveryString={0}""> link</a>",
                user.RecoveryAddress);
            var emailResult = await OtherServices.SendEmail(user.Email, "Przywracanie hasla", text);


            var repoResult = await userRepository.SaveChangesAsync();

            if (repoResult > 0 && emailResult)
            {
                result.IsSuccessful = true;
                result.Message      = "Wysłano wiadomość odnawiającą hasło.";
            }
            else
            {
                result.IsSuccessful = false;
                result.Message      = "Ups coś poszło nie tak !";
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <OperationResult> DeleteAdvertisement(int userId, int adId, string message = null)
        {
            var ad = await repository.GetAsync(adId);

            if (ad.UserId != userId)
            {
                var user = await userRepository.GetAsync(userId);

                if (user.Role.Equals("Admin"))
                {
                    if (message == null)
                    {
                        return(new OperationResult()
                        {
                            IsSuccessful = false,
                            IsClientError = true,
                            Message = "Proszę dodać wiadomość !"
                        });
                    }

                    var otherUser = await userRepository.GetAsync(ad.UserId);

                    var text = string.Format(
                        @"Witaj. </br> Twoje ogłoszenie z serwisu Games4Trade o tytule: '{0}' zostało usunięte. Oto powód usunięcia ogłoszenia:<br>{1}",
                        ad.Title, message);
                    var emailResult = await OtherServices.SendEmail(otherUser.Email, "Wiadomość o usunięciu ogłoszenia.", text);

                    if (emailResult)
                    {
                        var repoResult = await RemoveAdWithPhotos(ad);

                        if (repoResult > 0)
                        {
                            return(new OperationResult()
                            {
                                IsSuccessful = true
                            });
                        }

                        return(OtherServices.GetIncorrectDatabaseConnectionResult());
                    }
                    return(new OperationResult()
                    {
                        IsSuccessful = false,
                        IsClientError = false
                    });
                }

                return(new OperationResult()
                {
                    IsSuccessful = false,
                    IsClientError = true,
                    Message = "Tylko administrator może usunąć cudze ogłoszenie!"
                });
            }

            var result = await RemoveAdWithPhotos(ad);

            if (result > 0)
            {
                return(new OperationResult()
                {
                    IsSuccessful = true
                });
            }

            return(new OperationResult()
            {
                IsSuccessful = false, IsClientError = true
            });
        }