コード例 #1
0
        public async Task <IActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            var user = await _userManager.FindByIdAsync(id);

            if (user == null)
            {
                return(NotFound());
            }
            return(PartialView(user));
        }
コード例 #2
0
        public IActionResult AddUserToRestaurant([FromQuery(Name = "id")] int id, [FromQuery(Name = "userId")] string userId)
        {
            _requestLogService.SaveRequest(User.Identity.GetUserId(), "POST", "api/v1/restaurants/addUserToRestaurant", "AddUserToRestaurant");
            var restaurant = _restaurantService.GetRestaurantById(id);
            var user       = _userManager.FindByIdAsync(userId);

            if (restaurant == null || user == null)
            {
                return(NotFound());
            }
            if (!IsAuthorized(restaurant))
            {
                return(StatusCode(403, "You have to be logged in as one of the restaurant users to add new users to restaurant."));
            }
            var users   = _restaurantService.GetRestaurantUsersById(restaurant.RestaurantId);
            var userIds = new ArrayList();

            users.ForEach(u => userIds.Add(u.UserId));
            if (userIds.Contains(userId))
            {
                return(BadRequest("Provided user is already user of this restaurant."));
            }

            _restaurantService.AddUserToRestaurant(id, userId);
            return(StatusCode(201));
        }
コード例 #3
0
        public async Task <Object> GetUserProfile()
        {
            try
            {
                string userId = User.Claims.First(c => c.Type == "UserID").Value;

                if (userId == "" || userId == null)
                {
                    return(BadRequest("You must log in to use this service"));
                }


                var user = await _userManager.FindByIdAsync(userId);

                var cart = await _context.Carts.FirstOrDefaultAsync(x => x.UserId == userId);

                return(new
                {
                    user.UserName,
                    user.Email,
                    user.Id,
                    cart.CartId
                });
            }
            catch (Exception)
            {
                return(BadRequest("You must log in to use this service"));
            }
        }
コード例 #4
0
        public void SendJobApplicationEmail(JobApplication jobApplication, Microsoft.AspNetCore.Identity.UserManager <ApplicationUser> userManager, string webRootPath)
        {
            var             getJob      = new JobManager(context, userManager).GetJob(webRootPath, jobApplication.JobId);
            var             user        = userManager.FindByIdAsync(getJob.Data.Organisation.UserId);
            var             userDetails = new UserProfileManager(context, userManager).GetUserDetailsByUserId(jobApplication.UserId, webRootPath);
            string          body        = userDetails.Data.FirstName + " " + userDetails.Data.LastName + " has shown interest in the job for " + getJob.Data.Name + " you advertised on JobSearch. to view more details on the application click this link." + Configuration["FrontEndUrl:BaseUrl"] + Configuration["FrontEndUrl:ForgotPasswordUrlPreffix"] + jobApplication.Id;
            IdentityMessage message     = new IdentityMessage {
                Body = body, Destination = user.Result.Email, Subject = "Job Application"
            };

            new EmailService().SendEmailAsync(message);
        }
コード例 #5
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordModel changePasswordModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user = await userManager.FindByIdAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var result = await userManager.ChangePasswordAsync(
                user,
                changePasswordModel.OldPassword,
                changePasswordModel.NewPassword);

            return(Ok(new { success = result.Succeeded, message = result.Errors }));
        }
コード例 #6
0
ファイル: ReviewController.cs プロジェクト: surmannr/Webshop
        public async Task <ActionResult> Post([FromBody] ReviewDto newReview)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(newReview.UserId);

                var product = await _context.Products.FirstOrDefaultAsync(c => c.ProductID == newReview.ProductId);

                Review review = _mapper.Map <Review>(newReview);


                if (product != null)
                {
                    review.ProductId = product.ProductID;
                    product.Reviews.Add(review);
                }
                else
                {
                    return(BadRequest("Couldnt find the product"));
                }

                if (review.Stars > 5 || review.Stars < 0)
                {
                    return(BadRequest("Invalid star amount"));
                }

                _context.Reviews.Add(review);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(418, ex.Message));
            }
        }
コード例 #7
0
        private async Task <string> GetUserName(Guid userId)
        {
            var user = await _userManager.FindByIdAsync(userId.ToString());

            return(user.ToString());
        }