internal Keep GetById(int id) { var exists = _repo.GetById(id); if (exists == null) { throw new Exception("Invalid Id"); } exists.Views++; _repo.Edit(exists); return(exists); }
internal Keep Edit(Keep update, string userId) { var exists = _repo.GetById(update.Id); if (exists == null) { throw new Exception("Invalid Id"); } else if (exists.UserId != userId) { throw new Exception("You can't access that"); } _repo.Edit(update); return(update); }
public Keep Edit(Keep editKeep, string userId) { Keep original = GetById(editKeep.Id, userId); if (original.UserId != userId) { throw new Exception("This is not your Keep!"); } original.Name = editKeep.Name.Length > 0 ? editKeep.Name : original.Name; original.Description = editKeep.Description.Length > 0 ? editKeep.Description : original.Description; original.Img = editKeep.Img.Length > 0 ? editKeep.Img : original.Img; if (original.IsPrivate != editKeep.IsPrivate) { original.IsPrivate = editKeep.IsPrivate; } if (original.Keeps != editKeep.Keeps) { original.Keeps = editKeep.Keeps; } if (original.Shares != editKeep.Shares) { original.Shares = editKeep.Shares; } if (original.Views != editKeep.Views) { original.Views = editKeep.Views; } return(_repo.Edit(original)); }
internal Keep Edit(Keep editKeep, string userId) { Keep foundKeep = GetById(editKeep.Id); if (foundKeep.Views < editKeep.Views) { if (_repo.viewKeep(editKeep)) { foundKeep.Views = editKeep.Views; return(foundKeep); } throw new Exception("You can't view that Keep"); } if (foundKeep.Keeps < editKeep.Keeps) { if (_repo.keepKeep(editKeep)) { foundKeep.Keeps = editKeep.Keeps; return(foundKeep); } throw new Exception("You can't keep that Keep"); } if (foundKeep.UserId == userId && _repo.Edit(editKeep, userId)) { return(editKeep); } throw new Exception("Can't edit that keep"); }
internal object Edit(Keep updatedKeep) { Keep found = Get(updatedKeep.Id); if (found.UserId != updatedKeep.UserId) { throw new Exception("you are not the appropriate user"); } else { found.Name = updatedKeep.Name; found.Description = updatedKeep.Description != null ? updatedKeep.Description : found.Description; found.Keeps = updatedKeep.Keeps; return(_repo.Edit(found)); } }
public Keep Edit(Keep updatedKeep) { Keep found = Get(updatedKeep.Id); found.Views = updatedKeep.Views; found.Shares = updatedKeep.Shares; found.Keeps = updatedKeep.Keeps; return(_repo.Edit(found)); }
internal Keep Edit(int id, Keep updatedKeep) { Keep foundKeep = GetById(id); foundKeep.IsPrivate = updatedKeep.IsPrivate; foundKeep.Views = updatedKeep.Views; foundKeep.Keeps = updatedKeep.Keeps; foundKeep.Shares = updatedKeep.Shares; return(_repo.Edit(foundKeep)); }
///////////////////////// internal Keep Edit(Keep update) { var existenceTest = _repo.GetById(update.Id); if (existenceTest == null) { throw new Exception("cant edit bad request or id"); } _repo.Edit(update); return(update); }
internal Keep Edit(Keep keepToUpdate, string userId) { Keep foundKeep = GetById(keepToUpdate.Id); if (foundKeep.UserId != userId) { throw new Exception("UserId does not match."); } else { return(_repo.Edit(keepToUpdate)); } }
//checks the incoming payload against the existing data before passing the payload to the repo internal Keep Edit(Keep payload) { var data = GetById(payload.Id); if (data.CreatorId != payload.CreatorId) { throw new System.Exception("Cant let you do that dave"); } payload.Description = payload.Description != null ? payload.Description : data.Description; payload.Name = payload.Name != null && payload.Name.Length > 3 ? payload.Name : data.Name; payload.Views = payload.Views != 0 && payload.Views < data.Views ? payload.Views : data.Views; return(_repo.Edit(payload)); }
internal Keep Edit(Keep keepToUpdate, string userId) { Keep foundKeep = GetById(keepToUpdate.Id); if (foundKeep.UserId != userId) { throw new Exception("couldnt make private"); } if (_repo.Edit(keepToUpdate, userId)) { return(keepToUpdate); } throw new Exception("not your keep"); }
public Keep Edit(Keep EditedKeep) { Keep original = Get(EditedKeep.Id); if (EditedKeep.UserId != original.UserId) { throw new Exception("That's not your keep"); } original.Name = EditedKeep.Name != null ? EditedKeep.Name : original.Name; original.Description = EditedKeep.Description != null ? EditedKeep.Description : original.Description; original.Img = EditedKeep.Img != null ? EditedKeep.Img : original.Img; _repo.Edit(original); return(original); }