Exemple #1
0
        public HomeIndexViewModel ShowAll()
        {
            //IFoodService foodService = DependencyResolver.Current.GetService<IFoodService>();

            //Mapper.CreateMap()

            // Need to set a autio mapper to map Bussiness model with UI view Model
            //var sandwiches = foodService.GetAllSandwiches();

            var result = _foodService.GetAllSandwiches();
            GetSandwichResult getSandwichResult = new GetSandwichResult();

            getSandwichResult.CompanyDetailsModel = result.CompanyDetailsModel;
            getSandwichResult.SandwichModel       = result.SandwichModel;

            HomeIndexViewModel homeIndexViewModel = new HomeIndexViewModel();

            List <SandwichViewModel> sadwichList = new List <SandwichViewModel>();

            foreach (var sm in getSandwichResult.SandwichModel)
            {
                SandwichViewModel sandwichViewModelItems = new SandwichViewModel(sm.SandwichName, sm.SandwichType,
                                                                                 sm.Ingrediant, sm.Rate, sm.Price, sm.Image);

                sadwichList.Add(sandwichViewModelItems);

                //homeIndexViewModel.SandwichViewModel.Ingrediant = sm.Ingrediant;
                //homeIndexViewModel.SandwichViewModel.Price = sm.Price;
                //homeIndexViewModel.SandwichViewModel.Rate = sm.Rate;
                //homeIndexViewModel.SandwichViewModel.SandwichName = sm.SandwichName;
                //homeIndexViewModel.SandwichViewModel.SandwichType = sm.SandwichType;

                //homeIndexViewModel.AllSandwich.Add(sandwichViewModel);
            }

            homeIndexViewModel.AllSandwichList = new HomeSandwichListPartialViewModel(sadwichList);
            homeIndexViewModel.Details         = new CompanyDetailsViewModel(getSandwichResult.CompanyDetailsModel.CompanyName, getSandwichResult.CompanyDetailsModel.CompanyMoto, getSandwichResult.CompanyDetailsModel.StartDate);

            //homeIndexViewModel.Details.CompanyMoto = getSandwichResult.CompanyDetailsModel.CompanyMoto;
            //homeIndexViewModel.Details.CompanyName = getSandwichResult.CompanyDetailsModel.CompanyName;
            //homeIndexViewModel.Details.StartDate = getSandwichResult.CompanyDetailsModel.StartDate;

            //homeIndexViewModel.AllSandwich = getSandwichResult.SandwichModel

            //Mapper.Map<HomeIndexViewModel, GetSandwichResult>(result);

            //homeIndexViewModel.AllSandwich = result.SandwichModel;

            //homeIndexViewModel.Details = result.CompanyDetailsModel;

            SandwichViewModel sandwichViewModels1; //= Mapper.Map<SandwichViewModel>(sandwiches);

            return(homeIndexViewModel);
        }
        public List <SandwichViewModel> GetAllSandwich()
        {
            var result = _foodService.GetAllSandwiches();
            GetSandwichResult getSandwichResult = new GetSandwichResult();

            getSandwichResult.CompanyDetailsModel = result.CompanyDetailsModel;
            getSandwichResult.SandwichModel       = result.SandwichModel;

            List <SandwichViewModel> sandwichList = new List <SandwichViewModel>();

            foreach (var sm in getSandwichResult.SandwichModel)
            {
                SandwichViewModel sandwichViewModelItems = new SandwichViewModel(sm.SandwichName, sm.SandwichType, sm.Ingrediant, sm.Rate, sm.Price, sm.Image);

                sandwichList.Add(sandwichViewModelItems);
            }

            return(sandwichList);
        }