public async Task ChangeSeenStateByAdmin(Guid orderId)
        {
            if (_identityManager.CurrentIdentityHasOneOfRoles(new List <string>()
            {
                PreDefRoles.PrincipalAdministrator, PreDefRoles.Administrator
            }))
            {
                var order = await _orderDataService.Query.FirstAsync(x => x.Id == orderId);

                if (order.SeenByAdmin)
                {
                    return;
                }
                order.SeenByAdmin = true;
                _unitOfWork.Update(order);
                await _unitOfWork.SaveChangesAsync();
            }
        }
Esempio n. 2
0
        public async Task <AddCustomerReviewResponse> AddCustomerReview(AddCostomerReviewRequest model)
        {
            var sitePolicies = _settingService.GetSetting <WebSitePolicies>();
            var product      = _productDataService.Query.First(x => x.Id == model.Model.ProductId);

            if (!_accessManager.HasAccess(product, AccessPremission.See))
            {
                _securityLogger.LogDangeriousAddAttemp(model.RequestOwner, model.Model);
                return(new AddCustomerReviewResponse {
                    Access = ResponseAccess.Deny
                });
            }

            if (!product.AllowCustomerReviews)
            {
                return new AddCustomerReviewResponse
                       {
                           Access  = ResponseAccess.Deny,
                           Message = "err"
                       }
            }
            ;

            var doesBied = DoesUserBuiedAndOrderCompeleted(product);

            if (sitePolicies.EShopReviewPolicy == EShopReviewPolicy.BuiedUsers && !doesBied)
            {
                return new AddCustomerReviewResponse
                       {
                           Access  = ResponseAccess.Deny,
                           Message = "err"
                       }
            }
            ;

            if (sitePolicies.EShopReviewPolicy == EShopReviewPolicy.BuiedUsersInRoles && !doesBied ||
                !_identityManager.CurrentIdentityHasOneOfRoles(
                    sitePolicies.EShopReviewPolicyUserInRoles.Select(x => x.Name)))
            {
                return new AddCustomerReviewResponse
                       {
                           Access  = ResponseAccess.Deny,
                           Message = "err"
                       }
            }
            ;

            if (sitePolicies.EShopReviewPolicy == EShopReviewPolicy.UsersInRoles &&
                !_identityManager.CurrentIdentityHasOneOfRoles(
                    sitePolicies.EShopReviewPolicyUserInRoles.Select(x => x.Name)))
            {
                return new AddCustomerReviewResponse
                       {
                           Access  = ResponseAccess.Deny,
                           Message = "err"
                       }
            }
            ;
            if (sitePolicies.EShopReviewPolicy == EShopReviewPolicy.UsersInRoles &&
                !_identityManager.CurrentIdentityHasOneOfRoles(
                    sitePolicies.EShopReviewPolicyUserInRoles.Select(x => x.Name)))
            {
                return new AddCustomerReviewResponse
                       {
                           Access  = ResponseAccess.Deny,
                           Message = "err"
                       }
            }
            ;


            model.Model.Id = Guid.Empty;
            var review = Mapper.Map <ProductReview>(model.Model);

            review.UserId     = _workContext.CurrentUser.Id;
            review.IsApproved = false;
            product.ProductReviews.Add(review);
            await _unitOfWork.SaveChangesAsync();

            return(new AddCustomerReviewResponse
            {
                Access = ResponseAccess.Granted,
                Review = Mapper.Map <ReviewViewModel>(review),
                Product = product
            });
        }