public CocktailViewModel(ICocktail cocktail) { StringBuilder stringBuilder = new StringBuilder(); var ingredientsText = String.Join(", ", cocktail.Ingredients.Select(p => p.IngredientName)); if (ingredientsText.Length < 53) { stringBuilder.Append(ingredientsText.Substring(0)); } else { stringBuilder.Append(ingredientsText.Substring(0, 53)); stringBuilder.Append("..."); } Id = cocktail.Id; Name = cocktail.Name; AverageRating = cocktail.AverageRating; ShortDescription = stringBuilder.ToString(); Description = cocktail.Description; RatingsCount = cocktail.Ratings.Count(); Ratings = new CocktailRatingListViewModel(cocktail.Ratings); Comments = new CocktailCommentListViewModel(cocktail.Comments); Bars = new BarCocktailListViewModel(cocktail.Bars); FavoritedBy = new UserCocktailListViewModel(cocktail.FavoritedBy); Ingredients = new CocktailIngredientListViewModel(cocktail.Ingredients); Hidden = cocktail.Hidden == 1 ? true : false; }
public BarViewModel(IBar bar) { StringBuilder stringBuilder = new StringBuilder(); if (bar.Description.Length < 256) { stringBuilder.Append(bar.Description.Substring(0)); } else { stringBuilder.Append(bar.Description.Substring(0, 255)); } stringBuilder.Append("..."); Id = bar.Id; Name = bar.Name; Address = bar.Address; AverageRating = bar.AverageRating; ShortDescription = stringBuilder.ToString(); Description = bar.Description; RatingsCount = bar.Ratings.Count(); City = bar.City.Name; Country = bar.Country.Name; Ratings = new BarRatingListViewModel(bar.Ratings); Comments = new BarCommentListViewModel(bar.Comments); Cocktails = new BarCocktailListViewModel(bar.Cocktails); FavoritedBy = new UserBarListViewModel(bar.FavoritedBy); Hidden = bar.Hidden == 1 ? true : false; }