public async Task <IActionResult> Delete(string id)
        {
            var currentUserId = _helper.GetUserId(User);

            if (!currentUserId.ToString().Equals(id))
            {
                await _userManager.DeleteUser(Guid.Parse(id));

                return(Json(new { success = true }));
            }

            return(Json(new { success = false }));
        }
Пример #2
0
 public IActionResult ChangePhoneNumber()
 {
     ViewData["SmsSent"] = false;
     return(View(new ChangePhoneNumberViewModel()
     {
         UserId = _helper.GetUserId(User)
     }));
 }
Пример #3
0
        public override Task OnConnectedAsync()
        {
            var connectionId = Context.ConnectionId;
            var userId       = _helper.GetUserId(Context.User);

            _userConnectionManager.KeepUserConnection(userId, connectionId);

            return(Task.FromResult(0));
        }
        public IActionResult Index(Guid id)
        {
            var product = _dataManager.ProductRepository.GetEntity(id);

            if (product == null)
            {
                return(Redirect("/error/404"));
            }

            var reviews             = _dataManager.ReviewRepository.GetAllEntities().Where(x => x.Product.Id == id).ToList();
            var currentUserId       = _helper.GetUserId(User);
            var currentUserReview   = reviews.FirstOrDefault(x => x.User.Id == currentUserId);
            var reviewSubmitAllowed = false;

            if (User.Identity.IsAuthenticated)
            {
                var userFinishedOrders = _dataManager.OrderRepository.GetAllEntities()
                                         .Where(x => x.User.Id == currentUserId && x.Finished).ToList();

                foreach (var order in userFinishedOrders)
                {
                    if (order.PurchaseDetails.FirstOrDefault(x => x.Product.Id == id) != null)
                    {
                        reviewSubmitAllowed = true;
                    }
                }
            }

            var viewModel = new ProductViewModel
            {
                ProductId = id,
                Name      = product.Name,
                Desc      = product.Desc,
                Price     = product.Price,
                InStock   = product.InStock,
                ImagePath = product.ImagePath,
                Category  = product.Category,
                CurrentUserReviewExists = currentUserReview != null,
                Rating              = product.Rating,
                RatesCount          = product.RatesCount,
                Reviews             = reviews,
                ReviewSubmitAllowed = reviewSubmitAllowed,
                ReviewId            = currentUserReview?.Id ?? default,
                ReviewTitle         = currentUserReview?.Title ?? "",
                ReviewText          = currentUserReview?.Text ?? "",
                ReviewRating        = currentUserReview?.Rating ?? 5
            };

            if (TempData["errors"] != null)
            {
                var errors = (string[])TempData["errors"];
                foreach (var error in errors)
                {
                    if (error.Contains("title", StringComparison.InvariantCultureIgnoreCase))
                    {
                        ModelState.AddModelError(nameof(viewModel.ReviewTitle), error);
                    }

                    if (error.Contains("text", StringComparison.InvariantCultureIgnoreCase))
                    {
                        ModelState.AddModelError(nameof(viewModel.ReviewText), error);
                    }
                }
            }

            return(View(viewModel));
        }