public Result <IList <InsuranceCompany> > GetAll()
        {
            var result = new Result <IList <InsuranceCompany> >();
            InsuranceCompanyService bankService = new InsuranceCompanyService();

            var lstClient = bankService.Get();

            result.Value     = (IList <InsuranceCompany>)lstClient;
            result.IsSuccess = true;
            return(result);
        }
Esempio n. 2
0
        public InsuranceCompanyServiceTest()
        {
            policyService           = Substitute.For <IPolicyService>();
            insuranceCompanyService = new InsuranceCompanyService(policyService);

            // set availableRisks
            List <Risk> availableRisks = new List <Risk>()
            {
                RiskBuilder.Build("Risk 1", 100),
                RiskBuilder.Build("Risk 2", 10)
            };

            insuranceCompanyService.AvailableRisks = availableRisks;
        }
        public Result Delete(InsuranceCompany insuranceCompany)
        {
            var result = new Result();

            try
            {
                InsuranceCompanyService bankService = new InsuranceCompanyService();
                bankService.Delete(insuranceCompany);
                result.IsSuccess = true;
            }
            catch (Exception exception)
            {
                result.IsSuccess     = false;
                result.ExceptionInfo = exception;
            }
            return(result);
        }
        //[AuthenticateFilter(Role = "AddUser")]
        public async Task <IActionResult> AddUser(UserModel model)
        {
            DateTime        dtBeforeCalling = DateTime.Now;
            AdminRequestLog log             = new AdminRequestLog();

            log.UserIP    = Utilities.GetUserIPAddress();
            log.ServerIP  = Utilities.GetInternalServerIP();
            log.UserAgent = Utilities.GetUserAgent();
            log.PageName  = "Create-User";
            log.PageURL   = "/admin/create-user";
            // log.ApiURL = Utilities.GetCurrentURL(httpContext);
            log.MethodName = "AddUser";
            log.UserID     = User.GetUserId();
            log.UserName   = User.GetUserName();
            var output = new Output <UserModel>();

            try
            {
                output = model.IsValid <UserModel, UserModel>();
                if (!ModelState.IsValid)
                {
                    log.ServiceResponseTimeInSeconds = DateTime.Now.Subtract(dtBeforeCalling).TotalSeconds;
                    log.ServiceResponseTimeInSeconds = DateTime.Now.Subtract(dtBeforeCalling).TotalSeconds;
                    log.ErrorDescription             = output.ErrorDescription;
                    log.ErrorCode = (int)output.ErrorCode;
                    LogService.AddAdminRequestLogs(log);
                    return(Ok(output));
                }

                foreach (var company in model.Companies)
                {
                    if (!InsuranceCompanyService.CheckCompanyExist(company))
                    {
                        output.ErrorCode                 = Output <UserModel> .ErrorCodes.CompanyNotExist;
                        output.ErrorDescription          = ResourcesHepler.GetMessage("CompanyNotExists", model.Language);;
                        log.ServiceResponseTimeInSeconds = DateTime.Now.Subtract(dtBeforeCalling).TotalSeconds;
                        log.ServiceResponseTimeInSeconds = DateTime.Now.Subtract(dtBeforeCalling).TotalSeconds;
                        log.ErrorDescription             = output.ErrorDescription;
                        log.ErrorCode = (int)output.ErrorCode;
                        LogService.AddAdminRequestLogs(log);
                        return(Ok(output));
                    }
                }
                var user = new ApplicationUser
                {
                    Email       = model.Email,
                    UserName    = model.UserName,
                    PhoneNumber = model.PhoneNumber
                };
                var result = await userManager.CreateAsync(user, model.Userpassword);

                output = result.IsValidResult <UserModel>(model.Language, out string errorKey);
                if (output.ErrorCode == Output <UserModel> .ErrorCodes.Success)
                {
                    output.ErrorDescription          = ResourcesHepler.GetMessage("Success", model.Language);
                    log.ServiceResponseTimeInSeconds = DateTime.Now.Subtract(dtBeforeCalling).TotalSeconds;
                    log.ErrorDescription             = output.ErrorDescription;
                    log.ErrorCode = (int)output.ErrorCode;
                    LogService.AddAdminRequestLogs(log);
                    return(Ok(output));
                }
                output.ErrorDescription          = ResourcesHepler.GetMessage("ServerError", model.Language);
                log.ServiceResponseTimeInSeconds = DateTime.Now.Subtract(dtBeforeCalling).TotalSeconds;
                log.ErrorDescription             = "Failed to create user";
                log.ErrorCode = (int)output.ErrorCode;
                LogService.AddAdminRequestLogs(log);
                return(Ok(output));
            }
            catch (Exception ex)
            {
                output.ErrorCode                 = Output <UserModel> .ErrorCodes.ServerException;
                output.ErrorDescription          = ResourcesHepler.GetMessage("ServerError", model.Language);
                log.ServiceResponseTimeInSeconds = DateTime.Now.Subtract(dtBeforeCalling).TotalSeconds;
                log.ErrorDescription             = ex.ToString();
                log.ErrorCode = (int)output.ErrorCode;
                LogService.AddAdminRequestLogs(log);
                return(Ok(output));
            }
        }