示例#1
0
        public void CreateVehicle(VehicleDTO vehicleDto, int companyId)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var query = vehicleListQuery;
                query.ClearSortCriterias();
                query.Filter = new VehicleFilter {
                    LicencePlate = vehicleDto.LicencePlate
                };
                query.AddSortCriteria("LicencePlate", SortDirection.Ascending);
                query.Skip = 0;
                if (query.Execute().SingleOrDefault() != null)
                {
                    throw new ArgumentException("Vehicle service - CreateVehicle(...) vehicle with this licence plate already exists");
                }
                var vehicle = Mapper.Map <Vehicle>(vehicleDto);

                var company = companyRepository.GetById(companyId);
                if (company == null)
                {
                    throw new NullReferenceException("Vehicle service - CreateVehicle(...) company cant be null");
                }
                vehicle.Company = company;
                vehicle.Seats   = new List <Seat>();
                for (int i = 1; i <= vehicleDto.SeatCount; i++)
                {
                    var newSeat = CreateSeat(vehicle, i);
                    vehicle.Seats.Add(newSeat);
                    seatRepository.Insert(newSeat);
                }

                vehicleRepository.Insert(vehicle);
                uow.Commit();
            }
        }
        public string registerSeat([FromBody] Seat value)
        {
            SeatRepository employeeRepository = new SeatRepository();
            Task <int>     count = employeeRepository.Insert(value);

            if (count.Result > 0)
            {
                return("Data saved sucessfully");
            }
            else
            {
                return("Data  not saved sucessfully");
            }
        }