public ActionResult <MessageModel <UserBeneficiaryDTO> > ModifyOwnBeneficiarsInfo([FromRoute, SwaggerParameter("id,可從/user/beneficiars取得", Required = true)] int id, [FromBody] OftenBeneficiaryRequest oftenBeneficiarRequest) { var userId = long.Parse(User.FindFirstValue("id")); OftenBeneficiary Beneficiary = beneficiaryService.GetBeneficiarById(id); if (Beneficiary == null) { return(NotFound()); } if (userId != Beneficiary.UserId) { return(Unauthorized(new MessageModel <UserBeneficiaryDTO>() { Success = false, Msg = "Unauthorized" })); } OftenBeneficiary modifiedBeneficiar = mapper.Map <OftenBeneficiary>(oftenBeneficiarRequest); modifiedBeneficiar.Id = id; var payeeType = payeeTypeService.GetPayeeTypeByType((PayeeTypeEnum)oftenBeneficiarRequest.PayeeType); modifiedBeneficiar.PayeeTypeId = payeeType.Id; beneficiaryService.ModifyBeneficiar(modifiedBeneficiar, Beneficiary); UserBeneficiaryDTO userBeneficiarDTO = mapper.Map <UserBeneficiaryDTO>(Beneficiary); return(new MessageModel <UserBeneficiaryDTO> { Data = userBeneficiarDTO }); }
//[AllowAnonymous] public MessageModel <UserBeneficiaryDTO> AddOwnBeneficiarsInfo([FromBody] OftenBeneficiaryRequest oftenBeneficiarRequest) { var userId = long.Parse(User.FindFirstValue("id")); OftenBeneficiary OftenBeneficiary = mapper.Map <OftenBeneficiary>(oftenBeneficiarRequest); OftenBeneficiary.UserId = userId; var payeeType = payeeTypeService.GetPayeeTypeByType((PayeeTypeEnum)oftenBeneficiarRequest.PayeeType); OftenBeneficiary.PayeeTypeId = payeeType.Id; beneficiaryService.AddBeneficiar(OftenBeneficiary); UserBeneficiaryDTO userBeneficiarDTO = mapper.Map <UserBeneficiaryDTO>(OftenBeneficiary); return(new MessageModel <UserBeneficiaryDTO> { Data = userBeneficiarDTO }); }
public MessageModel <List <UserBeneficiaryDTO> > GetOwnBeneficiarsInfo() { var userId = long.Parse(User.FindFirstValue("id")); List <OftenBeneficiary> oftenBeneficiars = beneficiaryService.GetAllBeneficiars(userId); List <ReceiveBank> banks = bankService.GetReceiveBanks(); List <UserBeneficiaryDTO> userBeneficiaryDTOs = new List <UserBeneficiaryDTO>(); foreach (OftenBeneficiary beneficiary in oftenBeneficiars) { ReceiveBank bank = banks.Find(bank => bank.Id == beneficiary.ReceiveBankId); UserBeneficiaryDTO userBeneficiaryDTO = mapper.Map <UserBeneficiaryDTO>(beneficiary); userBeneficiaryDTO.EnName = bank.EnName; userBeneficiaryDTO.TwName = bank.TwName; userBeneficiaryDTO.VietName = bank.VietName; userBeneficiaryDTOs.Add(userBeneficiaryDTO); } return(new MessageModel <List <UserBeneficiaryDTO> > { Data = userBeneficiaryDTOs }); }