예제 #1
0
        public DonorSignInResponseViewModel SignIn(DonorSignInViewModel model)
        {
            if (model != null)
            {
                try
                {
                    var repo  = unitOfWork.GetRepository <Donors>();
                    var query = repo.Get();

                    var donor = query.Where(x => (x.Email == model.Email && x.Password == model.Password)).Select(x => x).FirstOrDefault();

                    if (donor != null)
                    {
                        var resultedDonor = new DonorSignInResponseViewModel
                        {
                            Email = donor.Email
                        };

                        return(resultedDonor);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(null);
        }
        public IActionResult SignIn([FromBody] DonorSignInViewModel model)
        {
            var result = accountService.SignIn(model);

            var token = JWTTokenHandler.GenerateJwtToken(result.Email);

            return(Ok(new DonorSignInResponseViewModel
            {
                Email = result.Email,
                Token = token
            }));
        }