public IHttpActionResult GetFoodsFromList(int id) { try { FoodList foodList = _foodListRepository.GetSingle(x => x.Id == id, "Foods"); return(Ok(foodList.Foods.Select(x => Mapper.Map <FoodItemViewModel>(x)))); } catch (Exception exception) { return(InternalServerError(exception)); } }
public IActionResult GetFoodsFromList(Guid id) { FoodList foodList = _foodListRepository.GetSingle(id, true); if (foodList.Foods == null) { var items = new List <FoodItem>(); return(Ok(items.Select(x => Mapper.Map <FoodItemDto>(x)))); } return(Ok(foodList.Foods.Select(x => Mapper.Map <FoodItemDto>(x)))); }
public IHttpActionResult GetAllSharedLists() { try { List <SharedFoodList> existingMatches = _sharedFoodListRepository .GetAll(x => x.UserEmail == CurrentUserEmail).ToList(); if (existingMatches.Any(x => x.UserId == String.Empty)) { foreach (SharedFoodList sharedFoodList in existingMatches) { if (sharedFoodList.UserId == String.Empty) { sharedFoodList.UserId = CurrentUserId; _sharedFoodListRepository.Update(sharedFoodList); } } _sharedFoodListRepository.Save(); } List <FoodList> toReturn = existingMatches .Select(sharedFoodList => _foodListRepository .GetSingle(x => x.Id == sharedFoodList.FoodListId)) .ToList(); return(Ok(toReturn.Select(x => Mapper.Map <FoodListViewModel>(x)))); } catch (Exception exception) { return(InternalServerError(exception)); } }
public IActionResult GetSingleList(Guid id) { FoodList singleFoodList = _foodListRepository.GetSingle(id, false); if (singleFoodList == null) { return(NotFound()); } if (singleFoodList.UserId != _userManager.GetUserId(HttpContext.User)) { return(new StatusCodeResult((int)HttpStatusCode.Forbidden)); } var toReturn = Mapper.Map <FoodListDto>(singleFoodList); return(Ok(toReturn)); }
public IHttpActionResult GetSingleList(int id) { try { FoodList singleFoodList = _foodListRepository.GetSingle(x => x.Id == id); if (singleFoodList == null) { return(NotFound()); } if (singleFoodList.UserId != CurrentUserId) { return(StatusCode(HttpStatusCode.Forbidden)); } return(Ok(Mapper.Map <FoodListViewModel>(singleFoodList))); } catch (Exception exception) { return(InternalServerError(exception)); } }