Ejemplo n.º 1
0
        // Get : Details
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Appointments apppointment = null;

            if (orm == 1)
            {
                apppointment = qdb.retAppointment((int)id);
            }
            else
            {
                apppointment = await(from i in _db.Appointments where i.Id == id select i).FirstAsync();
            }

            if (apppointment == null)
            {
                return(NotFound());
            }

            List <Products> products = null;
            List <ProductsSelectedForAppointment> psd = null;

            if (orm == 1)
            {
                products = qdb.p_join_psa((int)id);
                qdb.include_pt_st(products);
                psd = qdb.retpsa((int)id);
            }
            else
            {
                products = await(from i in _db.Products
                                 join j in _db.ProductsSelectedForAppointments on i.Id equals j.ProductId
                                 where j.AppointmentId == id
                                 select i).Include(e => e.ProductTypes).ToListAsync();
                psd = _db.ProductsSelectedForAppointments.Where(e => e.AppointmentId == id).ToList();
            }

            foreach (Products i in products)
            {
                i.Count = psd.First(e => e.ProductId == i.Id).Count;
                i.Price = i.Price * i.Count;
            }

            var applicationUsers = (from i in _db.ApplicationUsers select i);

            AppointmentDetailViewModel vm = new AppointmentDetailViewModel()
            {
                ApplicationUsers = applicationUsers,
                Appointments     = apppointment,
                Products         = products
            };

            return(View(vm));
        }