public IActionResult Post([FromBody] RecipeViewModel recipe) { if (recipe == null) { return(BadRequest("recipe is null.")); } //recipe.Token = Guid.NewGuid(); FillNullvalueswithDefaultValue(ref recipe); Recipe recipeDest = _custumMapper.Map(recipe); //Recipe recipeDest = _mapper.Map<RecipeViewModel, Recipe >(recipe); var name = _userManager.GetUserId(User); var user = _userManager.FindByNameAsync(name).Result; recipeDest.User = user; recipeDest.UserId = user.Id; if (_dataRepository.Exist(recipeDest)) { return(BadRequest("This recipe exist.")); } _dataRepository.Add(recipeDest); recipe.ID = recipeDest.ID; var rtlookup = new RecipeTokenLookUP() { RecipeID = recipe.ID, Recipe = recipeDest, Token = Guid.NewGuid() }; _tokenRepository.Add(rtlookup); return(Ok(rtlookup.Token.ToString())); }
public async Task RemoveAsync <D>(D dto, bool hardDelete = false) where D : IDTO { T dummyEntity = mapper.Map <T>(dto); T orjinal = await genericRepository.GetByIdAsync(dummyEntity.Id); orjinal = customMapper.Map(dto, orjinal); await genericRepository.RemoveAsync(orjinal, hardDelete); }
public ActionResult ShowWeather(WeatherQuestion weatherQuestion) { var weather = _weatherService.GetWeather(weatherQuestion.Country, weatherQuestion.City); var weatherModel = _mapper.Map <WeatherModel>(weather); return(View(weatherModel)); }
public void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); _mapper.Map(route, container); }
public void Test_map_From_recipeVieModel_To_recipe() { RecipeViewModel acctual = new MockDBHandler().buildMockRecipeView(); DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build(); using (var context = new RepositoryContext(options)) { _custumMapper = new CustomMapper(context); //Act var recipDes = _custumMapper.Map(acctual); var expected = _custumMapper.Map(recipDes); // Assert Assert.True(expected.Equals(acctual)); } }
public void Test_map_From_recipe_To_recipeVieModel() { DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build(); using (var context = new RepositoryContext(options)) { _custumMapper = new CustomMapper(context); var acctual = context.Recipe.Include(y => y.Category) .Include(r => r.Country) .Include(w => w.Ingredients) .FirstOrDefaultAsync().Result; acctual.Ingredients = context.RecipeIngredient.Include(x => x.Ingredient).Include(y => y.Unit).Where(T => T.RecipeID == acctual.ID).ToList(); //Act var recipDes = _custumMapper.Map(acctual); var expected = _custumMapper.Map(recipDes); // Assert Assert.True(expected.Equals(acctual)); } }
public ActionResult <PagedCollectionResponse <RecipeViewModel> > Get([FromQuery] FilterModel filter) { IEnumerable <Recipe> recipe = _dataRepository.GetAll(); List <RecipeViewModel> recipDes = new List <RecipeViewModel>(); //Filtering logic Func <FilterModel, IEnumerable <Recipe> > filterData = (filterModel) => { return(recipe.Where(p => p.Name.StartsWith(filterModel.Term ?? String.Empty, StringComparison.InvariantCultureIgnoreCase)) .Skip((filterModel.Page - 1) * filter.Limit) .Take(filterModel.Limit)); }; foreach (var item in filterData(filter)) { recipDes.Add(_custumMapper.Map(item)); } //Get the data for the current page var result = new PagedCollectionResponse <RecipeViewModel>(); result.Items = recipDes; //Get next page URL string FilterModel nextFilter = filter.Clone() as FilterModel; nextFilter.Page += 1; String nextUrl = filterData(nextFilter).Count() <= 0 ? null : this.Url.Action("Get", null, nextFilter, Request.Scheme); //Get previous page URL string FilterModel previousFilter = filter.Clone() as FilterModel; previousFilter.Page -= 1; String previousUrl = previousFilter.Page <= 0 ? null : this.Url.Action("Get", null, previousFilter, Request.Scheme); result.NextPage = !String.IsNullOrWhiteSpace(nextUrl) ? new Uri(nextUrl) : null; result.PreviousPage = !String.IsNullOrWhiteSpace(previousUrl) ? new Uri(previousUrl) : null; return(result); }
public static IPagedList <TResult> ToMappedPagedList <TSource, TResult>(this IPagedList <TSource> list, ICustomMapper <TSource, TResult> mapper) where TSource : class { var sourceList = mapper.Map(list); return(new StaticPagedList <TResult>(sourceList, list.GetMetaData())); }
public WeatherModel Get(string country, string city) { return(_mapper.Map <WeatherModel>(_weatherService.GetWeather(country, city))); }