public ActionResult CreateUser()
        {
            ViewBag.Gender = Gender();
            var roles = Roles();

            if (_roleAuthorize.IsUser("Broker manager"))
            {
                roles = GetBrokerManagerRoles();
            }
            ViewBag.Roles = roles;
            return(View());
        }
        public override Task OnConnected()
        {
            var roleAuthorize = new RoleAuthorize();

            _currentUser = HttpContext.Current.User.Identity.Name;
            var lastMessages = new List <LastMessagesDTO>();

            _isAdmin = roleAuthorize.IsUser("Admin");

            if (_isAdmin)
            {
                Groups.Add(Context.ConnectionId, "Admins");
                Groups.Add(Context.ConnectionId, _currentUser);

                Clients.Group(_currentUser).MessageRequest(GetActiveRequests());
                lastMessages = GetLastMessages(_currentUser, true);
            }
            else
            {
                Groups.Add(Context.ConnectionId, _currentUser);
                lastMessages = GetLastMessages(_currentUser, false);
            }
            if (!_currentUser.Equals(String.Empty))
            {
                Clients.Group(_currentUser).ActiveMessages(lastMessages);
            }

            return(base.OnConnected());
        }
        public void SendMessage(MessageDTO message)
        {
            if (message == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(message.From))
            {
                _currentUser = HttpContext.Current?.User?.Identity?.Name;
                if (string.IsNullOrWhiteSpace(_currentUser))
                {
                    return;
                }
                else
                {
                    message.From = _currentUser;
                    RoleAuthorize r = new RoleAuthorize();
                    if (r.IsUser("Admin"))
                    {
                        message.Admin = false;
                    }
                    else
                    {
                        message.Admin = true;
                    }
                }
            }
            Clients.Group(message.To).ReceiveMessage(message);

            SaveMessage(message);
        }
        public JsonResult ShowPolicies(string Prefix)
        {
            RoleAuthorize r = new RoleAuthorize();

            if (r.IsUser("End user"))
            {
                var policies             = _us.GetPoliciesByUsernameToList(System.Web.HttpContext.Current.User.Identity.Name, Prefix);
                var policiesAutoComplete = policies.Select(Mapper.Map <travel_policy, PolicyAutoCompleteViewModel>).ToList();
                return(Json(policiesAutoComplete, JsonRequestBehavior.AllowGet));
            }
            else if (r.IsUser("Admin"))
            {
                var policies             = _ps.GetAllPoliciesByPolicyNumber(Prefix);
                var policiesAutoComplete = policies.Select(Mapper.Map <travel_policy, PolicyAutoCompleteViewModel>).ToList();
                return(Json(policiesAutoComplete, JsonRequestBehavior.AllowGet));
            }

            return(null);
        }
        public override Task OnReconnected()
        {
            var roleAuthorize = new RoleAuthorize();

            if (HttpContext.Current != null)
            {
                _currentUser = HttpContext.Current.User.Identity.Name;
                _isAdmin     = roleAuthorize.IsUser("Admin");
            }
            else
            {
                _isAdmin = false;
            }

            return(base.OnReconnected());
        }
예제 #6
0
        public async Task <JsonResult> Index(Policy policy)
        {
            string username = System.Web.HttpContext.Current.User.Identity.Name;

            ok_setup Last_Entry = _os.GetLast();

            if (Last_Entry.SSNValidationActive == 1)
            {
                ValidationService validatePremium = new ValidationService();

                if (!validatePremium.validateSSN_Advanced(policy.SSN))
                {
                    return(Json(new { isValid = false, status = "error", message = Resource.Error_EMBG_Val_Advanced }));
                }
            }

            if (policy.IsSamePolicyHolderInsured)
            {
                policy.PolicyHolderName        = policy.Name;
                policy.PolicyHolderLastName    = policy.LastName;
                policy.PolicyHolderSSN         = policy.SSN;
                policy.PolicyHolderEmail       = policy.Email;
                policy.PolicyHolderAddress     = policy.Address;
                policy.PolicyHolderBirthDate   = policy.BirthDate;
                policy.PolicyHolderCity        = policy.City;
                policy.PolicyHolderPostalCode  = policy.PostalCode;
                policy.PolicyHolderPhoneNumber = policy.PhoneNumber;
            }
            else
            {
                ModelState.Remove("PolicyHolderName");
                ModelState.Remove("PolicyHolderLastName");
                ModelState.Remove("PolicyHolderEmail");
                ModelState.Remove("PolicyHolderAddress");
                ModelState.Remove("PolicyHolderBirthDate");
                ModelState.Remove("PolicyHolderCity");
                ModelState.Remove("PolicyHolderPostalCode");
                ModelState.Remove("PolicyHolderPhoneNumber");
                ModelState.Remove("PolicyHolderSSN");
            }

            if (ModelState.IsValid && policy != null)
            {
                RatingEngineService ratingEngineService = new RatingEngineService();
                Premium             Premium             = new Premium();
                Premium.PremiumAmount = (int)ratingEngineService.totalPremium(policy);
                if (_roleAuthorize.IsUser("Broker manager", username))
                {
                    if (Premium.PremiumAmount > 10000)
                    {
                        return(Json(new { isValid = false, status = "error", message = "ThePremiumIsExceeded", PremiumAmount = Premium.PremiumAmount }));
                    }
                }
                else if (_roleAuthorize.IsUser("Broker", username))
                {
                    if (Premium.PremiumAmount > 10000)
                    {
                        return(Json(new { isValid = false, status = "error", message = "ThePremiumIsExceeded", PremiumAmount = Premium.PremiumAmount }));
                    }
                }

                return(Json(new { isValid = true, status = "ok", PremiumAmount = Premium.PremiumAmount }));
            }
            else
            {
                return(Json(new { isValid = false, status = "error", message = InsuredTraveling.Resource.EnterAllData }));
            }
        }
        public static int SavePolicy(Policy p,
                                     IPolicyService _ps,
                                     IUserService _us,
                                     IInsuredsService _iss,
                                     IPolicyInsuredService _pis,
                                     IAdditionalChargesService _acs)
        {
            var policy   = _ps.Create();
            var username = "";

            if (p.isMobile)
            {
                username          = p.username;
                policy.Created_By = _us.GetUserIdByUsername(p.username);
            }
            else
            {
                username          = System.Web.HttpContext.Current.User.Identity.Name;
                policy.Created_By = _us.GetUserIdByUsername(username);
            }

            policy.Date_Created            = DateTime.UtcNow;
            policy.Policy_Number           = _ps.CreatePolicyNumber();
            policy.CountryID               = p.CountryID;
            policy.Exchange_RateID         = (p.Exchange_RateID.HasValue) ? p.Exchange_RateID.Value : 1;
            policy.Policy_TypeID           = p.Policy_TypeID;
            policy.Retaining_RiskID        = p.Retaining_RiskID;
            policy.Start_Date              = p.Start_Date;
            policy.End_Date                = p.End_Date;
            policy.Valid_Days              = p.Valid_Days;
            policy.Travel_NumberID         = p.Travel_NumberID;
            policy.Total_Premium           = p.Total_Premium;
            policy.Payment_Status          = false;
            policy.Travel_Insurance_TypeID = p.Travel_Insurance_TypeID;

            RoleAuthorize r = new RoleAuthorize();

            if (p.IsSamePolicyHolderInsured && (p.isMobile || r.IsUser("End user")))
            {
                _us.UpdateSsnById(policy.Created_By, p.SSN);

                var PolicyHolderId = SaveInsuredHelper.SaveInsured(_iss, p.Name, p.LastName, p.SSN, p.Email, p.BirthDate, p.PhoneNumber, p.PassportNumber_ID, p.Address, p.City, p.PostalCode, policy.Created_By);
                policy.Policy_HolderID = PolicyHolderId;
            }
            else if (p.IsSamePolicyHolderInsured && (r.IsUser("Admin") || r.IsUser("Broker") || r.IsUser("Broker manager")))
            {
                if (p.IsExistentPolicyHolder)
                {
                    policy.Policy_HolderID = _iss.GetInsuredBySsn(p.SSN).ID;
                }
                else
                {
                    var PolicyHolderId = SaveInsuredHelper.SaveInsured(_iss, p.PolicyHolderName, p.PolicyHolderLastName, p.PolicyHolderSSN, p.PolicyHolderEmail, p.PolicyHolderBirthDate.Value, p.PolicyHolderPhoneNumber, p.PolicyHolderPassportNumber_ID, p.PolicyHolderAddress, p.PolicyHolderCity, p.PolicyHolderPostalCode, policy.Created_By);
                    policy.Policy_HolderID = PolicyHolderId;
                }
            }

            if (!p.IsSamePolicyHolderInsured)
            {
                var ssn = "";
                if (r.IsUser("Admin") || r.IsUser("Broker") || r.IsUser("Broker manager"))
                {
                    ssn = p.PolicyHolderSSN;
                    var policyHolderId = _iss.GetInsuredIdBySsnAndCreatedBy(ssn, policy.Created_By);
                    if (policyHolderId != -1)
                    {
                        insured updateInsuredData = new insured();

                        policy.Policy_HolderID     = policyHolderId;
                        updateInsuredData.ID       = policyHolderId;
                        updateInsuredData.Name     = p.PolicyHolderName;
                        updateInsuredData.Lastname = p.PolicyHolderLastName;
                        updateInsuredData.SSN      = p.PolicyHolderSSN;

                        updateInsuredData.Email        = p.PolicyHolderEmail;
                        updateInsuredData.DateBirth    = p.PolicyHolderBirthDate ?? DateTime.UtcNow;
                        updateInsuredData.Phone_Number = p.PolicyHolderPhoneNumber;

                        updateInsuredData.Passport_Number_IdNumber = p.PolicyHolderPassportNumber_ID;

                        updateInsuredData.City        = p.PolicyHolderCity;
                        updateInsuredData.Postal_Code = p.PolicyHolderPostalCode;
                        updateInsuredData.Address     = p.PolicyHolderAddress;

                        updateInsuredData.Date_Modified = DateTime.Now;
                        updateInsuredData.Modified_By   = policy.Created_By;

                        _iss.UpdateInsuredData(updateInsuredData);
                    }
                    else
                    {
                        var newInsured = _iss.Create();

                        newInsured.Name     = p.PolicyHolderName;
                        newInsured.Lastname = p.PolicyHolderLastName;
                        newInsured.SSN      = p.PolicyHolderSSN;

                        newInsured.Email        = p.PolicyHolderEmail;
                        newInsured.DateBirth    = p.PolicyHolderBirthDate ?? DateTime.UtcNow;
                        newInsured.Phone_Number = p.PolicyHolderPhoneNumber;

                        newInsured.Passport_Number_IdNumber = p.PolicyHolderPassportNumber_ID;

                        newInsured.City        = p.PolicyHolderCity;
                        newInsured.Postal_Code = p.PolicyHolderPostalCode;
                        newInsured.Address     = p.PolicyHolderAddress;

                        newInsured.Date_Created = DateTime.Now;
                        newInsured.Created_By   = policy.Created_By;
                        try
                        {
                            var Id = _iss.AddInsured(newInsured);
                            policy.Policy_HolderID = Id;
                        }
                        finally { }
                    }
                }
                else if (r.IsUser("End user"))
                {
                    ssn = _us.GetUserSsnByUsername(username);
                    var policyHolderId = _iss.GetInsuredIdBySsnAndCreatedBy(ssn, policy.Created_By);
                    if (policyHolderId != -1)
                    {
                        policy.Policy_HolderID = policyHolderId;
                    }
                    else
                    {
                        var currentEndUser = _us.GetUserDataByUsername(username);
                        var newInsured     = _iss.Create();

                        newInsured.Name     = currentEndUser.FirstName;
                        newInsured.Lastname = currentEndUser.LastName;
                        newInsured.SSN      = currentEndUser.EMBG;

                        newInsured.Email        = currentEndUser.Email;
                        newInsured.DateBirth    = currentEndUser.DateOfBirth.HasValue == true ? currentEndUser.DateOfBirth.Value: DateTime.Now;
                        newInsured.Phone_Number = currentEndUser.PhoneNumber;

                        newInsured.Passport_Number_IdNumber = currentEndUser.PassportNumber;

                        newInsured.City        = currentEndUser.City;
                        newInsured.Postal_Code = currentEndUser.PostalCode;
                        newInsured.Address     = currentEndUser.Address;

                        newInsured.Date_Created = DateTime.Now;
                        newInsured.Created_By   = policy.Created_By;
                        try
                        {
                            var Id = _iss.AddInsured(newInsured);
                            policy.Policy_HolderID = Id;
                        }
                        finally { }
                    }
                }
            }

            var policyID  = _ps.AddPolicy(policy);
            var insuredId = _iss.GetInsuredIdBySsnAndCreatedBy(p.SSN, policy.Created_By);

            if (insuredId != -1)
            {
                // da se update
                var policyInsured = _pis.Create();
                policyInsured.InsuredID = insuredId;
                policyInsured.PolicyID  = policyID;
                _pis.Add(policyInsured);
            }
            else
            {
                var newInsured = _iss.Create();
                newInsured.Date_Created = DateTime.Now;
                newInsured.Created_By   = policy.Created_By;
                newInsured.Name         = p.Name;
                newInsured.Lastname     = p.LastName;
                newInsured.SSN          = p.SSN;

                newInsured.Email        = p.Email;
                newInsured.DateBirth    = p.BirthDate;
                newInsured.Phone_Number = p.PhoneNumber;

                newInsured.Passport_Number_IdNumber = p.PassportNumber_ID;

                newInsured.City        = p.City;
                newInsured.Postal_Code = p.PostalCode;
                newInsured.Address     = p.Address;
                try
                {
                    var            insuredIdNew  = _iss.AddInsured(newInsured);
                    policy_insured policyInsured = new policy_insured();
                    policyInsured.InsuredID = insuredIdNew;
                    policyInsured.PolicyID  = policyID;
                    _pis.Add(policyInsured);
                }
                finally { }
            }

            if (p.isMobile)
            {
                if (p.AdditionalChargeId1 != 1)
                {
                    var addChargeNew = _acs.Create();
                    addChargeNew.PolicyID            = policyID;
                    addChargeNew.Additional_ChargeID = p.AdditionalChargeId1;
                    _acs.AddAdditionalChargesPolicy(addChargeNew);
                }

                if (p.AdditionalChargeId2 != 1)
                {
                    var addChargeNew = _acs.Create();
                    addChargeNew.PolicyID            = policyID;
                    addChargeNew.Additional_ChargeID = p.AdditionalChargeId2;
                    _acs.AddAdditionalChargesPolicy(addChargeNew);
                }
            }
            else
            {
                if (p.additional_charges != null)
                {
                    foreach (additional_charge additionalCharge in p.additional_charges)
                    {
                        if (additionalCharge.ID != 1)
                        {
                            var addChargeNew = _acs.Create();
                            addChargeNew.PolicyID            = policyID;
                            addChargeNew.Additional_ChargeID = additionalCharge.ID;
                            _acs.AddAdditionalChargesPolicy(addChargeNew);
                        }
                    }
                }
            }
            return(policyID);
        }