Ejemplo n.º 1
0
        public IHttpActionResult AddList([FromBody] FoodListViewModel viewModel)
        {
            try
            {
                if (viewModel == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                FoodList item = Mapper.Map <FoodList>(viewModel);
                item.UserId = CurrentUserId;
                _foodListRepository.Add(item);
                int save = _foodListRepository.Save();

                if (save > 0)
                {
                    return(CreatedAtRoute("GetSingleList", new { id = item.Id }, item));
                }

                return(BadRequest());
            }
            catch (Exception exception)
            {
                return(InternalServerError(exception));
            }
        }
Ejemplo n.º 2
0
        public IActionResult FoodList(int pageNumber = 0)
        {
            var pageSize   = this.contextAccessor.HttpContext.Session.GetInt32("food_page_size") ?? 3;
            var food       = this.unitOfWork.FoodItems.Get().ToList();
            var totalPages = food.Count / pageSize;

            if (this.contextAccessor.HttpContext.Session.GetInt32("food_sort_direction") ==
                (int)SortDirection.Ascending)
            {
                food = this.orderAscending(food);
            }
            else if (this.contextAccessor.HttpContext.Session.GetInt32("food_sort_direction") ==
                     (int)SortDirection.Descending)
            {
                food = this.orderDescending(food);
            }

            totalPages += food.Count % pageSize == 0 ? 0 : 1;
            food        = food.Skip((pageNumber - 1) * pageSize).Take(pageSize > food.Count ? food.Count : pageSize)
                          .ToList();

            var viewModel = new FoodListViewModel {
                PageNumber = pageNumber,
                PageSize   = pageSize,
                TotalPages = totalPages,
                Items      = food
            };

            ViewBag.Page = "FoodList";
            return(View(viewModel));
        }
        public async Task <ActionResult> Index()
        {
            var query = queryProvider.Parse <FoodDTO>();

            int pg       = (int)query.Page;
            var grouping = query.GetGrouping <FoodDTOGrouping>();

            var model = new FoodListViewModel
            {
                Query    = query,
                Products =
                    grouping == null ?
                    await Repository.GetPage(
                        query.GetFilterExpression(),
                        query.GetSorting() ??
                        (q => q.OrderBy(m => m.ProductName)),
                        pg, 5)
                        :
                    await Repository.GetPageExtended(
                        query.GetFilterExpression(),
                        query.GetSorting <FoodDTOGrouping>() ??
                        (q => q.OrderBy(m => m.ProductName)),
                        pg, 5,
                        query.GetGrouping <FoodDTOGrouping>())
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public void Show(FoodListViewModel viewModel)
        {
            SortButton.Tag = viewModel.IsSorted;

            FoodListBox.DataSource    = new List <FoodViewModel>(viewModel.Food);
            FoodListBox.DisplayMember = "Name";
            FoodListBox.ValueMember   = "Id";
        }
Ejemplo n.º 5
0
        public ViewResult List()
        {
            ViewBag.Title = "Вкусно как дома";
            FoodListViewModel obj = new FoodListViewModel();

            obj.AllFood         = _allFoods.IFoods;
            obj.currentCategory = "Наименование и цены";
            return(View(obj));
        }
Ejemplo n.º 6
0
        public ViewResult List()
        {
            FoodListViewModel foodListViewModel = new FoodListViewModel();

            foodListViewModel.Foods = _foodRepository.Foods;

            foodListViewModel.CurrentCategory = "Cheese cakes";
            return(View(foodListViewModel));
        }
Ejemplo n.º 7
0
        public ActionResult Create(FoodListViewModel foodList, HttpPostedFileBase fileUpload)
        {
            string pathImage = string.Empty;

            //kiểm tra và thêm dữ liệu vào database
            if (ModelState.IsValid)
            {
                string filePathSave = string.Empty;
                //check image resource
                if (fileUpload == null)
                {
                    //đặt đường dẫn ảnh mặc định
                    filePathSave = "404.png";
                }
                else
                {
                    filePathSave = Path.GetFileName(fileUpload.FileName);
                    pathImage    = Path.Combine(Server.MapPath("~/Content/FoodList"), filePathSave);
                    if (System.IO.File.Exists(pathImage))
                    {
                        //Hình ảnh đã tồn tại
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        //Lưu tên file sẽ insert vào
                        filePathSave = fileUpload.FileName;
                    }
                }

                //cập nhật thời gian, tên ảnh, người thực hiện, mã của sản phẩm - thiếu người thực hiện
                foodList.FoodPoster  = filePathSave;
                foodList.CreatedDate = DateTime.Now;
                foodList.FoodPrefix  = CommonConstrants.FOOD_PREFIX;
                //thêm vào database và lưu kết quả
                FoodList result = new FoodList();
                result.UpdateFoodList(foodList);
                var resultFoodList = _foodListService.Add(result);
                if (resultFoodList == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    if (filePathSave != "404.png")
                    {
                        fileUpload.SaveAs(pathImage);
                    }
                    _foodListService.SaveChanges();
                    SetAlert("Thêm món ăn thành công", CommonConstrants.SUCCESS_ALERT);
                    return(RedirectToAction("Index", "FoodList"));
                }
            }
            ViewBag.FoodStatusID = new SelectList(_statusService.GetAll(), "StatusID", "StatusName");
            return(View(foodList));
        }
Ejemplo n.º 8
0
        public ViewResult List()
        {
            ViewBag.Name = "dotnet, how";
            var foods            = _foodRepository.Foods;
            FoodListViewModel vm = new FoodListViewModel();

            vm.Foods           = _foodRepository.Foods;
            vm.CurrentCategory = "FoodCategory";
            return(View(vm));
        }
        public ViewResult Index()
        {
            var FoodListViewModel = new FoodListViewModel
            {
                PreferredFoods = _foodrepository.PreferredFoods
            };


            return(View(FoodListViewModel));
        }
Ejemplo n.º 10
0
 public static void UpdateFoodList(this FoodList foodList, FoodListViewModel foodListVm)
 {
     foodList.FoodPrefix      = foodListVm.FoodPrefix;
     foodList.FoodName        = foodListVm.FoodName;
     foodList.FoodPrice       = foodListVm.FoodPrice;
     foodList.FoodDescription = foodListVm.FoodDescription;
     foodList.FoodPoster      = foodListVm.FoodPoster;
     foodList.FoodStatus      = foodListVm.FoodStatusID;
     foodList.CreatedDate     = foodListVm.CreatedDate;
     foodList.CreatedBy       = foodListVm.CreatedBy;
     foodList.UpdatedDate     = foodListVm.UpdatedDate;
     foodList.UpdatedBy       = foodListVm.UpdatedBy;
     foodList.MetaKeyword     = foodListVm.MetaKeyword;
     foodList.MetaDescription = foodListVm.MetaDescription;
 }
Ejemplo n.º 11
0
        public ActionResult FoodList()
        {
            //Create Map
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Food, FoodListViewModel>());
            var mapper = config.CreateMapper();
            //Copy values
            List <FoodListViewModel> viewModelsList = new List <FoodListViewModel>();

            foreach (Food food in _foodRepository.GetAll())
            {
                FoodListViewModel foodListViewModel = mapper.Map <FoodListViewModel>(food);
                viewModelsList.Add(foodListViewModel);
            }
            return(View(viewModelsList));
        }
Ejemplo n.º 12
0
        public FoodListPage()
        {
            InitializeComponent();

            BindingContext = new FoodListViewModel();


            /*  foodListView.ItemsSource = new List<Food>()
             * {
             *    new Food{Id=1,Name="Choclate Cake",Category="Burger",Image="http://lorempixel.com/200/100/food/10/",Description="Spice of Choclate"},
             *    new Food{Id=1,Name="Tofu Salad",Category="Juice",Image="http://lorempixel.com/200/100/food/2/",Description="Tofu with a Twist"},
             *   new Food{Id=1,Name="Green Omelete",Category="Fruits",Image="http://lorempixel.com/200/100/food/3/",Description="Healthy Duck Egg with Wheat Bread"},
             *   new Food{Id=1,Name="Organic Salad",Category="Juice",Image="http://lorempixel.com/200/100/food/4/",Description="From Fresh Farm"},
             *    new Food{Id=1,Name="Fruit Salad",Category="Beverages",Image="http://lorempixel.com/200/100/food/5/",Description="Good as New"},
             *   new Food{Id=1,Name="Sushi",Category="Chicken Wing",Image="http://lorempixel.com/200/100/food/6/",Description="Ting Wih Sushi"}
             * };*/
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Index(string category)
        {
            FoodListViewModel foodListViewModel = new FoodListViewModel
            {
                FoodList  = await Mediator.Send(new GetFoodsListQuery()),
                FoodTypes = await Mediator.Send(new GetFoodTypesQuery())
            };

            if (category != null)
            {
                foodListViewModel.FoodList = await Mediator.Send(new GetFoodListByCategoryQuery
                {
                    Items    = foodListViewModel.FoodList,
                    Category = category
                });
            }

            return(View(foodListViewModel));
        }
Ejemplo n.º 14
0
        public ActionResult List(int id)
        {
            List <Food> foods = _foodContext.GetAll().Where(r => r.RestaurantId == id).ToList();
            List <FoodListViewModel> foodMenu = new List <FoodListViewModel>();

            ViewBag.RestaurantId = id;

            //create Map
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Food, FoodListViewModel>());
            var mapper = config.CreateMapper();

            //Copy values
            foreach (Food food in foods)
            {
                FoodListViewModel foodViewModel = mapper.Map <FoodListViewModel>(food);
                foodViewModel.Rating = _facade.GetFoodRating(food.FoodId);
                foodMenu.Add(foodViewModel);
            }

            return(PartialView(foodMenu));
        }