public void CanGetById() { moqKeepsRepository.Setup(repo => repo.GetById(1)).Returns( new Keep { Id = 1 } ); var result = keepsService.GetById(1); moqKeepsRepository.Verify(repo => repo.GetById(1)); Assert.AreEqual(1, result.Id); }
public ActionResult <Keep> Get(int id) { try { var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; if (userId == null) { return(Ok(_ks.GetById(id))); } return(Ok(_ks.GetById(id, userId))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <VaultKeep> Post([FromBody] VaultKeep newVaultKeep) { try { var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; newVaultKeep.UserId = userId; int updateId = newVaultKeep.KeepId; int vaultId = newVaultKeep.VaultId; Keep update = _ks.GetById(updateId); _vks.IncrementKeepCount(update, vaultId, userId); return(Ok(_vks.Create(newVaultKeep))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> GetById(int keepId) { try { return(Ok(_service.GetById(keepId))); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <IEnumerable <Keep> > Get(int id) { try { return(Ok(_ks.GetById(id))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> GetbyId(int id) { try { return(Ok(_kService.GetById(id))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> Get(int id) { try { return(Ok(_kserv.GetById(id))); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> Get(int id) { try { return(Ok(_serve.GetById(id))); } catch (Exception error) { return(BadRequest(error.Message)); } }
public ActionResult <Keep> Get(int Id) { try { string userId = findUserInfo(); return(Ok(_ks.GetById(Id, userId))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <IEnumerable <ViewModelKeep> > > GetById(int id) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); return(Ok(_ks.GetById(userInfo?.Id, id))); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <IEnumerable <Keep> > > GetById(int id) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); var something = Ok(_serv.GetById(userInfo?.Id, id)); return(something); } catch (Exception error) { return(BadRequest(error.Message)); } }
public ActionResult <Keep> GetById(int id) { try { var res = _ks.GetById(id); if (res.IsPrivate) { Claim user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); if ((user == null) || (user.Value != res.UserId)) { throw new Exception("You do not have access to this keep."); } return(Ok(_ks.GetById(id))); } else { return(Ok(_ks.GetById(id))); } } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public ActionResult <Keep> GetById(int id) { try { var claim = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); string userId = ""; if (claim != null) { userId = claim.Value; } return(Ok(_ks.GetById(id))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> GetById(int id) { try { Claim user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); if (user == null) { return(Ok(_ks.GetByIdPublic(id))); } return(Ok(_ks.GetById(user.Value, id))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public ActionResult <Keep> GetById(int keepId) { try { Keep foundKeep = _ks.GetById(keepId); Claim userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); if (foundKeep.IsPrivate == true && userId.Value != foundKeep.UserId) { return(BadRequest("That keep is private")); } return(Ok(foundKeep)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <IEnumerable <Keep> > Get([FromRoute] int vaultId) { try { string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; IEnumerable <VaultKeeps> vks = _vks.Get(userId, vaultId); List <Keep> keps = new List <Keep>(); foreach (VaultKeeps vk in vks) { keps.Add(_ks.GetById(vk.KeepId, userId)); } return(keps); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> GetById(int id) { try { var creator = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); var userId = ""; if (creator != null) { userId = creator.Value; } var keep = _ks.GetById(id, userId); return(Ok(keep)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <VaultKeep> > Create([FromBody] VaultKeep newVK) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newVK.CreatorId = userInfo.Id; newVK.Creator = userInfo; var keepData = _ks.GetById(newVK.KeepId); keepData.Keeps++; _ks.Edit(keepData); var data = _vs.GetById(userInfo.Id, newVK.VaultId); return(Ok(_vks.Create(newVK, data))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> Get(int id) { try { Keep keep = _ks.GetById(id); if (keep.IsPrivate) { var user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); if (user != null && user.Value == keep.UserId) { return(Ok(keep)); } return(Unauthorized("You don't have access to this Keep")); } return(Ok(keep)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Keep> GetById([FromRoute] int id) { try { string userId; var ctx = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); if (ctx == null) { userId = "null"; } else { userId = ctx.Value; } return(Ok(_ks.GetById(id, userId))); } catch (Exception e) { return(BadRequest(e.Message)); } }