/// <summary> /// Opens the new watchlist. /// </summary> /// <param name="userId">The unique identifier of the user who owns the watchlist.</param> /// <param name="name">The watchlist name.</param> /// <param name="symbols">The initial symbols on the watchlist.</param> /// <returns>The identifier of the newly created watchlist.</returns> public Guid CreateWatchlist(Guid userId, string name, IEnumerable <string> symbols) { Validate.NotEmpty(userId, nameof(userId)); Validate.NotNullOrWhitespace(name, nameof(name)); Watchlist watchlist = Watchlist.CreateNew(userId, name, symbols); _watchlistRepository.Save(watchlist); return(watchlist.Id); }
public IActionResult New(int petId) { try{ string UserId = _userManager.GetUserId(HttpContext.User); Watchlist watchlist = new Watchlist(); watchlist.PetId = petId; watchlist.UserId = UserId; if (!_repository.IsWatchlistExists(petId, UserId)) { _repository.Save(watchlist); } else { return(Content("Already exists in your watchlists")); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { throw ex; } }