Exemplo n.º 1
0
        public async Task <IActionResult> New()
        {
            var listMealOperation = await _mbo.ListNonDeletedAsync();

            if (!listMealOperation.Success)
            {
                return(OperationErrorBackToIndex(listMealOperation.Exception));
            }

            var listRestOperation = await _rbo.ListNonDeletedAsync();

            if (!listRestOperation.Success)
            {
                return(OperationErrorBackToIndex(listRestOperation.Exception));
            }

            var mealList = new List <SelectListItem>();

            foreach (var item in listMealOperation.Result)
            {
                mealList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }

            var restList = new List <SelectListItem>();

            foreach (var item in listRestOperation.Result)
            {
                restList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }

            ViewBag.Meals       = mealList;
            ViewBag.Restaurants = restList;
            ViewData["Title"]   = "New Menu";
            var crumbs = GetCrumbs();

            crumbs.Add(new BreadCrumb()
            {
                Action = "New", Controller = "Menus", Icon = "fa-plus", Text = "New"
            });
            ViewData["BreadCrumbs"] = crumbs;
            return(View());
        }
Exemplo n.º 2
0
        public void TestDeleteRestaurantAsync()
        {
            RestaurantSeeder.Seed();
            var bo        = new RestaurantBusinessObject();
            var resList   = bo.ListAsync().Result;
            var resDelete = bo.DeleteAsync(resList.Result.First().Id).Result;

            resList = bo.ListNonDeletedAsync().Result;
            Assert.IsTrue(resDelete.Success && resList.Success && resList.Result.Count == 0);
        }
Exemplo n.º 3
0
        public void TestUpdateRestaurantAsync()
        {
            RestaurantSeeder.Seed();
            var bo      = new RestaurantBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();

            item.Name = "another";
            var resUpdate = bo.UpdateAsync(item).Result;

            resList = bo.ListNonDeletedAsync().Result;
            Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().Name == "another");
        }
        public async Task <IActionResult> ListAsync()
        {
            var listResult = await _bo.ListNonDeletedAsync();

            if (!listResult.Success)
            {
                return(InternalServerError(listResult.Exception));
            }
            var list = listResult.Result;
            var lst  = new List <RestaurantViewModel>();

            foreach (var item in list)
            {
                var vm = RestaurantViewModel.Parse(item);
                lst.Add(vm);
            }
            return(Ok(lst));
        }
        public async Task <IActionResult> Index()
        {
            var listOperation = await _bo.ListNonDeletedAsync();

            if (!listOperation.Success)
            {
                return(OperationErrorBackToIndex(listOperation.Exception));
            }

            var lst = new List <RestaurantViewModel>();

            foreach (var item in listOperation.Result)
            {
                lst.Add(RestaurantViewModel.Parse(item));
            }

            ViewData["Title"]       = "Restaurants";
            ViewData["BreadCrumbs"] = GetCrumbs();
            ViewData["DeleteHref"]  = GetDeleteRef();

            return(View(lst));
        }