public ActionResult Create(BlueprintJsonModel model) { var user = _store.GetApiKeyOwner(GetApiKey()); if (user == null) return Http403("Unknown API key."); //check if model is valid if (!IsModelValid()) return Http400("Invalid blueprint data."); // map data from the view model to the db model var blueprint = new Blueprint { Name = model.Name, Description = model.Description, JsonData = model.JsonData, VectorPreview = model.PreviewData, Changed = DateTime.Now }; // put the blueprint to the db _blueprints.CreateBlueprintForUser(user.UserId, blueprint); _blueprints.SaveChanges(); // add id of the blueprint model.id = blueprint.BlueprintId; // return with id the same model return Json(model); }
public ActionResult Update(int id, BlueprintJsonModel model) { var user = _store.GetApiKeyOwner(GetApiKey()); if (user == null) return Http403("Unknown API key."); var blueprint = _blueprints.GetBlueprintById(id); if (blueprint == null) return Http404("Blueprint not found."); // updating model isn't allowed for this api key if (user.UserId != blueprint.UserId) return Http403("This model can't be updated with this API key."); blueprint.Name = model.Name; blueprint.Description = model.Description; blueprint.JsonData = model.JsonData; blueprint.VectorPreview = model.PreviewData; blueprint.Changed = DateTime.Now; _blueprints.SaveChanges(); return Http200(); }
public ActionResult Read(int id) { var blueprint = _blueprints.GetBlueprintById(id); if (blueprint == null) return Http404("Blueprint not found."); var viewModel = new BlueprintJsonModel { id = id, Name = blueprint.Name, Description = blueprint.Description, JsonData = blueprint.JsonData, PreviewData = blueprint.VectorPreview }; return Json(viewModel, JsonRequestBehavior.AllowGet); }