Пример #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));
            }
        }