示例#1
0
        public void UpdateVehicle(Objects.Vehicle vehicle)
        {
            IUnitOfWork           unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Vehicle> repository = new Repositor <Vehicle>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(vehicle);
                unitOfWork.BeginTransaction();
                var v = repository.Single(c => c.VehicleID == vehicle.ID);
                v.VehicleDescription = String.IsNullOrWhiteSpace(vehicle.Description) ? null : vehicle.Description;
                repository.Update(v);
                unitOfWork.CommitTransaction();
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
示例#2
0
        public Int32 AddVehicle(Objects.Vehicle vehicle)
        {
            IUnitOfWork           unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Vehicle> repository = new Repositor <Vehicle>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(vehicle);
                Vehicle v = new Vehicle();
                v.VehicleNumber       = String.IsNullOrWhiteSpace(vehicle.Number) ? null : vehicle.Number;
                v.VehicleDescription  = String.IsNullOrWhiteSpace(vehicle.Description) ? null : vehicle.Description;
                v.VehicleDetachmentID = vehicle.DetachmentID;
                unitOfWork.BeginTransaction();
                repository.Add(v);
                unitOfWork.CommitTransaction();
                return(v.VehicleID);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }