Beispiel #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");
        }
        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);
        }
Beispiel #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);
        }
        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);
        }
Beispiel #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;
     }
 }
Beispiel #6
0
 internal VaultKeepViewModel Create(VaultKeepViewModel newvVaultKeep)
 {
     return(_repo.Create(newvVaultKeep));
 }