Beispiel #1
0
        public async Task <int> SaveClaims(ClaimDetails claimDetail)

        {
            return(await _claimsRepository.SaveClaims(claimDetail));
        }
        public async Task <int> SaveClaims(ClaimDetails claimDetail)

        {
            try

            {
                ClaimTypes claimType = await _dBContext.ClaimTypes.AsNoTracking().Where(c => c.ClaimType == claimDetail.ClaimType).FirstOrDefaultAsync();

                Member member = await _dBContext.Member.AsNoTracking().Where(m => m.FirstName + " " + m.LastName == claimDetail.MemberName).FirstOrDefaultAsync();



                var claim = await _dBContext.Claims.AsNoTracking().Where(c => c.ClaimID == claimDetail.ClaimID).FirstOrDefaultAsync();

                if (claim == null)

                {
                    Claims claims = new Claims()

                    {
                        ClaimID = 0,

                        ClaimType = claimType.ClaimTypeID,

                        ClaimAmount = claimDetail.ClaimAmount,

                        ClaimDate = claimDetail.ClaimDate,

                        Remarks = claimDetail.Remarks,

                        MemberID = member.MemberID
                    };

                    _dBContext.Claims.Add(claims);

                    await _dBContext.SaveChangesAsync();
                }

                else

                {
                    claim = new Claims()

                    {
                        ClaimType = claimType.ClaimTypeID,

                        ClaimAmount = claimDetail.ClaimAmount,

                        ClaimDate = claimDetail.ClaimDate,

                        Remarks = claimDetail.Remarks,

                        MemberID = member.MemberID
                    };

                    _dBContext.Claims.UpdateRange(claim);

                    await _dBContext.SaveChangesAsync();
                }

                return(claimDetail.ClaimID);
            }

            catch (Exception ex)

            {
                throw ex;
            }
        }