Exemplo n.º 1
0
        public void DeleteBeneficiar(OftenBeneficiary deleteBeneficiar)
        {
            var temp = dbContext.OftenBeneficiary.Remove(deleteBeneficiar);

            dbContext.SaveChanges();
            return;
        }
Exemplo n.º 2
0
 public OftenBeneficiary AddBeneficiar(OftenBeneficiary Beneficiary)
 {
     dbContext.OftenBeneficiary.Add(Beneficiary);
     dbContext.SaveChanges();
     dbContext.Entry(Beneficiary).Reference(Beneficiary => Beneficiary.PayeeType).Load();
     return(Beneficiary);
 }
Exemplo n.º 3
0
        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
            });
        }
        private string CheckBenificiarExistence(long id)
        {
            OftenBeneficiary Beneficiary = beneficiaryService.GetBeneficiarById(id);

            if (Beneficiary == null)
            {
                return("Beneficiary does not exist!");
            }
            return(null);
        }
Exemplo n.º 5
0
 public OftenBeneficiary ModifyBeneficiar(OftenBeneficiary modifyBeneficiar, OftenBeneficiary originalBeneficiar)
 {
     dbContext.Entry(originalBeneficiar).CurrentValues.SetValues(modifyBeneficiar);
     dbContext.Entry(originalBeneficiar).Property(x => x.CreateTime).IsModified = false;
     dbContext.Entry(originalBeneficiar).Property(x => x.UserId).IsModified     = false;
     dbContext.OftenBeneficiary.Update(originalBeneficiar);
     dbContext.SaveChanges();
     dbContext.Entry(originalBeneficiar).Reference(Beneficiary => Beneficiary.PayeeType).Load();
     dbContext.Entry(originalBeneficiar).Reference(Beneficiary => Beneficiary.PayeeRelation).Load();
     return(originalBeneficiar);
 }
Exemplo n.º 6
0
        //[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
            });
        }
Exemplo n.º 7
0
        public ActionResult <MessageModel <UserBeneficiaryDTO> > DeleteOwnBeneficiarsInfo([FromRoute, SwaggerParameter("id,可從/user/beneficiars取得", Required = true)] int id)
        {
            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"
                }));
            }
            beneficiaryService.DeleteBeneficiar(Beneficiary);

            return(new MessageModel <UserBeneficiaryDTO>()
            {
            });
        }