コード例 #1
0
        public ActionResult <BikeDTO> GetBikeByName(string name)
        {
            try
            {
                Bike    bike    = _bikeRepository.GetByName(name);
                BikeDTO bikeDTO = new BikeDTO
                {
                    Id    = bike.Id,
                    Name  = bike.Name,
                    Parts = bike.Parts.Select(p =>
                    {
                        PartDTO part = new PartDTO
                        {
                            Id             = p.Part.Id,
                            Name           = p.Part.Name,
                            Description    = p.Part.Description,
                            Functionality  = p.Part.Functionality.ToString(),
                            IsOptional     = p.Part.IsOptional,
                            DominantParts  = p.Part.DominantParts.Select(dp => dp.DominantPart.Name).ToList(),
                            DependantParts = p.Part.DependantParts.Select(dp => dp.DependantPart.Name).ToList(),
                            BikeId         = p.Part.BikeParts.Select(b => b.BikeId).ToList()
                        };

                        return(part);
                    }).OrderBy(p => p.Name).ToList(),
                    Type = bike.Type
                };
                return(Ok(bikeDTO));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
コード例 #2
0
        public ActionResult <Bike> CreateBike(BikeDTO bike)
        {
            Bike newBike = new Bike(bike.Name, bike.BikeBrand, bike.BikeGroupset, bike.BikeType, bike.DiscBrakes, bike.Price);

            _bikeRepository.Add(newBike);
            _bikeRepository.SaveChanges();
            return(CreatedAtAction(nameof(Get), new { id = newBike.ID }, bike));
        }
コード例 #3
0
        public void CreateBike_MaaktEenFiets()
        {
            BikeDTO dto = new BikeDTO();

            dto.Name         = "Venge";
            dto.BikeBrand    = BrandEnum.Specialized;
            dto.BikeGroupset = Groupset.Shimano;
            dto.BikeType     = BikeType.Road_Bike;
            dto.DiscBrakes   = true;
            dto.Price        = 10m;
            var result = _bikesController.CreateBike(dto);

            Assert.IsType <ActionResult <Bike> >(result);
        }
コード例 #4
0
 public static Bike Map(BikeDTO bikeDTO)
 {
     return(new Bike
     {
         ID = bikeDTO.ID,
         BikeType = null,
         BikeTypeID = bikeDTO.BikeTypeID,
         Brand = bikeDTO.Brand,
         FrameMaterial = bikeDTO.FrameMaterial,
         Image = Map(bikeDTO.Image),
         Name = bikeDTO.Name,
         Price = bikeDTO.Price,
         Wheels = bikeDTO.Wheels
     });
 }