public void AddFavorite(string username, int eventId) { var u = _context.Users.Include(u => u.Favorites).FirstOrDefault(u => u.UserName.Equals(username)); var e = _context.Events.FirstOrDefault(e => e.Id.Equals(eventId)); if (u == null || e == null) { return; } if (u.Favorites == null) { u.Favorites = new List <UserFavorites>(); } var f = u.Favorites.FirstOrDefault(f => f.EventId.Equals(eventId)); if (f == null) { var uf = new UserFavorites { Event = e, EventId = e.Id, User = u, UserId = u.Id }; u.Favorites.Add(uf); _context.SaveChanges(); } }
public async Task <IActionResult> Edit(int id, [Bind("UserId,ProductId")] UserFavorites userFavorites) { if (id != userFavorites.UserId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(userFavorites); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserFavoritesExists(userFavorites.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", userFavorites.ProductId); ViewData["UserId"] = new SelectList(_context.WebUsers, "UserId", "Address", userFavorites.UserId); return(View(userFavorites)); }
public void addToFavorites(int productid, int userid) { UserFavorites userFavorite = new UserFavorites() { ProductId = productid, UserId = userid }; _Context.UserFavorites.Add(userFavorite); _Context.SaveChanges(); }
public async Task <IActionResult> AddFavorite([FromQuery] int id = 0) { UserFavorites newFave = new UserFavorites() { UserId = User.FindFirstValue(ClaimTypes.NameIdentifier), PokemonId = id }; await _context.UserFavorites.AddAsync(newFave); await _context.SaveChangesAsync(); return(Redirect("/Pokemon/PokemonResults?id=" + id)); }
public async Task <IActionResult> Create([Bind("UserId,ProductId")] UserFavorites userFavorites) { if (ModelState.IsValid) { _context.Add(userFavorites); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", userFavorites.ProductId); ViewData["UserId"] = new SelectList(_context.WebUsers, "UserId", "Address", userFavorites.UserId); return(View(userFavorites)); }
public async Task <IActionResult> RemoveFavorite([FromQuery] int id = 0) { string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); UserFavorites fave = _context.UserFavorites.FirstOrDefault(x => x.UserId.Equals(userId) && x.PokemonId.Equals(id)); if (fave == null) { return(Forbid()); } _context.UserFavorites.Remove(fave); await _context.SaveChangesAsync(); return(Redirect("/Pokemon/PokemonResults?id=" + id)); }
public async Task <ActionResult <UserFavorites> > Post(UserFavorites fav) { var queryable = dataContext.Set <InventoryItem>().Where(x => x.Id == fav.InventoryId); if (queryable.Any()) { dataContext.Add(fav); await dataContext.SaveChangesAsync(); return(Ok(fav)); } else { return(NotFound("The inventory item you tried favoriting does not exist.")); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif GetAppData(); SetupTiles(); UserFavorites.InitAsync().RunAndForget(); Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); // Set the default language rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(Shell), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }
public ActionResult Delete(long establishmentId) { try { UserFavorites userFavorites = _userFavoritesAppService.GetByEstablishment(establishmentId, this.User); if (userFavorites == null) { return(Forbid()); } _userFavoritesAppService.RemoveEntity(userFavorites); return(NoContent()); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult <DTOSimpleUser> AddFavorite([FromBody] DTOId expertId, Guid userId) { var claims = User.Claims; var id = claims.FirstOrDefault(x => x.Type == "id")?.Value; if (id != userId.ToString()) { return(Unauthorized()); } using (var unit = _factory.GetUOF()) { var dbUser = unit.Users.GetEager(userId); var dbExpert = unit.Experts.Get(expertId.Id); if (dbExpert == null) { return(BadRequest(new { message = $"Expert with id: {expertId} does not exist" })); } if (dbUser.Favorites.Any(x => x.ExpertId == expertId.Id)) { return(BadRequest(new { message = $"Favorite with id {expertId.Id}, is already in list" })); } var userFavorite = new UserFavorites { Expert = dbExpert, User = dbUser }; dbUser.Favorites.Add(userFavorite); unit.Complete(); var simpleUser = new DTOSimpleUser(); Mapper.Map(dbUser, simpleUser); return(CreatedAtAction("GetFavorites", simpleUser)); } }
public virtual bool IsFavoritedBy(User user) { ParamIs.NotNull(() => user); return(UserFavorites.Any(a => a.User.Equals(user))); }