public async Task <int> CreateRelation(int visitorId, int productId) { RelationProducts relation = new RelationProducts { ProductId = productId, Visitor = visitorId }; await _context.Relations.AddAsync(relation); return(await _context.SaveChangesAsync()); }
public async Task <int> AddToCart(int userId, int productId) { RelationProducts relation = new RelationProducts { ProductId = productId, Visitor = userId }; await _context.Relations.AddAsync(relation); return(await _context.SaveChangesAsync()); }
public int DeleteProductFromCart(int userId, int productId) { RelationProducts relation = _context.Relations.FirstOrDefault(x => x.Visitor == userId && x.ProductId == productId); if (relation != null) { _context.Remove(relation); return(_context.SaveChanges()); } else { return(0); } }