Пример #1
0
        private void LoadModel()
        {
            _file = new FileInfo(Application.StartupPath + @"\\Vehicle.xlsx");

            using (var package = new ExcelPackage(_file))
            {
                var workbook = package.Workbook;

                using (var tx = NHibernateSessionManager.GetLocalSession().BeginTransaction())
                {
                    var ws     = workbook.Worksheets[@"Model"];
                    var brands = _vehicleBrandRepository.GetAll();

                    for (var i = 1; i < ws.Dimension.End.Row + 1; i++)
                    {
                        VehicleSize size;

                        Enum.TryParse(ws.Cells[i, 3].Value.ToString(), out size);

                        var newModel = new VehicleModel(
                            ws.Cells[i, 1].Value.ToString(),
                            ws.Cells[i, 2].Value.ToString(),
                            brands.FirstOrDefault(x => x.Code == ws.Cells[i, 3].Value.ToString()),
                            size,
                            VehicleType.CAR
                            );

                        _vehicleModelRepository.Insert(newModel);
                    }

                    tx.Commit();
                }
            }
        }
Пример #2
0
        public VehicleModel Save(string code, string name, VehicleBrand brand, VehicleSize size, VehicleType type)
        {
            VehicleModel newModel = null;
            var          session  = NHibernateSessionManager.GetLocalSession();

            session.DoTransactional(sess =>
            {
                newModel = _modelRepo.Insert(new VehicleModel(code, name, brand, size, type));
            });

            return(newModel);
        }
Пример #3
0
 public async Task <int> InsertVehicleModel(IVehicleModelDomainModel entity)
 {
     return(await _vehicleModelRepository.Insert(entity));
 }