public HttpResponseMessage Get(int version, string id) { HttpResponseMessage message = null; ICriterion criterion = new Criterion(); criterion.AddItem("Id", id); var response = Service.Get <ToDo>(criterion); if (response.IsOkay) { message = Request.GenerateResponse(HttpStatusCode.OK, response.Model); } else { message = Request.GenerateErrorResponse(HttpStatusCode.NotFound, ""); } return(message); }
protected virtual ICriterion Delete(ICriterion criterion, IContext context) { ICriterion result = new Criterion(); //WriteConcernResult writeConcern = Collection.Remove(Query.EQ("_id", new ObjectId(criterion.GetValue<string>("Id")))); WriteConcernResult writeConcern = Collection.Remove(criterion.ToQueryDocument<T>()); //WriteConcernResult writeConcern = Collection.Remove(Query.EQ("_id", new ObjectId(criterion.GetValue<string>("Id")))); if (writeConcern.Ok) { long affected = writeConcern.DocumentsAffected; result.AddItem("documentsAffected", affected); } else { IRequestContext ctx = context as IRequestContext; var message = Exceptions.ComposeDatastoreException<T>(ModelActionOption.Delete, writeConcern.ErrorMessage, null, criterion, context, this.GetType().FullName, "MongoDB"); ctx.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error); } return result; }
protected virtual ICriterion Delete(ICriterion criterion, IContext context) { ICriterion result = new Criterion(); if (Collection != null) { WriteConcernResult writeConcern = Collection.Remove(criterion.ToQueryDocument <T>()); if (writeConcern.Ok) { long affected = writeConcern.DocumentsAffected; result.AddItem("documentsAffected", affected); } else { IRequestContext ctx = context as IRequestContext; var message = Exceptions.ComposeDatastoreException <T>(ModelActionOption.Delete, writeConcern.ErrorMessage, null, criterion, context, this.GetType().FullName, "MongoDB"); ctx.SetError(500, message.ToPublish()); EventWriter.WriteError(message.ToLog(), SeverityType.Error, XFConstants.Category.DataAccess, context.ToDictionary(message.Id)); } } return(result); }