public void UpdateGroup(VehicleGroupViewModel vehicleGroup, int userId)
        {
            using (var trans = _unitOfWork.BeginTransaction())
            {
                try
                {
                    // insert new group
                    VehicleGroup entity = new VehicleGroup();
                    Map(vehicleGroup, entity);
                    _vehicleGroupRepository.AttachNavigation<Customer>(entity.Customer);
                    entity.Id = 0;
                    entity.CreateUserId = entity.ModifyUserId = userId;
                    entity.CreateDate = entity.ModifyDate = DateTime.Now;
                    entity.ModifyUserId = entity.ModifyUserId = userId;
                    entity.ModifyDate = entity.ModifyDate = DateTime.Now;
                    entity.Status = (int)DbConstant.DefaultDataStatus.Active;
                    VehicleGroup insertedVehicleGroup = _vehicleGroupRepository.Add(entity);
                    _unitOfWork.SaveChanges();

                    // update last group status to deleted
                    _vehicleGroupRepository.AttachNavigation<Customer>(entity.Customer);
                    entity.Id = vehicleGroup.Id;
                    entity.Status = (int)DbConstant.DefaultDataStatus.Deleted;
                    _vehicleGroupRepository.Update(entity);
                    _unitOfWork.SaveChanges();

                    //update all vehicle to new group
                    foreach (var vehicle in _vehicleRepository.GetMany(v => v.VehicleGroupId == vehicleGroup.Id && v.Status == (int) DbConstant.DefaultDataStatus.Active))
                    {
                        _vehicleRepository.AttachNavigation<Customer>(vehicle.Customer);
                        _vehicleRepository.AttachNavigation<Brand>(vehicle.Brand);
                        _vehicleRepository.AttachNavigation<BrawijayaWorkshop.Database.Entities.Type>(vehicle.Type);
                        _vehicleRepository.AttachNavigation<VehicleGroup>(vehicle.VehicleGroup);
                        vehicle.VehicleGroup = insertedVehicleGroup;
                        vehicle.ModifyUserId = entity.ModifyUserId = userId;
                        vehicle.ModifyDate = entity.ModifyDate = DateTime.Now;

                        _vehicleRepository.Update(vehicle);
                        _unitOfWork.SaveChanges();
                    }

                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
        }
        public void DeleteVehicleGroup(VehicleGroupViewModel selectedGroup, int userId)
        {
            using (var trans = _unitOfWork.BeginTransaction())
            {
                try
                {
                    VehicleGroup entity = _vehicleGroupRepository.GetById(selectedGroup.Id);
                    Map(selectedGroup, entity);
                    _vehicleGroupRepository.AttachNavigation<Customer>(entity.Customer);
                    entity.Status = (int)BrawijayaWorkshop.Constant.DbConstant.DefaultDataStatus.Deleted;
                    entity.ModifyUserId = userId;
                    entity.ModifyDate = DateTime.Now;
                    _vehicleGroupRepository.Update(entity);
                    _unitOfWork.SaveChanges();

                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
        }
        public void InsertNewGroup(VehicleGroupViewModel vehicleGroup, int userId)
        {
            using (var trans = _unitOfWork.BeginTransaction())
            {
                try
                {
                    VehicleGroup entity = new VehicleGroup();
                    Map(vehicleGroup, entity);
                    _vehicleGroupRepository.AttachNavigation<Customer>(entity.Customer);
                    entity.CreateUserId = entity.ModifyUserId = userId;
                    entity.CreateDate = entity.ModifyDate = DateTime.Now;
                    entity.Status = (int)DbConstant.DefaultDataStatus.Active;
                    _vehicleGroupRepository.Add(entity);
                    _unitOfWork.SaveChanges();

                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
        }