public void Post([FromBody] PolicyInfoDto model)
        {
            var policyInfo = new PolicyInfo();

            policyInfo.PolicyNumber             = model.PolicyNumber;
            policyInfo.FullName                 = model.FullName;
            policyInfo.IdNumber                 = model.IdNumber;
            policyInfo.Nationality              = model.Nationality;
            policyInfo.DateOfBirth              = model.DateOfBirth;
            policyInfo.Gender                   = model.Gender;
            policyInfo.MaritalStatus            = model.MaritalStatus;
            policyInfo.Address                  = model.Address;
            policyInfo.Mobile                   = model.Mobile;
            policyInfo.HomeNumber               = model.HomeNumber;
            policyInfo.PlanName                 = model.PlanName;
            policyInfo.SumInsured               = model.SumInsured;
            policyInfo.TotalPremiumPayable      = model.TotalPremiumPayable;
            policyInfo.PaymentMode              = model.PaymentMode;
            policyInfo.PaymentMethod            = model.PaymentMethod;
            policyInfo.InsuredSignedDate        = model.InsuredSignedDate;
            policyInfo.RepresentativeSignedDate = model.RepresentativeSignedDate;
            policyInfo.RepresentativeName       = model.RepresentativeName;
            policyInfo.RepresentativeCode       = model.RepresentativeCode;
            context.PolicyInfo.InsertOne(policyInfo);
        }
        public RerutnDataDto GetPolicyInfo(string policynumber, string insuredidn, string insuredfname, string insuredlname)

        {
            MappingProfile.ConfigureMapper();
            RerutnDataDto data = new RerutnDataDto();

            data.name     = "maindata";
            data.maindata = new List <PolicyInfoDto>();

            using (var dbContext = new IBFEntities())
            {
                var policyTemp = (from p in dbContext.Policies
                                  join pv in dbContext.PolicyVersions on p.Id equals pv.PolicyId
                                  join curr in dbContext.Currencies on p.CurrencyId equals curr.Id

                                  join pvType in dbContext.PolicyVersionStatus on pv.PolicyVersionStatusId equals pvType.Id
                                  join product in dbContext.SubProducts on p.ProductId equals product.Id into producta
                                  from productl in producta.DefaultIfEmpty()

                                  join org in dbContext.People on pv.OrganisationId equals org.Id into orga
                                  from orgnl in orga.DefaultIfEmpty()
                                  join client in dbContext.People on pv.ClientId equals client.Id into clienta
                                  from clientl in clienta.DefaultIfEmpty()
                                  join beneficiary in dbContext.People on pv.BeneficiaryId equals beneficiary.Id into beneficiarya
                                  from beneficiaryl in beneficiarya.DefaultIfEmpty()

                                  where !pv.IsHidden && !pv.IsDelete && pv.IsActive &&
                                  !p.IsHidden && !p.IsDelete &&
                                  p.ProductId == 3 &&// სიცოცხლის დაზღვევა
                                  (!string.IsNullOrEmpty(policynumber) ? p.PolicyNumber == policynumber : 1 == 1) &&
                                  (!string.IsNullOrEmpty(insuredidn) ? beneficiaryl.PersonNo == insuredidn : 1 == 1) &&
                                  (!string.IsNullOrEmpty(insuredfname) ? beneficiaryl.FirstName.Contains(insuredfname) : 1 == 1) &&
                                  (!string.IsNullOrEmpty(insuredlname) ? beneficiaryl.Lastname.Contains(insuredlname) : 1 == 1)

                                  select new
                {
                    PolicyId = p.Id,
                    PolicyNumber = p.PolicyNumber,
                    PolicyVersionId = pv.Id,
                    //PolicyVersionIsActive = pv.IsActive,
                    StartDate = pv.StartDate,
                    EndDate = pv.EndDate,
                    // PolicyStatusId = pv.PolicyStatusId,
                    PolicyStatus = pv.StartDate <= DateTime.Now && pv.EndDate >= DateTime.Now ? pv.PolicyStatu.Name : "ვადაგასული",
                    //PolicyVersionStatusId = pv.PolicyVersionStatusId,
                    //CurrencyId = p.CurrencyId,
                    //Currency = curr.Name,
                    note = pv.InnerComment,
                    canceldate = pv.PolicyVersionStatusId == 3 ? p.EndDate : null,                  //??sanaxavia
                    //productl,
                    organizartionName = orgnl.FirstName,
                    //clientl,
                    beneficiaryl,
                    package = pv.PolicyContractPackages.FirstOrDefault().Name

                              //services = p.ContractPackageService.ContractPackage
                }).ToList();

                //policyTemp = policyTemp.GroupBy(g => new
                //{
                //    g.PolicyId,
                //    g.beneficiaryl,
                //    g.canceldate,
                //    g.EndDate,
                //    g.note,
                //    g.organizartionName,
                //    g.package,
                //    g.PolicyNumber,
                //    g.PolicyStatus
                //     ,
                //    g.PolicyVersionId
                //     ,
                //    g.StartDate

                //}).Select(s => s.FirstOrDefault())
                //     .ToList();

                for (int i = 0; i < policyTemp.Count; i++)
                {
                    PolicyInfoDto policyInfo = new PolicyInfoDto();

                    policyInfo.partner         = Mapper.Map <PartnerDto>(policyTemp[i].beneficiaryl);
                    policyInfo.partner.insurer = policyTemp[i].organizartionName;

                    policyInfo.services = GetPolicyLimits(policyTemp[i].PolicyVersionId);

                    policyInfo.policy = new PolicyV2Dto()
                    {
                        note            = policyTemp[i].note,
                        canceldate      = policyTemp[i].canceldate,
                        num             = policyTemp[i].PolicyNumber,
                        startdate       = policyTemp[i].StartDate,
                        enddate         = policyTemp[i].EndDate,
                        package         = policyTemp[i].package,
                        status          = policyTemp[i].PolicyStatus,
                        policyVersionId = policyTemp[i].PolicyVersionId
                    };

                    data.maindata.Add(policyInfo);
                }



                return(data);
            }
        }