예제 #1
0
        internal string Delete(int id, string userId)
        {
            VaultKeepViewModel foundVaultKeep = GetById(id, userId);

            if (_repo.Delete(id, userId))
            {
                return("Deleted!");
            }
            throw new Exception("Invalid id");
        }
예제 #2
0
        internal VaultKeepViewModel Create(VaultKeepViewModel newVaultKeep)
        {
            string sql = @"
        INSERT INTO vaultkeeps
        (vaultId, keepId, userId)
        VALUES
        (@VaultId, @KeepId, @UserId);
        SELECT LAST_INSERT_ID()";

            newVaultKeep.Id = _db.ExecuteScalar <int>(sql, newVaultKeep);
            return(newVaultKeep);
        }
예제 #3
0
        public VaultKeepViewModel GetById(int id, string userId)
        {
            VaultKeepViewModel foundVaultKeep = _repo.GetById(id, userId);

            if (foundVaultKeep == null)
            {
                throw new Exception("Invalid Id");
            }
            if (foundVaultKeep.UserId != userId)
            {
                throw new Exception("This is not yours!");
            }
            return(foundVaultKeep);
        }
예제 #4
0
        internal void Delete(int id, string userId)
        {
            VaultKeepViewModel vkm = _repo.GetById(id);

            if (vkm == null)
            {
                throw new Exception("Invalid vkm");
            }
            if (vkm.CreatorId != userId)
            {
                throw new Exception("Invalid User");
            }
            _repo.Delete(id);
        }
예제 #5
0
 public ActionResult <VaultKeepViewModel> Create([FromBody] VaultKeepViewModel newVaultKeep)
 {
     try
     {
         Claim user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
         if (user == null)
         {
             throw new Exception("Must be logged in.");
         }
         newVaultKeep.UserId = user.Value;
         return(Ok(_vks.Create(newVaultKeep)));
     }
     catch (System.Exception)
     {
         throw;
     }
 }
예제 #6
0
 internal VaultKeepViewModel Create(VaultKeepViewModel newvVaultKeep)
 {
     return(_repo.Create(newvVaultKeep));
 }