コード例 #1
0
        public async Task CreatePostRating(RatingPostModel ratingPostModel)
        {
            await using (_context = new Sep3DBContext())
            {
                bool exists = await _context.RatingPost.AnyAsync(r =>
                                                                 r.AccountModelUserId == ratingPostModel.AccountModelUserId &&
                                                                 r.PostModelId == ratingPostModel.PostModelId);

                if (exists)
                {
                    List <RatingPostModel> list = await _context.RatingPost
                                                  .Where(r => r.PostModelId == ratingPostModel.PostModelId &&
                                                         r.AccountModelUserId == ratingPostModel.AccountModelUserId).ToListAsync();

                    RatingPostModel rating = list[0];
                    rating.Score = ratingPostModel.Score;
                    _context.RatingPost.Update(rating);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    Console.WriteLine("rating nu exista  ");
                    await _context.RatingPost.AddAsync(ratingPostModel);

                    await _context.SaveChangesAsync();
                }
            }
        }
コード例 #2
0
        public ActionResult RateProduct(RatingPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index, new { @productId = model.ProductId }));
            }

            var customer = HttpContext.GetCustomer();

            if (!customer.IsRegistered && !AppLogic.AppConfigBool("RatingsCanBeDoneByAnons"))
            {
                return(RedirectToAction(ActionNames.Index, new { @productId = model.ProductId }));
            }

            var sqlParams = new SqlParameter[]
            {
                new SqlParameter("@isFilthy", Ratings.StringHasBadWords(model.Comment)),
                new SqlParameter("@rating", model.Rating),
                new SqlParameter("@hasComment", !string.IsNullOrEmpty(model.Comment)),
                new SqlParameter("@comments", model.Comment ?? string.Empty),
                new SqlParameter("@productId", model.ProductId),
                new SqlParameter("@customerId", customer.CustomerID),
                new SqlParameter("@storeId", AppLogic.StoreID()),
            };

            if (model.Editing)
            {
                var editSql = @"UPDATE Rating 
								SET IsFilthy = @isFilthy, 
									Rating = @rating, 
									HasComment = @hasComment, 
									Comments = @comments 
								WHERE ProductID = @productId 
									AND CustomerID = @customerId 
									AND StoreID = @storeId"                                    ;

                DB.ExecuteSQL(editSql, sqlParams);
            }
            else
            {
                var insertSql = @"INSERT INTO Rating (ProductID, IsFilthy, CustomerID, CreatedOn, Rating, HasComment, StoreID, Comments)
									VALUES(@productId, @isFilthy, @customerId, GETDATE(), @rating, @hasComment, @storeId, @comments)"                                    ;

                DB.ExecuteSQL(insertSql, sqlParams);
            }

            return(View(ActionNames.Index, BuildRatingViewModel(model.ProductId, true)));
        }
コード例 #3
0
 public async void GiveRating(string content)
 {
     RatingPostModel ratingPostModel = JsonSerializer.Deserialize <RatingPostModel>(content);
     await _ratingRepo.CreatePostRating(ratingPostModel);
 }