Ejemplo n.º 1
0
        public async Task <IActionResult> ScheduleAppointment()
        {
            Dictionary <int, int> items = HttpContext.Session.Get <Dictionary <int, int> >("ls");

            if (items.Keys.Count == 0)
            {
                return(RedirectToAction(nameof(Index), "Home"));
            }

            ShoppingCardvm.Appointments.AppointmentDate = ShoppingCardvm.Appointments.AppointmentDate
                                                          .AddHours(ShoppingCardvm.Appointments.AppointmentTime.Hour)
                                                          .AddMinutes(ShoppingCardvm.Appointments.AppointmentTime.Minute);

            if (orm == 1)
            {
                ShoppingCardvm.Appointments.Id = qdb.inappointment(ShoppingCardvm.Appointments);
            }
            else
            {
                _db.Appointments.Add(ShoppingCardvm.Appointments);
                await _db.SaveChangesAsync();
            }


            int idAppointment = ShoppingCardvm.Appointments.Id;

            if (orm == 1)
            {
                foreach (var i in items.Keys)
                {
                    ProductsSelectedForAppointment psa = new ProductsSelectedForAppointment()
                    {
                        AppointmentId = idAppointment,
                        ProductId     = i,
                        Count         = items[i]
                    };
                    //qdb.include_pi_ai(psa);
                    qdb.inpsa(psa);
                }
            }
            else
            {
                foreach (var i in items.Keys)
                {
                    ProductsSelectedForAppointment psa = new ProductsSelectedForAppointment()
                    {
                        AppointmentId = idAppointment,
                        ProductId     = i,
                        Count         = items[i]
                    };
                    _db.ProductsSelectedForAppointments.Add(psa);
                }
                await _db.SaveChangesAsync();
            }

            //items = new Dictionary<int, int>();
            items[int.MaxValue] = idAppointment;
            HttpContext.Session.Set("ls", items);
            return(RedirectToAction("AppointmentConfirmation", "ShoppingCard",
                                    new { id = ShoppingCardvm.Appointments.Id }));
        }