public async Task <IActionResult> Add([FromForm] PaymentNotificationDto paymentNotificationDto) { try { var paymentNotification = _mapper.Map <PaymentNotification>(paymentNotificationDto); var userAddedPaymentNotification = await _paymentNotificationService.Add(paymentNotification, paymentNotificationDto.Images); var tokenString = ""; var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, userAddedPaymentNotification.Id.ToString()) }), Expires = DateTime.UtcNow.AddDays(365), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); tokenString = tokenHandler.WriteToken(token); var userDtoUser = _mapper.Map <UserDtoUser>(userAddedPaymentNotification); userDtoUser.Token = tokenString; return(Ok(userDtoUser)); } catch (AppException ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> GetByHiDee([FromForm] PaymentNotificationDto paymentNotificationDto) { var paymentNotificationByHiDee = await _paymentNotificationService.GetByHiDee(paymentNotificationDto.TransactionType, paymentNotificationDto.UserHiDee); if (paymentNotificationDto.UserHiDee.Equals(GlobalVariables.BaseKey())) { var paymentNotificationDtoAdmin = _mapper.Map <IList <PaymentNotificationDto> >(paymentNotificationByHiDee); return(Ok(paymentNotificationDtoAdmin)); } else { var paymentNotificationDtoUser = _mapper.Map <IList <PaymentNotificationDtoUser> >(paymentNotificationByHiDee); return(Ok(paymentNotificationDtoUser)); } }
public async Task <IActionResult> Update([FromForm] PaymentNotificationDto paymentNotificationDto) { try { var paymentNotification = _mapper.Map <PaymentNotification>(paymentNotificationDto); var updatedPaymentNotification = await _paymentNotificationService.Update(paymentNotification, paymentNotificationDto.Images); var paymentNotificationDtoUser = _mapper.Map <PaymentNotificationDtoUser>(updatedPaymentNotification); return(Ok(paymentNotificationDtoUser)); } catch (AppException ex) { return(BadRequest(ex.Message)); } }