public IActionResult GetSet(string setNumber) { var setToReturn = _setInfoRepository.GetSetDetail(setNumber); if (setToReturn == null) { _logger.LogInformation($"Set Number {setNumber} not found"); return(NotFound()); } var results = Mapper.Map <SetDto>(setToReturn); return(Ok(setToReturn)); }
public IActionResult ImportRebrickableSet(string setNumber) { //get set from rebrickable //confirm that it does not exist in our database //create new set in our db (mapping) //include all parts if (_setInfoRepository.SetExists(setNumber)) { return(BadRequest($"setNumber {setNumber} already exists")); } var sourceSet = _rebrickableInfoRepository.GetSet(setNumber); if (sourceSet == null) { if (!setNumber.EndsWith("-1")) { setNumber = setNumber + "-1"; sourceSet = _rebrickableInfoRepository.GetSet(setNumber); } if (sourceSet == null) { return(NotFound()); } } var s = new Entities.Set() { SetNumber = sourceSet.SetNumber, Name = sourceSet.Name, ThemeId = sourceSet.ThemeId, Theme = GetThemePath(sourceSet.ThemeId), SetImageUrl = sourceSet.SetImageUrl.AbsoluteUri }; var sourceSetParts = _rebrickableInfoRepository.GetSetParts(setNumber); foreach (var sourceSetPart in sourceSetParts) { var sp = new Entities.SetPart() { Id = sourceSetPart.Id, PartNumber = sourceSetPart.Part.PartNum, Name = sourceSetPart.Part.Name, PartUrl = sourceSetPart.Part.PartUrl, PartImageUrl = sourceSetPart.Part.PartImgUrl, Color = sourceSetPart.Color.Name, QuantityNeeded = sourceSetPart.Quantity, ElementId = sourceSetPart.ElementId, CategoryId = sourceSetPart.Part.PartCatId }; s.Parts.Add(sp); } _setInfoRepository.AddSet(s); _setInfoRepository.Save(); var setToReturn = _setInfoRepository.GetSetDetail(setNumber); var results = Mapper.Map <SetDto>(setToReturn); return(Ok(setToReturn)); }