private void UpdateProductSellers(string[] selectedSellers, Product productToUpdate)
        {
            if (selectedSellers == null)
            {
                productToUpdate.SellerProducts = new List <SellerProduct>();
                return;
            }

            var selectedSellersHS = new HashSet <string>(selectedSellers);
            var productSellers    = new HashSet <int>
                                        (productToUpdate.SellerProducts.Select(c => c.Seller.Id));

            foreach (var seller in _context.Sellers)
            {
                if (selectedSellersHS.Contains(seller.Id.ToString()))
                {
                    if (!productSellers.Contains(seller.Id))
                    {
                        productToUpdate.SellerProducts.Add(new SellerProduct {
                            ProductId = productToUpdate.Id, SellerId = seller.Id
                        });
                    }
                }
                else
                {
                    if (productSellers.Contains(seller.Id))
                    {
                        SellerProduct sellerToRemove = productToUpdate.SellerProducts.FirstOrDefault(i => i.SellerId == seller.Id);
                        _context.Remove(sellerToRemove);
                    }
                }
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Delete(ApiTokenDto dto)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound("The specified user could not be found."));
            }

            if (dto == null)
            {
                return(BadRequest());
            }
            var token = await _context.ApiTokens.SingleOrDefaultAsync(t => t.UserId == user.Id && t.Id == dto.Id);

            if (token == null)
            {
                return(NotFound());
            }

            _context.Remove(token);
            await _context.SaveChangesAsync();

            return(new OkResult());
        }
        public async Task Unregister(string route, int?organisation)
        {
            var assignment =
                _context.SrnAuthAssignments.SingleOrDefaultAsync(a =>
                                                                 a.Route == route && a.OrganisationId == organisation);

            if (assignment == null)
            {
                return;
            }

            _context.Remove(assignment);
            await _context.SaveChangesAsync();
        }
 public void Delete(User user, CancellationToken cancellationToken)
 {
     _identityContext.Remove(user);
 }