public async Task CreateComponentRating(RatingComponentModel ratingComponentModel) { await using (_context = new Sep3DBContext()) { bool exists = await _context.RatingComponent.AnyAsync(r => r.AccountModelUserId == ratingComponentModel.AccountModelUserId && r.ComponentModelId == ratingComponentModel.ComponentModelId); if (exists) { List <RatingComponentModel> list = await _context.RatingComponent .Where(r => r.ComponentModelId == ratingComponentModel.ComponentModelId && r.AccountModelUserId == ratingComponentModel.AccountModelUserId).ToListAsync(); RatingComponentModel rating = list[0]; rating.Score = ratingComponentModel.Score; _context.RatingComponent.Update(rating); await _context.SaveChangesAsync(); } else { Console.WriteLine("rating nu exista "); await _context.RatingComponent.AddAsync(ratingComponentModel); await _context.SaveChangesAsync(); } } }
public async void GiveRating(string content) { RatingComponentModel ratingComponentModel = JsonSerializer.Deserialize <RatingComponentModel>(content); await _ratingRepo.CreateComponentRating(ratingComponentModel); }