//List public TriggerListResponse Get(TriggerListRequest request) { TriggerListResponse response = new TriggerListResponse (); response.triggers = new List<TriggerResponse> (); try { foreach (var trigger in triggerscollection.FindAll ()) { Console.WriteLine (JsonSerializer.SerializeToString (trigger)); TriggerResponse triggerresponse = new TriggerResponse (); triggerresponse.Id = trigger.Id; triggerresponse.placeID = trigger.placeID; triggerresponse.dateFrom = trigger.dateFrom; triggerresponse.dateTo = trigger.dateTo; triggerresponse.delay = trigger.delay; triggerresponse.extra = trigger.extra; triggerresponse.Id = trigger.Id; triggerresponse.perUserRunCount = trigger.perUserRunCount; triggerresponse.text = trigger.text; triggerresponse.timeFrom = trigger.timeFrom; triggerresponse.timeTo = trigger.timeTo; triggerresponse.type = trigger.type; response.triggers.Add (triggerresponse); } } catch (Exception ex) { Console.WriteLine (ex.Message); } response.responseStatus = new ResponseStatus (); response.responseStatus.ErrorCode = "200"; response.responseStatus.Message = "SUCCESS"; return response; }
//Create public TriggerResponse Post(TriggerRequest request) { TriggerResponse response = new TriggerResponse (); response.dateFrom = request.dateFrom; response.dateTo = request.dateTo; response.delay = request.delay; response.extra = request.extra; response.perUserRunCount = request.perUserRunCount; response.placeID = request.placeId; response.text = request.text; response.timeFrom = request.timeFrom; response.timeTo = request.timeTo; response.type = request.type; WriteConcernResult result = triggerscollection.Insert (response); response.responseStatus = new ResponseStatus (); if (result.Ok) { response.responseStatus.ErrorCode = "200"; response.responseStatus.Message = "SUCCESS"; } else { response.responseStatus.ErrorCode = "500"; response.responseStatus.Message = "FAILURE"; } return response; }
//Update public TriggerResponse Put(TriggerRequest request) { TriggerResponse response = new TriggerResponse (); var query = Query.EQ ("_id", request.Id); //var trigger = triggerscollection.FindOneAs<TriggerResponse> (query); response.Id = request.Id; response.placeID = request.placeId; response.dateFrom = request.dateFrom; response.dateTo = request.dateTo; response.delay = request.delay; response.extra = request.extra; response.perUserRunCount = request.perUserRunCount; response.text = request.text; response.timeFrom = request.timeFrom; response.timeTo = request.timeTo; response.type = request.type; var update = Update.Replace (response); FindAndModifyResult result = triggerscollection.FindAndModify (query, SortBy.Null, update); response.responseStatus = new ResponseStatus (); if (result.Ok) { response.responseStatus.ErrorCode = "200"; response.responseStatus.Message = "SUCCESS"; } else { response.responseStatus.ErrorCode = "500"; response.responseStatus.Message = "FAILURE"; } return response; }
//Info public TriggerResponse Get(TriggerRequest request) { TriggerResponse response = new TriggerResponse (); var query = Query.EQ ("_id", request.Id); var trigger = triggerscollection.FindOneAs<TriggerResponse> (query); response.dateFrom = trigger.dateFrom; response.dateTo = trigger.dateTo; response.delay = trigger.delay; response.extra = trigger.extra; response.Id = trigger.Id; response.perUserRunCount = trigger.perUserRunCount; response.text = trigger.text; response.timeFrom = trigger.timeFrom; response.timeTo = trigger.timeTo; response.type = trigger.type; response.responseStatus = new ResponseStatus (); response.responseStatus.ErrorCode = "200"; response.responseStatus.Message = "SUCCESS"; return response; }