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"); }
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"); }
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"); }
public void Insert(Cook entity) { _cookRepository.Add(entity); }