public int Create(VaultKeep newVk) { var kId = newVk.KeepId; string sql1 = "UPDATE keepstable SET keeps = keeps + 1 WHERE @kId = id"; _db.Execute(sql1, new { kId }); string sql = @" INSERT INTO vaultkeeps (vaultId, keepId, creatorId) VALUES (@VaultId, @KeepId, @CreatorId); SELECT LAST_INSERT_ID();"; return(_db.ExecuteScalar <int>(sql, newVk)); }
internal VaultKeep Delete(int id, string userInfoId) { VaultKeep current = _valKeepRepo.GetById(id); if (current == null) { throw new SystemException("Invalid Id... The vaultkeep doesn't exist"); } if (current.CreatorId != userInfoId) { throw new SystemException("You can't delete something you didn't create"); } _valKeepRepo.Delete(id); return(current); }
public async System.Threading.Tasks.Task <ActionResult <string> > Create([FromBody] VaultKeep newVaultKeep) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newVaultKeep.CreatorId = userInfo.Id; VaultKeep vaultKeep = _vks.Create(newVaultKeep, userInfo.Id); return(Ok(vaultKeep)); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
internal VaultKeep Delete(int id, string userInfoId) { VaultKeep data = _vaultKeepRepo.GetById(id); if (data == null) { throw new Exception("Invalid Id"); } if (data.CreatorId != userInfoId) { throw new Exception("Invalid Edit Permissions"); } _vaultKeepRepo.Delete(id); return(data); }
public bool AddVaultKeep(VaultKeep newvaultkeep) { VaultKeep vk = _db.QueryFirstOrDefault <VaultKeep>(@" SELECT * FROM vaultkeeps WHERE vaultId = @VaultId AND keepId = @KeepId;", newvaultkeep); if (vk == null) { int success = _db.Execute(@" INSERT INTO vaultkeeps (VaultId, KeepId, UserId) Values (@VaultId, @KeepId, @UserId)", newvaultkeep); return(success != 0); } return(false); }
internal VaultKeep Create(VaultKeep vaultKeepData) { //throw new NotImplementedException(); string sql = @" UPDATE keeps set keeps = keeps + 1 where id = @KeepId LIMIT 1; INSERT INTO vaultKeeps (userId, vaultId, keepId) VALUES (@UserId, @VaultId, @KeepId); SELECT LAST_INSERT_ID()"; //vaultKeepData.Id = _db.ExecuteScalar<int>(sql, vaultKeepData); vaultKeepData.Id = _db.Execute(sql, vaultKeepData); return(vaultKeepData); }
public int EditVaultKeep(VaultKeep vk) { try { return(_db.Execute($@" DELETE FROM vaultkeeps WHERE keepId = @KeepId AND vaultId = @vaultId", vk)); } catch (Exception ex) { Console.WriteLine(ex); return(0); } }
internal string Delete(int keepId, int vaultId, string userId) { VaultKeep exists = _repo.FindByIds(keepId, vaultId); if (exists == null) { throw new Exception("Invalid Id Combination"); } else if (exists.UserId != userId) { throw new Exception("No tienes estes"); } _repo.Delete(exists.Id); return("Successfully Deleted"); }
internal void Create(VaultKeep newData) { VaultKeep exists = _repo.GetById(newData.Id); if (exists != null) { throw new Exception("Relationship already exists"); } // Pretty sure I don't need this on create... // else if (exists.UserId != newData.UserId) // { // throw new Exception(""); // } _repo.Create(newData); }
public async Task <ActionResult <VaultKeep> > CreateAsync([FromBody] VaultKeep newVK) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newVK.CreatorId = userInfo.Id; VaultKeep createdVK = _service.Create(newVK); return(Ok(createdVK)); } catch (Exception e) { return(BadRequest(e.Message)); } }
// Edit public VaultKeep EditVaultKeep(int id, VaultKeep Vaultkeep) { Vaultkeep.Id = id; var i = _db.Execute(@" UPDATE vaultkeeps SET keepId = @KeepId vaultId = @VaultId WHERE id = @Id ", Vaultkeep); if (i > 0) { return Vaultkeep; } return null; }
public VaultKeep Create(VaultKeep newVaultKeeps) { string sql = @" UPDATE keeps SET keeps = keeps + 1 WHERE id = @keepId; INSERT INTO vaultkeeps (vaultId, keepId, userId) VALUES (@vaultId, @keepId, @userId); SELECT LAST_INSERT_ID();"; newVaultKeeps.Id = _db.ExecuteScalar <int>(sql, newVaultKeeps); return(newVaultKeeps); }
public VaultKeep Create(VaultKeep newVk, string userId) { Vault original = _vr.GetOne(newVk.VaultId); if (original == null) { throw new Exception("Bad Id"); } if (original.CreatorId != userId) { throw new Exception("Not the User : Access Denied"); } newVk.Id = _repo.Create(newVk); return(newVk); }
internal VaultKeep Create(Profile userInfo, VaultKeep newVaultKeep) { newVaultKeep.Id = _repo.Create(newVaultKeep); Vault vault = _vRepo.GetById(newVaultKeep.VaultId); if (vault.CreatorId != userInfo.Id) { throw new Exception("You do not own this Vault"); } Keep data = _kRepo.GetById(newVaultKeep.KeepId); data.Keeps++; _kRepo.Edit(data); return(newVaultKeep); }
internal VaultKeep DeleteOne(int id, string userInfoId) { VaultKeep current = _vkrepo.GetOneById(id); if (current == null) { throw new SystemException("Invalid Id: This vault keep does not exist or the wrong Id was passed in the delete request."); } if (current.CreatorId != userInfoId) { throw new SystemException("You are not the creator of this, therefore you can not delete this relationsip."); } _vkrepo.DeleteOne(id); return(current); }
// [Authorize] public async Task <ActionResult <VaultKeepsController> > Create([FromBody] VaultKeep newVaultKeep) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newVaultKeep.CreatorId = userInfo.Id; VaultKeep created = _vks.Create(newVaultKeep); return(Ok(created)); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
public VaultKeep Create([FromBody] VaultKeep vaultkeep) { vaultkeep.UserId = HttpContext.User.Identity.Name; if (!ModelState.IsValid) { throw new Exception("Invalid Input"); } VaultKeep newVaultKeep = _repo.Create(vaultkeep); if (vaultkeep == null) { throw new Exception("Invalid Input"); } return(newVaultKeep); }
internal string Delete(int vaultId, int keepId, string userId) { VaultKeep exists = _vkr.Find(keepId, vaultId); if (exists == null) { throw new Exception("Can't find it"); } else if (exists.UserId != userId) { throw new Exception("You can't do that"); } _vkr.Delete(exists.Id); return("Successfully deleted"); }
public VaultKeep Post([FromBody] VaultKeep VaultKeep) { var user = HttpContext.User; var id = user.Identity.Name; UserReturnModel activeUser = null; if (id != null) { activeUser = userDb.GetUserById(id); } VaultKeep.UserId = activeUser.Id; return(vaultKeepDb.Add(VaultKeep)); }
public async Task <ActionResult <VaultKeep> > Create([FromBody] VaultKeep vaultKeep) { try { Vault original = _vs.GetOne(vaultKeep.VaultId); Profile userinfo = await HttpContext.GetUserInfoAsync <Profile>(); vaultKeep.CreatorId = userinfo.Id; return(Ok(_vks.Create(vaultKeep))); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
internal object DeleteVaultKeep(int id, string userId) { VaultKeep data = _repo.GetById(id); if (data == null) { throw new Exception("Invalid Id... from vaultkeepsService"); } if (data.CreatorId != userId) { throw new Exception("Access Denied NOT YOURS... from vaultkeepsService"); } _repo.DeleteVaultKeep(id); return("Successfully deleted... from vaultkeepsService"); }
public ActionResult <VaultKeep> CreateVaultKeep([FromBody] VaultKeep newVK) { VaultKeep intermediate = newVK; var id = HttpContext.User.FindFirstValue("Id"); var user = _userRepo.GetUserById(id); if (user != null) { intermediate.UserId = id; return(Ok(_vkRepo.CreateVaultKeep(intermediate))); } return(BadRequest()); }
public bool Delete(VaultKeep vaultkeep) { int success = _db.Execute(@" DELETE FROM vaultkeeps WHERE KeepId = @KeepId AND VaultId = @VaultId; ", new { KeepId = vaultkeep.KeepId, VaultId = vaultkeep.VaultId }); if (success != 1) { return(false); } return(true); }
public bool StoreInVault(VaultKeep vaultKeep) { return(_db.ExecuteScalar <int> (@" INSERT INTO vaultkeeps ( vaultId, keepId, userId ) VALUES ( @VaultId, @KeepId, @UserId ); UPDATE keeps SET keeps = keeps + 1 WHERE id = @KeepId; SELECT ROW_COUNT(); ", vaultKeep) != 0); }
internal VaultKeep Create(VaultKeep newVk) { string sql = @" UPDATE keeps k SET k.keeps = k.keeps +1 WHERE k.id = @keepId; INSERT INTO vaultkeeps (vaultId, keepId, creatorId) VALUES (@VaultId, @KeepId, @CreatorId); SELECT LAST_INSERT_ID();"; int id = _db.ExecuteScalar <int>(sql, newVk); newVk.Id = id; return(newVk); }
public ActionResult <VaultKeep> Post([FromBody] VaultKeep value) { value.UserId = HttpContext.User.FindFirstValue("Id"); VaultKeep addedVaultKeep = _repo.AddKeepToVault(value); try { { return(Ok(_repo.AddKeepToVault(value))); } } catch (Exception e) { return(BadRequest(e)); } }
internal int Create(VaultKeep newVaultKeep) { string sql = @" UPDATE keeps SET keeps = keeps + 1 WHERE id = @KeepId; INSERT INTO vaultkeeps (creatorId, vaultId, keepId) VALUES (@CreatorId, @VaultId, @KeepId); SELECT LAST_INSERT_ID()"; return(_db.ExecuteScalar <int>(sql, newVaultKeep)); }
public async Task <ActionResult <VaultKeep> > CreateVaultKeep([FromBody] VaultKeep newVaultKeep) { try { var userInfo = await HttpContext.GetUserInfoAsync <Account>(); newVaultKeep.CreatorId = userInfo?.Id; VaultKeep vk = _vks.Create(newVaultKeep); _ks.incrementKeeps(vk.KeepId); return(Ok(vk)); } catch (Exception e) { return(BadRequest(e.Message)); } }
//Used when new keep is made or coppied by other user. new vk is made with the current user and the vault of their choice. public int NewVaultKeep(VaultKeep vk) { int outVal = -1; var newVK = _db.ExecuteScalar(@" INSERT INTO vaultkeeps (vaultId,keepId,userId) VALUES (@VaultId, @KeepId, @UserId); SELECT LAST_INSERT_ID()", vk); if (newVK != null) { int.TryParse(newVK.ToString(), out outVal); } ; return(outVal); }
internal int Create(VaultKeep newVaultKeep) { string sql = @" Update keeps SET keeps = keeps + 1 WHERE id = @keepId; INSERT INTO vaultkeeps (keepId, vaultId, userId) VALUES (@KeepId, @VaultId, @UserId); SELECT LAST_INSERT_ID();"; return(_db.ExecuteScalar <int>(sql, newVaultKeep)); }