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 BlueprintSearchResult(string namePattern,string descrPattern,string authorPattern,Blueprint blueprint)
 {
     BlueprintId = blueprint.BlueprintId;
     NameResult = new SearchResult(blueprint.Name,namePattern);
     AuthorResult = new SearchResult(blueprint.User.Username, authorPattern);
     DescriptionResult = new SearchResult(blueprint.Description,descrPattern);
     SearchScore = NameResult.MatchesCount + DescriptionResult.MatchesCount + AuthorResult.MatchesCount;
 }
        /// <summary>
        /// Creates a blueprint in database for the specific user.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="blueprint"></param>
        public void CreateBlueprintForUser(int userId, Blueprint blueprint)
        {
            var user = _userDb.Users.SingleOrDefault(u => u.UserId == userId);
            if (user == null) throw new ArgumentException(String.Format("User with id {0} doesn't exist.",userId));

            blueprint.User = user;
            // save
            _userDb.Blueprints.Add(blueprint); //EFCodeFirst
        }
        public ActionResult Create(Blueprint blueprint)
        {
            if (ModelState.IsValid)
            {
                db.Blueprints.Add(blueprint);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.UserId = new SelectList(db.Users, "UserId", "Username", blueprint.UserId);
            return View(blueprint);
        }
 public ActionResult Create(CreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         var blueprint = new Blueprint
                             {Name = model.Name, Description = model.Description, Changed = DateTime.Now};
         _blueprints.CreateBlueprintForUser(UserInfo.UserId, blueprint);
         _blueprints.SaveChanges();
         return Redirect(String.Format("{0}/#{1}",Url.Action("Index", "Editor"),blueprint.BlueprintId));
     }
     return View(model);
 }
 public ActionResult Edit(Blueprint blueprint)
 {
     if (ModelState.IsValid)
     {
         db.Entry(blueprint).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.UserId = new SelectList(db.Users, "UserId", "Username", blueprint.UserId);
     return View(blueprint);
 }
 /// <summary>
 /// Removes the blueprint from the database.
 /// </summary>
 /// <param name="blueprint">Blueprint to be removed.</param>
 public void RemoveBlueprint(Blueprint blueprint)
 {
     _userDb.Blueprints.Remove(blueprint); //EFCodeFirst
 }