Ejemplo n.º 1
0
        public async Task <IActionResult> RemoveFromSessionInConfirmation(int?id, int appoinmentId)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Dictionary <int, int> lst = HttpContext.Session.Get <Dictionary <int, int> >("ls");

            if (lst[int.MaxValue] != appoinmentId)
            {
                return(NotFound());
            }


            //Dictionary<int, int> lst = HttpContext.Session.Get<Dictionary<int, int>>("ssShoppingCard");
            //if (lst.Count > 0)
            //{
            //    if (lst.ContainsKey((int)id))
            //    {
            //        lst.Remove((int)id);
            //    }
            //}
            ProductsSelectedForAppointment psd = null;

            if (orm == 1)
            {
                qdb.rmpsa(appoinmentId, (int)id);
            }
            else
            {
                psd = await _db.ProductsSelectedForAppointments.FirstAsync(e => e.AppointmentId == appoinmentId && e.ProductId == id);

                _db.ProductsSelectedForAppointments.Remove(psd);
                await _db.SaveChangesAsync();
            }

            var count = _db.ProductsSelectedForAppointments.Count(e => e.AppointmentId == appoinmentId);

            if (count == 0)
            {
                lst[int.MinValue] = 1;
                HttpContext.Session.Set("ls", lst);
                return(RedirectToAction(nameof(Index)));
            }

            HttpContext.Session.Set("ls", lst);
            return(RedirectToAction("AppointmentConfirmation", "ShoppingCard", new { id = appoinmentId }));
        }