public ActionResult <bool> Put([FromRoute] int id, [FromBody] RequestMarker marker) { try{ if (ModelState.IsValid) { if (marker.Id == null) { marker.Id = id; } var markerData = _mapper.Map <RequestMarker, Marker>(marker); bool status = _dataAccess.UpdateMarker(markerData); return(Ok(new GenericResponse() { Data = marker.Id, Message = "Location updated successfully" })); } else { return(ReturnStatus400("Input data is not valid")); } } catch (Exception ex) //todo: Do proper logging of the exception { ResponseBase responseData = _mapResponseProcessor.ProcessMapErrors(ex); if (responseData != null) { return(ReturnStatus400ByResponseBase(responseData)); } return(ReturnStatus500("Opps! Server error, contact API owner")); } }
public void MarkRequest() { var requestMarker = GetCurrentRequestMarker(); if (requestMarker != null) { requestMarker.CountIncrement(); } else { requestMarker = new RequestMarker(); PutCurrentRequestMarker2Cache(requestMarker, _Config.SameIpIntervalRequestInSeconds); } }
private void PutCurrentRequestMarker2Cache(RequestMarker requestMarker, int absoluteExpirationInCacheInSeconds) { if (requestMarker == null) { throw (new ArgumentNullException("requestMarker")); } _Config.HttpContext.Cache.Remove(CACHE_KEY); _Config.HttpContext.Cache.Add ( CACHE_KEY, requestMarker, null, requestMarker.DateTime.AddSeconds(Convert.ToDouble(absoluteExpirationInCacheInSeconds)), TimeSpan.Zero, CacheItemPriority.NotRemovable, null ); }
public ActionResult <ResponseMarkerModel> Post([FromBody] RequestMarker marker) { //marker.lang = lang; try{ if (ModelState.IsValid) { var markerData = _mapper.Map <RequestMarker, Marker>(marker); int?markerId = _dataAccess.InsertMarker(markerData); return(Ok(new GenericResponse() { Data = markerId, Message = "Location saved successfully" })); } else { if (marker.Id != null) { return(ReturnStatus400("Please check input")); } else { return(ReturnStatus400("Input data is not valid")); } } } catch (Exception ex) //todo: Do proper logging of the exception { ResponseBase responseData = _mapResponseProcessor.ProcessMapErrors(ex); if (responseData != null) { return(StatusCode(StatusCodes.Status400BadRequest, responseData)); } return(ReturnStatus500("Opps! Server error, contact API owner")); } }
private void BannedRequest(RequestMarker requestMarker) { requestMarker.Banned(); PutCurrentRequestMarker2Cache(requestMarker, _Config.SameIpBannedIntervalInSeconds + 1); }