Exemplo n.º 1
0
        public IDataResult <User> Register(UserForRegisterDto userForRegisterDto, string password, string imgName)
        {
            //metota verilen string password olamasa da olur. Çünkü password değeri userForRegisterDto içinde var.
            //string password kullanıcının texte girdiği haslenmemiş parola

            byte[] passwordHash, passwordSalt; //işlem bitince bunlar oluşacak

            //bu çalışınca hash ve salt değerleri dönecek. bu operasyon dönünce yukarıda tanımlanan değerlerde değişecek.
            HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);

            var user = new User
            {
                Email        = userForRegisterDto.Email,
                FirstName    = userForRegisterDto.FirstName,
                LastName     = userForRegisterDto.LastName,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt,
                Status       = true,
                ImgName      = imgName
            };

            _userService.Add(user);

            var registerSave = new SuccessDataResult <User>(user, Messages.UserRegistered);

            _userService.AddUserRole(userForRegisterDto, registerSave.Data.Id);//kayıt işleminden sonra role tablosuna kaydetme işlemine geçer.
            //return new SuccessResult(registerSave.Message);
            return(new SuccessDataResult <User>(user, Messages.UserRegistered));
        }
Exemplo n.º 2
0
        [TransactionScopeAspect]//+++
        public IDataResult <Post> Add(PostCreateDto postCreateDto, string imageName)
        {
            var post = new Post
            {
                Title     = postCreateDto.Title,
                Content   = postCreateDto.Content,
                ImageName = imageName,
                UserId    = postCreateDto.UserId,
                Created   = DateTime.Now
            };

            _postDal.Add(post);
            var postSave = new SuccessDataResult <Post>(post, Messages.UserRegistered);

            string[] category = postCreateDto.CategoryId.Split("*");
            foreach (var item in category)
            {
                if (item != "")
                {
                    var postCategory = new PostCategoryCreateDto {
                        PostId = postSave.Data.Id, CategoryId = item
                    };
                    _postCategoryService.Add(postCategory);
                }
            }
            return(new SuccessDataResult <Post>(post, Messages.PostAdded));
        }
Exemplo n.º 3
0
            public async Task <IDataResult <IEnumerable <Product> > > Handle(GetProductsQuery request, CancellationToken cancellationToken)
            {
                var result = new SuccessDataResult <IEnumerable <Product> >(await _productDal.GetListAsync());

                _messageBrokerHelper.QueueMessage($"GetProductsQuery Komutuyla Bütün Ürünler Sorgulandı.");
                return(result);
            }
Exemplo n.º 4
0
        public ActionResult Login(UserForLoginDto userForLoginDto)
        {
            var userToLogin = _authService.Login(userForLoginDto);

            if (!userToLogin.Success)
            {
                return(BadRequest(userToLogin));
            }

            var tokenResult = _authService.CreateAccessToken(userToLogin.Data);

            if (!tokenResult.Success)
            {
                return(BadRequest(tokenResult));
            }
            AuthDto authDto = new AuthDto
            {
                UserId     = userToLogin.Data.Id,
                FirstName  = userToLogin.Data.FirstName,
                LastName   = userToLogin.Data.LastName,
                Token      = tokenResult.Data.Token,
                Expiration = tokenResult.Data.Expiration,
            };
            var result = new SuccessDataResult <AuthDto>(authDto, userToLogin.Message);

            return(Ok(result));
        }
Exemplo n.º 5
0
        public ActionResult Register(UserForRegisterDto userForRegisterDto)
        {
            var userExists = _authService.UserExists(userForRegisterDto.Email);

            if (!userExists.Success)
            {
                return(BadRequest(userExists));
            }

            var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password);
            var tokenResult    = _authService.CreateAccessToken(registerResult.Data);

            if (!tokenResult.Success)
            {
                return(BadRequest(tokenResult));
            }
            var loginDto = new UserForLoginDto
            {
                Email    = userForRegisterDto.Email,
                Password = userForRegisterDto.Password
            };
            var     userToLogin = _authService.Login(loginDto).Data.Id;
            AuthDto authDto     = new AuthDto
            {
                UserId     = userToLogin,
                FirstName  = registerResult.Data.FirstName,
                LastName   = registerResult.Data.LastName,
                Token      = tokenResult.Data.Token,
                Expiration = tokenResult.Data.Expiration
            };
            var result = new SuccessDataResult <AuthDto>(authDto, registerResult.Message);

            return(Ok(result));
        }
Exemplo n.º 6
0
        public async Task <IDataResult <Product> > Add(ProductCreateDto productCreateDto)
        {
            var product = new Product
            {
                ProductName   = productCreateDto.ProductName,
                ProductTypeId = productCreateDto.ProductTypeId,
                //  Title = productCreateDto.Title,
                Content = productCreateDto.Content,
                UserId  = productCreateDto.UserId,
                Created = DateTime.Now
            };
            await _productDal.Add(product);

            // var postSave = new SuccessDataResult<Product>(product, Messages.UserRegistered);
            if (productCreateDto.Categories != null)
            {
                var entity = new SuccessDataResult <Product>(product);
                foreach (var item in productCreateDto.Categories)
                {
                    await _productCategoryService.Add(
                        new ProductCategoryCreateDto { ProductId = entity.Data.Id, CategoryId = item }
                        );
                }
            }
            return(new SuccessDataResult <Product>(product, Messages.ProductAdded));
        }
Exemplo n.º 7
0
        public virtual IActionResult GetByProductId(int id)
        {
            var _couponService = EngineContext.Current.Resolve <ICouponService>();
            var coupon         = _couponService.GetCouponByProductId(id);
            var result         = new SuccessDataResult(coupon);

            return(Ok(result));
        }
Exemplo n.º 8
0
        public virtual async Task <IActionResult> Delete(int customerId, [FromBody] DeleteShoppingCartItemModel model)
        {
            var updatedShoppingCart = await _shoppingCartService.DeleteShoppingCartItem(model.ProductId, customerId, model.ShoppingCartType);

            var result = new SuccessDataResult(updatedShoppingCart);

            return(Ok(result));
        }
Exemplo n.º 9
0
        public virtual async Task <IActionResult> Put(int customerId, [FromBody] UpdateShoppingCartItemModel model)
        {
            var shoppingCartItem    = model.ModelToEntity <ShoppingCartItem>();
            var updatedShoppingCart = await _shoppingCartService.UpdateShoppingCartItem(shoppingCartItem, customerId, model.ShoppingCartType);

            var result = new SuccessDataResult(updatedShoppingCart);

            return(Ok(result));
        }
Exemplo n.º 10
0
        public IActionResult Get()
        {
            var score       = RandomCreditScoreGenerator(0, 1900);
            var creditScore = new CustomerCreditScore
            {
                CreditScore = score
            };
            IDataResult <CustomerCreditScore> creditScoreReturn = new SuccessDataResult <CustomerCreditScore>(creditScore, "Müşreti findeks puanı başarıyla getirildi.");

            return(Ok(creditScoreReturn));
        }
Exemplo n.º 11
0
        public IActionResult GetUserInfo()
        {
            var userInfo = new SuccessDataResult <UserInfoDto>(new UserInfoDto
            {
                Fullname        = User.GetName(),
                Email           = User.GetEmail(),
                OperationClaims = User.GetClaimRoles()
            });

            return(Ok(userInfo));
        }
Exemplo n.º 12
0
        public virtual async Task <IActionResult> Get(string id)
        {
            var _productService = EngineContext.Current.Resolve <IProductService>();

            var product = await _productService.GetByIdAsync(id);

            var model = product.ToModel <ProductModel>();

            var result = new SuccessDataResult(model);

            return(Ok(result));
        }
Exemplo n.º 13
0
        public async Task UserExist_IfUserNotExist_ShouldReturnSuccessResult()
        {
            User user = null;
            IDataResult <User> dataResult = new SuccessDataResult <User>(user);

            _mockUserService.Setup(s => s.GetByMailAsync("*****@*****.**"))
            .ReturnsAsync(dataResult);

            AuthManager authManager = new AuthManager(_mockUserService.Object, _mockTokenHelper.Object);

            var result = await authManager.UserExistAsync("*****@*****.**");

            Assert.True(result.Success);
        }
Exemplo n.º 14
0
        public void Add_WhenFixturePositionIsNotAvailable_ShouldThrowLogicException()
        {
            // Arrange
            DebitForAddDto        debitForAddDto    = new DebitForAddDto();
            IDataResult <Fixture> fixtureDataResult = new SuccessDataResult <Fixture>(new Fixture()
            {
                FixturePositionId = 2
            });
            var mockDebitDal       = new MockDebitDal().MockAdd(new Debit());
            var mockFixtureService = new MockFixtureService().MockGetById(fixtureDataResult).MockUpdatePostiton(new SuccessResult());
            var sut = new DebitManager(mockDebitDal.Object, mockFixtureService.Object);

            // Act & Assert
            Assert.Throws <LogicException>(() => sut.Add(debitForAddDto));
        }
Exemplo n.º 15
0
        public void Delete_WhenFixturePositionIsNotDebit_ShouldThrowLogicException()
        {
            // Arrange
            Guid debitId = Guid.NewGuid();
            IDataResult <Fixture> fixtureDataResult = new SuccessDataResult <Fixture>(new Fixture()
            {
                FixturePositionId = 0
            });
            var mockDebitDal       = new MockDebitDal().MockUpdate().MockGet(new Debit());
            var mockFixtureService = new MockFixtureService().MockGetById(fixtureDataResult).MockUpdatePostiton(new SuccessResult());
            var sut = new DebitManager(mockDebitDal.Object, mockFixtureService.Object);

            // Act & Assert
            Assert.Throws <LogicException>(() => sut.Delete(debitId));
        }
Exemplo n.º 16
0
        public async Task UserExist_IfUserAlreadyExist_ShouldReturnError()
        {
            User user = new User();
            IDataResult <User> dataResult = new SuccessDataResult <User>(user);

            _mockUserService.Setup(s => s.GetByMailAsync("*****@*****.**"))
            .ReturnsAsync(dataResult);

            AuthManager authManager = new AuthManager(_mockUserService.Object, _mockTokenHelper.Object);

            var result = await authManager.UserExistAsync("*****@*****.**");

            Assert.False(result.Success);
            Assert.Equal(Messages.UserAlreadyExist, result.Message);
        }
        public async Task <IDataResult <IEnumerable <PivotReportTemplate> > > GetAll()
        {
            IDataResult <IEnumerable <PivotReportTemplate> > result;

            try
            {
                var data = await _pivotReportTemplateDal.List(null);

                result = new SuccessDataResult <IEnumerable <PivotReportTemplate> >(data);
            }
            catch (Exception ex)
            {
                result = new ErrorDataResult <IEnumerable <PivotReportTemplate> >(null, ex.Message);
            }

            return(result);
        }
Exemplo n.º 18
0
        public async Task <IDataResult <TEntity> > GetById(int id)
        {
            IDataResult <TEntity> result;

            try
            {
                var entity = await _baseDal.Get(x => x.Id == id);

                result = new SuccessDataResult <TEntity>(entity, "Update was succesed");
            }
            catch (Exception ex)
            {
                result = new SuccessDataResult <TEntity>(ex.Message);
            }

            return(result);
        }
Exemplo n.º 19
0
        public void Delete_WhenDeletedDebit_ShouldUpdateReturnStatus()
        {
            // Arrange
            Guid debitId = Guid.NewGuid();
            IDataResult <Fixture> fixtureDataResult = new SuccessDataResult <Fixture>(new Fixture()
            {
                FixturePositionId = 2
            });
            var mockDebitDal       = new MockDebitDal().MockUpdate().MockGet(new Debit());
            var mockFixtureService = new MockFixtureService().MockGetById(fixtureDataResult).MockUpdatePostiton(new SuccessResult());
            var sut = new DebitManager(mockDebitDal.Object, mockFixtureService.Object);

            // Act
            sut.Delete(debitId);

            // Assert
            mockDebitDal.VerifyUpdate(Times.Once());
        }
Exemplo n.º 20
0
        public virtual async Task <IActionResult> Get(int customerId, ShoppingCartType shoppingCartType)
        {
            var shoppingCart = await _shoppingCartService.GetShoppingCart(customerId, shoppingCartType);

            if (shoppingCart.ShoppingCartItems != null && shoppingCart.ShoppingCartItems.Any())
            {
                foreach (var cartItem in shoppingCart.ShoppingCartItems)
                {
                    var coupon = await _discountProtoServiceClient.GetDiscountAsync(new GetDiscountRequest { ProductId = cartItem.ProductId });

                    _shoppingCartService.CalculateCartItemPrice(cartItem, coupon.Amount);
                }
            }

            var result = new SuccessDataResult(shoppingCart);

            return(Ok(result));
        }
Exemplo n.º 21
0
        public void Add_WhenAddedNewDebit_ShouldAddAndReturnId()
        {
            // Arrange
            DebitForAddDto        debitForAddDto    = new DebitForAddDto();
            IDataResult <Fixture> fixtureDataResult = new SuccessDataResult <Fixture>(new Fixture()
            {
                FixturePositionId = 1
            });
            var mockDebitDal       = new MockDebitDal().MockAdd(new Debit());
            var mockFixtureService = new MockFixtureService().MockGetById(fixtureDataResult).MockUpdatePostiton(new SuccessResult());
            var sut = new DebitManager(mockDebitDal.Object, mockFixtureService.Object);

            // Act
            var result = sut.Add(debitForAddDto);

            // Assert
            Assert.Equal(new Guid(), result.Data);
        }
Exemplo n.º 22
0
        public async Task CreateAccessTokenAsync_IfCorrect_ShouldReturSuccessResult()
        {
            Guid userId = new Guid();

            User user = new User
            {
                Id = userId
            };

            IDataResult <List <Role> > claims = new SuccessDataResult <List <Role> >(new List <Role> {
                new Role
                {
                    Name = "Test Name 1"
                }
            });

            AccessToken accessToken = new AccessToken
            {
                Token      = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFobWV0dW5nZUBvdXRsb29rLmNvbSIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJBaG1ldCDDnG5nZSIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWVpZGVudGlmaWVyIjoiY2Q3NDQ3MGMtNGNlNy00ODE3LWJjZTYtZmY5YzMxZDM2Y2Y0IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW4iLCJuYmYiOjE1ODQyNzY4MjIsImV4cCI6MTU4NDI3NzQyMiwiaXNzIjoid3d3LmFobWV0dW5nZS5jb20iLCJhdWQiOiJ3d3cuYWhtZXR1bmdlLmNvbSJ9.FeWXYaH4_1YrCW2jz3HqyDS4lD3FGNoDHk5M0e-LgnQ",
                Expiration = new DateTime(1907, 10, 20)
            };

            _mockUserService.Setup(s => s.GetRolesAsync(It.IsAny <Guid>()))
            .ReturnsAsync(claims);

            _mockTokenHelper.Setup(th => th.CreateToken(It.IsAny <User>(), It.IsAny <List <Role> >()))
            .Returns(accessToken);


            AuthManager authManager = new AuthManager(_mockUserService.Object, _mockTokenHelper.Object);


            IDataResult <AccessToken> result = await authManager.CreateAccessTokenAsync(user);

            Assert.True(result.Success);

            Assert.Equal(accessToken.Token, result.Data.Token);
            Assert.Equal(accessToken.Expiration, result.Data.Expiration);
        }
Exemplo n.º 23
0
        public static async Task <IDataResult <IdentityResult> > WatchedListAsync(this UserManager <VesizleUser> userManager, ClaimsPrincipal userClaims, WatchedList watchedList)
        {
            IDataResult <IdentityResult> result;
            var userId = userClaims.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = await userManager.Users.Include(vesizleUser => vesizleUser.WatchedLists)
                         .FirstOrDefaultAsync(vesizleUser => vesizleUser.Id == userId);

            var userWatched = user.WatchedLists.FirstOrDefault(watch => watch.MovieId == watchedList.MovieId);

            if (userWatched == null)
            {
                user.WatchedLists.Add(watchedList);
                result = new SuccessDataResult <IdentityResult>(Messages.AddWatchedListSuccess, await userManager.UpdateAsync(user));
            }
            else
            {
                user.WatchedLists.Remove(userWatched);
                result = new SuccessDataResult <IdentityResult>(Messages.RemoveWatchedListSuccess, await userManager.UpdateAsync(user));
            }

            return(result);
        }
Exemplo n.º 24
0
        public static async Task <IDataResult <IdentityResult> > FavoriteAsync(this UserManager <VesizleUser> userManager, ClaimsPrincipal userClaims, Favorite favorite)
        {
            IDataResult <IdentityResult> result;
            var userId = userClaims.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = await userManager.Users.Include(vesizleUser => vesizleUser.Favorites)
                         .FirstOrDefaultAsync(vesizleUser => vesizleUser.Id == userId);

            var userFav = user.Favorites.FirstOrDefault(fav => fav.MovieId == favorite.MovieId);

            if (userFav == null)
            {
                user.Favorites.Add(favorite);
                result = new SuccessDataResult <IdentityResult>(Messages.AddFavoriteSuccess, await userManager.UpdateAsync(user));
            }
            else
            {
                user.Favorites.Remove(userFav);
                result = new SuccessDataResult <IdentityResult>(Messages.RemoveFavoriteSuccess, await userManager.UpdateAsync(user));
            }

            return(result);
        }
Exemplo n.º 25
0
        public async Task Login_IfPasswordWrong_ShouldReturnError()
        {
            User user = new User
            {
                PasswordHash = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
                PasswordSalt = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }
            };

            IDataResult <User> dataResult = new SuccessDataResult <User>(user);

            _mockUserService.Setup(s => s.GetByMailAsync("*****@*****.**"))
            .ReturnsAsync(dataResult);

            AuthManager authManager = new AuthManager(_mockUserService.Object, _mockTokenHelper.Object);

            var result = await authManager.LoginAsync(new UserForLoginDto
            {
                Email    = "*****@*****.**",
                Password = "******"
            });

            Assert.False(result.Success);
            Assert.Equal(Messages.UserNotFound, result.Message);
        }
Exemplo n.º 26
0
        public async Task <IDataResult <Users> > Login(UserLoginModel userLoginModel)
        {
            IDataResult <Users> result;

            try
            {
                var resultUser = await _userDal.Get(x => x.UserName == userLoginModel.UserName && x.Password == userLoginModel.Password);

                if (resultUser != null)
                {
                    result = new SuccessDataResult <Users>(resultUser);
                }
                else
                {
                    result = new SuccessDataResult <Users>(resultUser, "User was not found.");
                }
            }
            catch (Exception ex)
            {
                result = new ErrorDataResult <Users>(null, ex.Message);
            }

            return(result);
        }
Exemplo n.º 27
0
        public IDataResult <List <Person> > GetAllPersons()
        {
            var result = new SuccessDataResult <List <Person> >(_personDal.GetList(null, pi1 => pi1.ContactInfos));

            return(result);
        }
        public IDataResult <User> GetByEmail(string email)
        {
            var result = new SuccessDataResult <User>(_userDal.Get(u => u.Email == email));

            return(result);
        }