Ejemplo n.º 1
0
 private DetailViewModel CreateDetailviewModel(Tool tool, DateTime dueDate)
 {
     DetailViewModel dt = new DetailViewModel();
     dt.tool = tool;
     return dt;
 }
Ejemplo n.º 2
0
        // GET: Tools/Details/5
        public ActionResult Details(int? id, int? categoryId)
        {
            ViewBag.selectedCategoryId = categoryId;
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Tool tool = db.Tools.Find(id);
            if (tool == null)
            {
                return HttpNotFound();
            }

            var checkedOutTool = (from t in db.Tools
                                  join r in db.Rentals on t.Id equals r.Tool.Id
                                  where t.Id == id
                                  orderby r.CheckedOut
                                  select t);

            var rentals = (from r in db.Rentals
                           where r.Tool.Id == id
                           select r).ToList();

            var detailViewModel = new DetailViewModel();
            detailViewModel.tool = tool;
            detailViewModel.CategoryId = Convert.ToInt16(categoryId);
            ViewBag.CategoryId = tool.CategoryId;
            if (rentals.Count > 0)
            {
                detailViewModel.Rentals = rentals;
                List<DateTime> reservedDates = GetCheckedOutDates(tool.Id);
                detailViewModel.ReservedDates = reservedDates;
                detailViewModel.TriggerOnLoad = false;
                detailViewModel.TriggerOnLoadMessage = "";
                return View(detailViewModel);
            }
            else
            {
                detailViewModel.Rentals = rentals;
                detailViewModel.tool = tool;
                detailViewModel.TriggerOnLoad = false;
                detailViewModel.TriggerOnLoadMessage = "";
                List <DateTime> ReservedDates = GetCheckedOutDates(tool.Id);
                detailViewModel.ReservedDates = ReservedDates;
                return View(detailViewModel);
            }

            //DetailViewModel viewModel = new DetailViewModel();
            //viewModel.tool = tool;
            //detailViewModel.CategoryId = Convert.ToInt16(categoryId);

            //List<DateTime> ReservedDates = GetCheckedOutDates(tool.Id);
            //viewModel.ReservedDates = ReservedDates;
            //ViewBag.CategoryId = tool.CategoryId;
        }