public LandmarkModel GetLandmark(int id, string imageFolderPath) { using (LandmarkRepository repo = new LandmarkRepository()) { var landmark = repo.Read(id); var data = new LandmarkModel(landmark); data.FLargeUrl = Helper.ToBase64String(imageFolderPath, landmark.FLargeUrl); data.FThumbnailUrl = Helper.ToBase64String(imageFolderPath, landmark.FThumbnailUrl); return(data); } }
public IActionResult GetLandmarksByCreatorID(int cratedUserId) { string errorString = null; try { LandmarkModel LandmarkMethods = new LandmarkModel(); List <Landmark> obj = LandmarkMethods.GetAllLandmarksByCreatorId(cratedUserId, out errorString); return(new JsonResult(obj)); } catch (Exception e) { return(BadRequest(e + "\n" + errorString)); } }
public IActionResult GetAllLandmarks() { string errorString = null; try { LandmarkModel landmarkModel = new LandmarkModel(); List <Landmark> obj = landmarkModel.GetAllLandmarks(out errorString); return(new JsonResult(obj)); } catch (Exception e) { return(BadRequest(e + "\n\n Exception FROM DB \n" + errorString)); } }
public async Task <IActionResult> setLandmark([ModelBinder(BinderType = typeof(JsonModelBinder))] Landmark newLandmark, IList <IFormFile> files) { string errorString = null; try { newLandmark.CreatedByUserId = Int32.Parse(User.Claims.FirstOrDefault(x => x.Type.Equals("UserId")).Value); LandmarkModel LandmarkModel = new LandmarkModel(); OrganizationModel orgModel = new OrganizationModel(); newLandmark.LandmarkId = LandmarkModel.AddNewLandmark(newLandmark, out errorString); await new FileHelper().FilesAsync(newLandmark, files, true); return(new JsonResult(newLandmark.LandmarkId)); } catch (Exception e) { return(BadRequest(e + "\n" + errorString)); } }
public IActionResult UpdateLandmark([FromBody] Landmark newLandmark) { string errorString = null; try { LandmarkModel landmarkModel = new LandmarkModel(); if (newLandmark.LandmarkId == 0) { return(BadRequest("please enter 'LandmarkID'")); } newLandmark.UpdatedByUserId = Int32.Parse(User.Claims.FirstOrDefault(x => x.Type.Equals("UserId")).Value); newLandmark.LandmarkId = landmarkModel.UpdateLandmarkId(newLandmark, out errorString); return(new JsonResult(newLandmark)); } catch (Exception e) { return(BadRequest(e + "\n" + errorString)); } }
public IActionResult GetLandmark(int id) { string errorString = null; try { LandmarkModel landmarkModel = new LandmarkModel(); Landmark obj = landmarkModel.GetLandmarkById(id, out errorString); if (obj != null && errorString == null) { return(new JsonResult(obj)); } else { return(BadRequest("cant find")); } } catch (Exception e) { return(Ok(e + "\n" + errorString)); } }
public IActionResult CreateLandmark(int cityId, [FromBody] LandmarkModelCreation landmark) { var city = CityDataStore.Current.Cities .FirstOrDefault(c => c.Id == cityId); if (city == null) { return(NotFound()); } //Posting ID # var maxLandmarkId = CityDataStore.Current.Cities .SelectMany(c => c.Landmarks) .Max(p => p.Id); //Creating new Landmark data var inputNewLandmark = new LandmarkModel() { Id = ++maxLandmarkId, Name = landmark.Name, Description = landmark.Description }; //Adding Landmark to City city.Landmarks.Add(inputNewLandmark); return(CreatedAtRoute( "GetLandmark", new { cityId = cityId, id = inputNewLandmark.Id, inputNewLandmark })); }