예제 #1
0
        public async Task <IActionResult> CreateRecipe(RecipeForCreateDto recipeForCreateDto)
        {
            //Get values from token
            //   var identity = HttpContext.User.Identity as ClaimsIdentity;
            //  if (identity != null)
            //     {
            //          IEnumerable<Claim> claims = identity.Claims;
            //     }
            if (User.FindFirst(ClaimTypes.NameIdentifier) == null)
            {
                throw new Exception("Cant find user in token");
            }


            recipeForCreateDto.UserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);


            var recipe = _mapper.Map <Recipe>(recipeForCreateDto);

            _repo.Add(recipe);

            if (await _repo.SaveAll())
            {
                return(StatusCode(201));
            }

            throw new Exception($"the creation for recipe fail");
        }
예제 #2
0
        public async Task <IActionResult> AddReview(ReviewForCreateDto reviewClient)
        {
            if (reviewClient.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (await _repo.AlreadyUserReview(reviewClient.UserId, reviewClient.RecipeId))
            {
                throw new Exception($"You already review this recipe");
            }

            reviewClient.Created = DateTime.Now;
            reviewClient.Status  = "Acepted";

            var reviewMap = _mapper.Map <Review>(reviewClient);

            _repo.Add(reviewMap);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"the creation for review fail");
        }
예제 #3
0
        public async Task <IActionResult> createFallowUser(int id)
        {
            var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (await _repo.GetUser(userId) == null)
            {
                return(Unauthorized());
            }

            var fallowUser = new FallowUserForCreateDto();

            fallowUser.DateCreated = DateTime.Now;
            fallowUser.UserId      = userId;
            fallowUser.FollowerId  = id;

            FollowUser newFallowUser = _mapper.Map <FollowUser>(fallowUser);

            _repo.Add(newFallowUser);


            if (await _repo.SaveAll())
            {
                return(StatusCode(201));
            }

            throw new Exception($"the creation for fallowUser fail");
        }
예제 #4
0
 public void Insert(Cook entity)
 {
     _cookRepository.Add(entity);
 }