示例#1
0
 public static bool ValidateInsurance(Insurrance insurrance)
 {
     if (insurrance.ContractNumber == null || insurrance.ContractNumber == "" || insurrance.TimeIn == null || insurrance.TimeOut == null)
     {
         return(false);
     }
     return(true);
 }
        public int DeleteInsurrance(int id)
        {
            using (var dataContext = new InsurranceDBModel())
            {
                var        insurranceRepository = new Repository <Insurrance>(dataContext);
                Insurrance insurrance           = insurranceRepository.Find(id);

                return(insurranceRepository.Delete(insurrance));
            }
        }
 public DTO adapt(DBO dbo)
 {
     InsurranceLogic.EFDataBaseConecction.Insurrance insurranceDBO = (InsurranceLogic.EFDataBaseConecction.Insurrance)dbo;
     InsurranceLogic.Model.Insurrance insurranceDTO = new Insurrance();
     insurranceDTO.Nombre               = insurranceDBO.Nombre;
     insurranceDTO.descripcion          = insurranceDBO.descripcion;
     insurranceDTO.id                   = insurranceDBO.id;
     insurranceDTO.inicioVigenciaPoliza = insurranceDBO.inicioVigenciaPoliza;
     insurranceDTO.periodoCobertura     = insurranceDBO.periodoCobertura;
     insurranceDTO.cobertura            = insurranceDBO.cobertura;
     insurranceDTO.precioPoliza         = insurranceDBO.precioPoliza;
     insurranceDTO.tipoRiesgo           = insurranceDBO.tipoRiesgo;
     insurranceDTO.TiposCubrimiento     = new TiposCubrimiento();
     insurranceDTO.TiposCubrimiento.id  = insurranceDBO.idTipoCubrimiento;
     return(insurranceDTO);
 }
示例#4
0
        public IActionResult update([FromBody] Insurrance insurrance)
        {
            if (insurrance == null)
            {
                return(new ObjectResult(new Message {
                    status = StatusMessage.error.ToString(), message = MyMessage.INVALID_DATA
                }));
            }
            var customer = _context.customers.Where(c => c.CustomerID == insurrance.CustomerID).FirstOrDefault();
            var product  = _context.products.Where(p => p.ProductID == insurrance.ProductID).FirstOrDefault();
            var emplyee  = _context.employees.Where(e => e.EmployeeID == insurrance.EmployeeID).FirstOrDefault();

            if (product == null || customer == null || emplyee == null)
            {
                return(new ObjectResult(new Message {
                    status = StatusMessage.error.ToString(), message = MyMessage.ERROR_INVALID_PRODUCT_OR_CUS
                }));
            }
            var a = _context.insurrances.Where(c => c.InsurranceID == insurrance.InsurranceID || c.ContractNumber == insurrance.ContractNumber).FirstOrDefault();

            if (a == null)
            {
                return(new ObjectResult(new Message {
                    status = StatusMessage.error.ToString(), message = MyMessage.ERROR_NOT_FOUND_INS
                }));
            }
            else
            {
                a.BanhchCode           = insurrance.BanhchCode;
                a.CoverageRate         = insurrance.CoverageRate;
                a.CustomerID           = insurrance.CustomerID;
                a.description          = insurrance.description;
                a.DurationOfInsurrance = insurrance.DurationOfInsurrance;
                a.ProductID            = insurrance.ProductID;
                a.EmployeeID           = insurrance.EmployeeID;
                a.FormOfPayment        = insurrance.FormOfPayment;
                a.StatusContract       = insurrance.StatusContract;
                a.StatusFee            = insurrance.StatusFee;
                a.TimeIn  = insurrance.TimeIn;
                a.TimeOut = insurrance.TimeOut;
                _context.Update(a);
                _context.SaveChanges();
                return(new ObjectResult(new Message {
                    status = StatusMessage.success.ToString(), message = MyMessage.SUCCESS_UPDATE_INS
                }));
            }
        }
示例#5
0
        public IActionResult add([FromBody] Insurrance insurrance)
        {
            if (insurrance == null)
            {
                return(new ObjectResult(new Message {
                    status = StatusMessage.error.ToString(), message = MyMessage.INVALID_DATA
                }));
            }
            else
            {
                if (!Validator.ValidateInsurance(insurrance))
                {
                    return(new ObjectResult(new Message {
                        status = StatusMessage.error.ToString(), message = MyMessage.INVALID_DATA
                    }));
                }
                var customer = _context.customers.Where(c => c.CustomerID == insurrance.CustomerID).FirstOrDefault();
                var product  = _context.products.Where(p => p.ProductID == insurrance.ProductID).FirstOrDefault();
                var emplyee  = _context.employees.Where(e => e.EmployeeID == insurrance.EmployeeID).FirstOrDefault();
                if (product == null || customer == null || emplyee == null)
                {
                    return(new ObjectResult(new Message {
                        status = StatusMessage.error.ToString(), message = MyMessage.ERROR_INVALID_PRODUCT_OR_CUS
                    }));
                }
                else
                {
                    var a = _context.insurrances.Where(c => c.ContractNumber == insurrance.ContractNumber || c.InsurranceID == insurrance.InsurranceID).FirstOrDefault();
                    if (a == null)
                    {
                        insurrance.InsurranceID = 0;
                        _context.insurrances.Add(insurrance);
                        _context.SaveChanges();

                        return(new ObjectResult(new Message {
                            status = StatusMessage.success.ToString(), message = MyMessage.ADD_SUCCESS
                        }));
                    }
                    else
                    {
                        return(new ObjectResult(new Message {
                            status = StatusMessage.error.ToString(), message = MyMessage.ERROR_ADD_INS
                        }));
                    }
                }
            }
        }
 public string Put(int id, [FromBody] Insurrance elemento)
 {
     if (elemento.periodoCobertura < 1)
     {
         return("Periodo cobertura no puede ser menor a 1");
     }
     if (elemento.tipoRiesgo > 4 || elemento.tipoRiesgo < 1)
     {
         return("Tipo de riesgo erroneo");
     }
     if (elemento.tipoRiesgo == 4 && elemento.cobertura > 50)
     {
         return("Con riesgo alto, no puede tener cobertura mayor al 50%");
     }
     InsurranceLogic.LogicFacade.Instance.UpdateInsurrance(id, elemento.Nombre, elemento.descripcion,
                                                           elemento.inicioVigenciaPoliza, elemento.cobertura, elemento.periodoCobertura, elemento.precioPoliza, elemento.tipoRiesgo, elemento.TiposCubrimiento);
     return("Ok");
 }
        public Insurrance AddInsurrance(string Nombre, string descripcion, int idTipoCubrimiento,
                                        DateTime inicioVigenciaPoliza, float cobertura, int periodoCobertura, decimal precioPoliza, int tipoRiesgo)
        {
            using (var dataContext = new InsurranceDBModel())
            {
                var        insurranceRepository = new Repository <Insurrance>(dataContext);
                Insurrance insurrance           = new Insurrance();
                insurrance.Nombre               = Nombre;
                insurrance.descripcion          = descripcion;
                insurrance.idTipoCubrimiento    = idTipoCubrimiento;
                insurrance.cobertura            = cobertura;
                insurrance.inicioVigenciaPoliza = inicioVigenciaPoliza;
                insurrance.periodoCobertura     = periodoCobertura;
                insurrance.precioPoliza         = precioPoliza;
                insurrance.tipoRiesgo           = tipoRiesgo;

                return(insurranceRepository.Create(insurrance));
            }
        }
示例#8
0
        public void TestMethod3()
        {
            // Arrange
            InsurranceController controller = new InsurranceController();

            Insurrance insurrance = new Insurrance();

            insurrance.cobertura            = 51;
            insurrance.descripcion          = "Cobertura no apta para tipo riesgo";
            insurrance.tipoRiesgo           = 5;
            insurrance.Nombre               = "Test";
            insurrance.inicioVigenciaPoliza = DateTime.Now;
            insurrance.periodoCobertura     = 12;
            insurrance.precioPoliza         = 1200000;
            // Act
            string result = controller.Post(insurrance);

            // Assert
            Assert.AreEqual("Tipo de riesgo erroneo", result);
        }
示例#9
0
        public static void Initialize(UserContext context)
        {
            context.Database.EnsureCreated();
            if (context.insurrances.Any())
            {
                return;   // DB has been seeded
            }
            var users = new User[]
            {
                new User {
                    username = "******", password = "******", fullname = "Nguyễn Minh Hiếu", role = "admin"
                },
                new User {
                    username = "******", password = "******", fullname = "Nguyễn Minh Hiếu", role = "staff"
                },
                new User {
                    username = "******", password = "******", fullname = "Nguyễn Minh Hiếu", role = "em"
                }
            };

            foreach (var i in users)
            {
                context.users.Add(i);
            }
            context.SaveChanges();
            var products = new Product[] {
                new Product {
                    ProductName = "sản phấm số 1", ProductCode = "A001", ProductStatus = "1", Money = "100000", PayMethod = 1
                },
                new Product {
                    ProductName = "sản phấm số 2", ProductCode = "A002", ProductStatus = "1", Money = "100000", PayMethod = 1
                },
                new Product {
                    ProductName = "sản phấm số 3", ProductCode = "A003", ProductStatus = "1", Money = "100000", PayMethod = 1
                },
                new Product {
                    ProductName = "sản phấm số 4", ProductCode = "A004", ProductStatus = "1", Money = "100000", PayMethod = 1
                }
            };

            foreach (var i in products)
            {
                context.products.Add(i);
            }
            context.SaveChanges();

            var employees = new Employee[]
            {
                new Employee {
                    EmployeeNumber = "E2014001", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                },
                new Employee {
                    EmployeeNumber = "E2014002", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                },
                new Employee {
                    EmployeeNumber = "E2014003", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                },
                new Employee {
                    EmployeeNumber = "E2015001", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                },
                new Employee {
                    EmployeeNumber = "E2016001", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                },
                new Employee {
                    EmployeeNumber = "E2017045", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                },
                new Employee {
                    EmployeeNumber = "E2011034", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                },
                new Employee {
                    EmployeeNumber = "E2012032", Dob = DateTime.Parse("1996-12-18"), Address = "Hà Nội", Email = "abc@123", Fullname = "Nguyễn Minh A", PhoneNumber = "0123456798"
                }
            };

            foreach (var i in employees)
            {
                context.employees.Add(i);
            }
            context.SaveChanges();


            var agencies = new Agency[]
            {
                new Agency {
                    BanhchCode = "MBHQ1", ConsultantName = "Nguyễn Minh Hiếu", Address = "Hà Nội", Name = "chi nhánh Cầu Giấy 1", Phonenumber = "04123432",
                },
                new Agency {
                    BanhchCode = "MBHQ2", ConsultantName = "Nguyễn Minh Hiếu", Address = "Hà Nội", Name = "chi nhánh Cầu Giấy 2", Phonenumber = "04123432"
                },
                new Agency {
                    BanhchCode = "MBHQ3", ConsultantName = "Nguyễn Minh Hiếu", Address = "Hà Nội", Name = "chi nhánh Cầu Giấy 3", Phonenumber = "04123432"
                },
                new Agency {
                    BanhchCode = "MBHQ4", ConsultantName = "Nguyễn Minh Hiếu", Address = "Hà Nội", Name = "chi nhánh Cầu Giấy 4", Phonenumber = "04123432"
                }
            };

            foreach (var i in agencies)
            {
                context.agencies.Add(i);
            }
            context.SaveChanges();

            var customers = new Customer[]
            {
                new Customer {
                    Cmtnd = "135847874", Dob = DateTime.Now, Phonenumber = "0978963262", Sex = "Nam", FullName = "Nguyễn Văn A", CustomerCode = "A2017001"
                },
                new Customer {
                    Cmtnd = "1358478741", Dob = DateTime.Now, Phonenumber = "0978963262", Sex = "Nam", FullName = "Nguyễn Văn B", CustomerCode = "A2017001"
                },
                new Customer {
                    Cmtnd = "1358478742", Dob = DateTime.Now, Phonenumber = "0978963262", Sex = "Nam", FullName = "Nguyễn Văn C", CustomerCode = "A2017001"
                },
                new Customer {
                    Cmtnd = "1358478743", Dob = DateTime.Now, Phonenumber = "0978963262", Sex = "Nam", FullName = "Nguyễn Văn D", CustomerCode = "A2017001"
                }
            };

            foreach (var i in customers)
            {
                context.customers.Add(i);
            }
            context.SaveChanges();
            var insurrances = new Insurrance[]
            {
                new Insurrance {
                    BanhchCode = "MBHQ1", ContractNumber = "A001", CoverageRate = "10%", EmployeeID = 1, description = "Các sản phẩm bảo hiểm được thiết kế riêng biệt theo từng nhu cầu khách hàng trong từng giai đoạn cuộc đời. Không chỉ hướng tới mục tiêu bảo vệ Quý khách và những người thân yêu trước rủi ro của cuộc sống, các kế hoạch bảo hiểm còn giúp Quý khách thực hiện được các kế hoạch tài chính cho cá nhân và gia đình, đảm bảo nguồn tài chính vững vàng cho tương lai.",
                    Create_at  = DateTime.Now, Create_by = "hieunm", CustomerID = 1, DurationOfInsurrance = 3, ProductID = 1, FormOfPayment = 1, StatusContract = "Đang hiệu lực", StatusFee = "Đã thanh toán"
                },
                new Insurrance {
                    BanhchCode = "MBHQ1", ContractNumber = "A002", CoverageRate = "10%", EmployeeID = 2, description = "Các sản phẩm bảo hiểm được thiết kế riêng biệt theo từng nhu cầu khách hàng trong từng giai đoạn cuộc đời. Không chỉ hướng tới mục tiêu bảo vệ Quý khách và những người thân yêu trước rủi ro của cuộc sống, các kế hoạch bảo hiểm còn giúp Quý khách thực hiện được các kế hoạch tài chính cho cá nhân và gia đình, đảm bảo nguồn tài chính vững vàng cho tương lai.",
                    Create_at  = DateTime.Now, Create_by = "hieunm", CustomerID = 1, DurationOfInsurrance = 3, ProductID = 1, FormOfPayment = 1, StatusContract = "Đang hiệu lực", StatusFee = "Đã thanh toán"
                },
                new Insurrance {
                    BanhchCode = "MBHQ1", ContractNumber = "A003", CoverageRate = "10%", EmployeeID = 3, description = "Các sản phẩm bảo hiểm được thiết kế riêng biệt theo từng nhu cầu khách hàng trong từng giai đoạn cuộc đời. Không chỉ hướng tới mục tiêu bảo vệ Quý khách và những người thân yêu trước rủi ro của cuộc sống, các kế hoạch bảo hiểm còn giúp Quý khách thực hiện được các kế hoạch tài chính cho cá nhân và gia đình, đảm bảo nguồn tài chính vững vàng cho tương lai.",
                    Create_at  = DateTime.Now, Create_by = "hieunm", CustomerID = 1, DurationOfInsurrance = 3, ProductID = 1, FormOfPayment = 1, StatusContract = "Đang hiệu lực", StatusFee = "Đã thanh toán"
                },
                new Insurrance {
                    BanhchCode = "MBHQ1", ContractNumber = "A004", CoverageRate = "10%", EmployeeID = 4, description = "Các sản phẩm bảo hiểm được thiết kế riêng biệt theo từng nhu cầu khách hàng trong từng giai đoạn cuộc đời. Không chỉ hướng tới mục tiêu bảo vệ Quý khách và những người thân yêu trước rủi ro của cuộc sống, các kế hoạch bảo hiểm còn giúp Quý khách thực hiện được các kế hoạch tài chính cho cá nhân và gia đình, đảm bảo nguồn tài chính vững vàng cho tương lai.",
                    Create_at  = DateTime.Now, Create_by = "hieunm", CustomerID = 1, DurationOfInsurrance = 3, ProductID = 1, FormOfPayment = 1, StatusContract = "Đang hiệu lực", StatusFee = "Đã thanh toán"
                },
                new Insurrance {
                    BanhchCode = "MBHQ1", ContractNumber = "A005", CoverageRate = "10%", EmployeeID = 5, description = "Các sản phẩm bảo hiểm được thiết kế riêng biệt theo từng nhu cầu khách hàng trong từng giai đoạn cuộc đời. Không chỉ hướng tới mục tiêu bảo vệ Quý khách và những người thân yêu trước rủi ro của cuộc sống, các kế hoạch bảo hiểm còn giúp Quý khách thực hiện được các kế hoạch tài chính cho cá nhân và gia đình, đảm bảo nguồn tài chính vững vàng cho tương lai.",
                    Create_at  = DateTime.Now, Create_by = "hieunm", CustomerID = 1, DurationOfInsurrance = 3, ProductID = 1, FormOfPayment = 1, StatusContract = "Đang hiệu lực", StatusFee = "Đã thanh toán"
                }
            };

            foreach (var i in insurrances)
            {
                context.insurrances.Add(i);
            }
            context.SaveChanges();

            context.SaveChanges();
            var payments = new Payment[]
            {
                new Payment {
                    amountPayment = 100, customerCode = "A2017001", insurranceId = 1, createAt = DateTime.Now
                }
            };

            foreach (var i in payments)
            {
                context.payments.Add(i);
            }
            context.SaveChanges();
        }