public ActionResult <Keep> Post([FromBody] Keep val) { val.UserId = HttpContext.User.Identity.Name; if (val.UserId != null) { Keep result = _repo.AddKeep(val); return(Created("/api/keeps" + result.Id, result)); } return(Unauthorized("Login to create keep!!!!")); }
internal VaultKeep Create(VaultKeep newVaultKeep, string userId) { Vault vault = _vrepo.Get(newVaultKeep.VaultId); Keep keep = _krepo.GetOne(newVaultKeep.KeepId); if (keep == null) { throw new Exception("invalid keep id"); } if (vault == null) { throw new Exception("invalid vault id"); } if (vault.CreatorId != userId) { throw new Exception("you are not the owner of this vault"); } int id = _repo.Create(newVaultKeep); newVaultKeep.Id = id; keep.Keeps = keep.Keeps + 1; _krepo.AddKeep(keep); return(newVaultKeep); }