private void InitMockList() { this.mockList = new List <TouristRout>(); TouristRout touristRout = new TouristRout() { ID = Guid.NewGuid(), Title = "青天河", Description = "都是水", OriginalPrice = 1300, Features = "吃喝玩乐", Notes = "注意安全", CreateTime = DateTime.Now, Fees = "住宿费自己掏" }; TouristRout touristRout1 = new TouristRout() { ID = Guid.NewGuid(), Title = "八里沟", Description = "没啥好玩的", Fees = "交通费自理", OriginalPrice = 1250, Notes = "人比较多" }; this.mockList.Add(touristRout); this.mockList.Add(touristRout1); TouristRoutPicture picture = new TouristRoutPicture() { Url = "../images/1.jpg", Destription = "太美丽了", }; }
public void AddTouristRoutePicture(Guid tourisrRouteId, TouristRoutPicture picture) { if (!FakeContext.TouristRout.Any(x => x.ID == tourisrRouteId) || picture == null) { throw new ArgumentNullException(nameof(tourisrRouteId)); } picture.TouristRoutID = tourisrRouteId; FakeContext.TouristRoutPictures.Add(picture); }
public async Task <IActionResult> GetPictureByTouristIDAsync([FromRoute] Guid touristRoutsID, [FromRoute] int id) { TouristRoutPicture picture = await _fakerepository.GetTouistRoutePictureAsync(touristRoutsID, id); if (picture == null) { return(NotFound($"没有找到ID{id}的图片")); } return(Ok(_mapper.Map <TouristRoutPictureDto>(picture))); }
public async Task <IActionResult> DeletePictureAsync([FromRoute] Guid touristRoutsID, [FromRoute] int id) { if (!await _fakerepository.JudgeTouristRouteExistAsync(touristRoutsID)) { return(NotFound($"旅游路线{touristRoutsID}不存在")); } TouristRoutPicture pictureDel = await _fakerepository.GetTouistRoutePictureAsync(touristRoutsID, id); if (pictureDel == null) { return(NotFound($"没有找到ID{id}的图片")); } _fakerepository.DeleteTouristRoutePicture(pictureDel); if (await _fakerepository.SaveAsync()) { return(NoContent()); } else { return(BadRequest()); } }
public async Task <IActionResult> CreateTouristRoutePictureAsync([FromRoute] Guid touristRoutsID, [FromBody] TouristRoutePicturesCreateDto pictureCreateDto) { TouristRoutPicture pictureData = _mapper.Map <TouristRoutPicture>(pictureCreateDto); try { _fakerepository.AddTouristRoutePicture(touristRoutsID, pictureData); } catch (Exception ex) { Console.WriteLine(ex.Message);; return(BadRequest()); } if (await _fakerepository.SaveAsync()) { return(CreatedAtRoute("GetPictureByTouristIDAsync", new { id = pictureData.ID, touristRoutsID = pictureData.TouristRoutID }, _mapper.Map <TouristRoutPictureDto>(pictureData))); } else { return(BadRequest()); } }
public void DeleteTouristRoutePicture(TouristRoutPicture picture) { FakeContext.TouristRoutPictures.Remove(picture); }