Beispiel #1
0
        public async Task <JObject> GetExistentLoggedInUserData()
        {
            var Result = new JObject();

            if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                var     dateTime       = ConfigurationManager.AppSettings["DateFormat"];
                var     dateTimeFormat = dateTime != null && (dateTime.Contains("yy") && !dateTime.Contains("yyyy")) ? dateTime.Replace("yy", "yyyy") : dateTime;
                string  username       = System.Web.HttpContext.Current.User.Identity.Name;
                var     loggedUserSsn  = _us.GetUserSsnByUsername(username);
                var     loggedUserData = _iss.GetInsuredBySsnAndCreatedBy(loggedUserSsn, _us.GetUserIdByUsername(username));
                JObject insuredData    = new JObject();
                if (loggedUserData == null)
                {
                    var loggedUser = _us.GetUserDataByUsername(username);
                    insuredData.Add("FirstName", loggedUser.FirstName);
                    insuredData.Add("Name", loggedUser.LastName);
                    insuredData.Add("Address", loggedUser.Address);
                    insuredData.Add("City", loggedUser.City);
                    insuredData.Add("PostalCode", loggedUser.PostalCode);
                    insuredData.Add("Ssn", loggedUser.EMBG);

                    insuredData.Add("DateBirth", loggedUser.DateOfBirth != null ? loggedUser.DateOfBirth.Value.ToString(dateTimeFormat, new CultureInfo("en-US")) : null);
                    insuredData.Add("PassportID", loggedUser.PassportNumber);
                    insuredData.Add("Email", loggedUser.Email);
                    insuredData.Add("PhoneNumber", loggedUser.MobilePhoneNumber);

                    Result.Add("InsuredData", insuredData);

                    Result.Add("response", "Not registered insured");
                    return(Result);
                }
                insuredData.Add("FirstName", loggedUserData.Name);
                insuredData.Add("Name", loggedUserData.Lastname);
                insuredData.Add("Address", loggedUserData.Address);
                insuredData.Add("City", loggedUserData.City);
                insuredData.Add("PostalCode", loggedUserData.Postal_Code);
                insuredData.Add("Ssn", loggedUserData.SSN);

                insuredData.Add("DateBirth", loggedUserData.DateBirth.ToString(dateTimeFormat, new CultureInfo("en-US")));
                insuredData.Add("PassportID", loggedUserData.Passport_Number_IdNumber);
                insuredData.Add("Email", loggedUserData.Email);
                insuredData.Add("PhoneNumber", loggedUserData.Phone_Number);

                Result.Add("InsuredData", insuredData);
            }
            else
            {
                Result.Add("response", "Not authenticated user");
            }

            return(Result);
        }
        public static int SavePolicyFromMobile(AddPolicyMobileViewModel addPolicyMobile,
                                               IPolicyService _ps,
                                               IUserService _us,
                                               IInsuredsService _iss,
                                               IPolicyInsuredService _pis,
                                               IAdditionalChargesService _acs)
        {
            try
            {
                //add policy details
                var username = addPolicyMobile.Username;

                var policy = _ps.Create();
                policy.Policy_Number           = _ps.CreatePolicyNumber();
                policy.Exchange_RateID         = addPolicyMobile.Exchange_RateID;
                policy.CountryID               = addPolicyMobile.CountryID;
                policy.Policy_TypeID           = addPolicyMobile.Policy_TypeID;
                policy.Retaining_RiskID        = addPolicyMobile.Retaining_RiskID;
                policy.Start_Date              = addPolicyMobile.Start_Date;
                policy.End_Date                = addPolicyMobile.End_Date;
                policy.Valid_Days              = addPolicyMobile.Valid_Days;
                policy.Travel_NumberID         = addPolicyMobile.Travel_NumberID;
                policy.Travel_Insurance_TypeID = addPolicyMobile.Travel_Insurance_TypeID;
                policy.Total_Premium           = addPolicyMobile.Total_Premium;
                policy.Created_By              = addPolicyMobile.Created_By;
                policy.Date_Created            = DateTime.UtcNow;
                policy.Payment_Status          = false;

                //add policy holder
                var policyHolder = _iss.GetInsuredBySsnAndCreatedBy(addPolicyMobile.SSN, addPolicyMobile.Created_By);
                if (policyHolder == null)
                {
                    var policyHolderID = SaveInsuredHelper.SaveInsured(_iss, addPolicyMobile.Name,
                                                                       addPolicyMobile.LastName,
                                                                       addPolicyMobile.SSN,
                                                                       addPolicyMobile.Email,
                                                                       addPolicyMobile.DateBirth,
                                                                       addPolicyMobile.Phone_Number,
                                                                       addPolicyMobile.Passport_Number_IdNumber,
                                                                       addPolicyMobile.Address,
                                                                       addPolicyMobile.City,
                                                                       addPolicyMobile.Postal_Code,
                                                                       addPolicyMobile.Created_By);
                    policy.Policy_HolderID = policyHolderID;
                }
                else
                {
                    policy.Policy_HolderID = policyHolder.ID;
                }

                var policyID = _ps.AddPolicy(policy);

                if (addPolicyMobile.Insureds != null)
                {
                    foreach (var insured in addPolicyMobile.Insureds)
                    {
                        var addInsured   = _iss.GetInsuredBySsnAndCreatedBy(insured.SSN, addPolicyMobile.Created_By);
                        var addInsuredID = SaveInsuredHelper.SaveInsured(_iss, insured.Name,
                                                                         insured.Lastname,
                                                                         insured.SSN,
                                                                         insured.Email,
                                                                         insured.DateBirth,
                                                                         insured.Phone_Number,
                                                                         insured.Passport_Number_IdNumber,
                                                                         insured.Address,
                                                                         insured.City,
                                                                         insured.Postal_Code,
                                                                         addPolicyMobile.Created_By);

                        var policyInsured = _pis.Create();
                        policyInsured.InsuredID = addInsuredID;
                        policyInsured.PolicyID  = policyID;
                        _pis.Add(policyInsured);
                    }
                }

                if (addPolicyMobile.Additional_charges != null)
                {
                    foreach (var additionalChargeId in addPolicyMobile.Additional_charges)
                    {
                        var additionalChargeObject = _acs.GetAdditionalChargeById(additionalChargeId);
                        if (additionalChargeObject != null)
                        {
                            var addNewCharge = _acs.Create();
                            addNewCharge.PolicyID            = policyID;
                            addNewCharge.Additional_ChargeID = additionalChargeObject.ID;
                            _acs.AddAdditionalChargesPolicy(addNewCharge);
                        }
                    }
                }
                return(policyID);
            }
            catch (Exception e)
            {
                return(-1);
            }
        }