public IActionResult IndexPost()
        {
            List <int> lstCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");

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

            Appointments appointments = ShoppingCartVM.Appointments;

            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            int appointmentId = appointments.Id;

            foreach (int productId in lstCartItems)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId     = productId
                };
                _db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
            }
            _db.SaveChanges();
            lstCartItems = new List <int>();
            HttpContext.Session.Set("ssShoppingCart", lstCartItems);

            return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
        }
예제 #2
0
        public async Task <ActionResult> IndexPost()
        {
            if (ModelState.IsValid)
            {
                var usr = userManager.FindByNameAsync("*****@*****.**").Result;
                shoppingCartViewModel.Appointment.SalesPersonId = usr.Id;
                List <int> lstCartItems = HttpContext.Session.Get <List <int> >("shoppingCart");
                db.Appointments.Add(shoppingCartViewModel.Appointment);
                await db.SaveChangesAsync();

                var appointmentId = shoppingCartViewModel.Appointment.Id;
                foreach (int productId in lstCartItems)
                {
                    ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                    {
                        AppointmentId = appointmentId,
                        ProductId     = productId
                    };
                    db.ProductsSelectedForAppointments.Add(productsSelectedForAppointment);
                }
                await db.SaveChangesAsync();

                //Charge( stripeEmail,  stripeToken);
                //HttpContext.Session.Set("shoppingCart",new List<int>());
                return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { area = "Customer", Id = shoppingCartViewModel.Appointment.Id }));
            }
            return(RedirectToAction($"Index", "ShoppingCart", new { area = "Customer" }));
        }
예제 #3
0
        public IActionResult IndexPost()
        {
            //add appointment to database
            List <int> lstCartItem = HttpContext.Session.Get <List <int> >("ssShoppingCart");

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

            _context.Appointments.Add(appointments);
            _context.SaveChanges();

            //add productselectedforappointment to database
            int apponitmentId = appointments.Id;

            foreach (int productId in lstCartItem)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = apponitmentId,
                    ProductId     = productId
                };
                _context.ProductsSelectedForAppointments.Add(productsSelectedForAppointment);
                _context.SaveChanges();
            }

            _context.SaveChanges();

            //set bag null when click button submit
            lstCartItem = new List <int>();
            HttpContext.Session.Set("ssShoppingCart", lstCartItem);
            return(RedirectToAction("AppointmentConfirm", "ShoppingCart", new { Id = apponitmentId }));
        }
예제 #4
0
        public IActionResult IndexPost()
        {
            List <int>   ListCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");
            Appointments appointments  = ShoppingViewModel.Appointments;

            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            int appointmentid = appointments.Id;

            foreach (var productid in ListCartItems)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment
                {
                    AppointmentId = appointmentid,
                    ProductId     = productid,
                };
                _db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
            }
            _db.SaveChanges();
            ListCartItems = new List <int>();
            HttpContext.Session.Set("ssShoppingCart", ListCartItems);

            return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentid }));
        }
예제 #5
0
        public IActionResult IndexPost()
        {
            List <int> cartItemList = HttpContext.Session.Get <List <int> >(StaticDetails.ShoppingCartName);

            ShoppingCartVM.Appointment.AppointmentDate = ShoppingCartVM.Appointment.AppointmentDate
                                                         .AddHours(ShoppingCartVM.Appointment.AppointmentTime.Hour)
                                                         .AddMinutes(ShoppingCartVM.Appointment.AppointmentTime.Minute);

            Appointment appointment = ShoppingCartVM.Appointment;

            _db.Appointments.Add(appointment);
            _db.SaveChanges();

            int appointmentId = appointment.Id;

            foreach (var productId in cartItemList)
            {
                ProductsSelectedForAppointment productsSelected = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId     = productId
                };

                _db.ProductsSelectedForAppointments.Add(productsSelected);
            }

            _db.SaveChanges();
            cartItemList = new List <int>();
            HttpContext.Session.Set(StaticDetails.ShoppingCartName, cartItemList);

            return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
        }
예제 #6
0
        public IActionResult IndexPost()                                                       //ShoppingCartVM is already binded, no need for parameters
        {
            List <int> lstCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart"); //get the session to list of int

            //DATEPICKER JQUERY NEVRACI SPRAVNE DATUM
            ShoppingCartVM.Appointments.AppointmentDate = ShoppingCartVM.Appointments.AppointmentDate       //merge app.time and app.date to appointment itself (AppointmentDate)
                                                          .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                                                          .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute);


            Appointments appointments = ShoppingCartVM.Appointments;  //save to appointments object

            this.db.Appointments.Add(appointments);
            this.db.SaveChanges();

            int appointmentId = appointments.Id;     //id was created when save to Db

            foreach (int productId in lstCartItems)  //for every itemid in shoppingcart
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,                                          //merge appointmentId with AppointmentId from ProductsSelectedForAppointment class
                    ProductId     = productId                                               //viz vyse
                };
                this.db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment); //pridej do Db
            }
            this.db.SaveChanges();
            lstCartItems = new List <int>();                         //empty listcart items
            HttpContext.Session.Set("ssShoppingCart", lstCartItems); //begin new session for another shoppingcart

            //po vytvoreni appointment redirect to AppointmentConfirmation method in ShoppingCartcontroller and use Id you retrieve
            return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
        }
        public async Task <IActionResult> IndexPost()
        {
            List <int> listCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            //marge appointment day and time
            ShoppingCartVM.Appointments.AppointmentDate = ShoppingCartVM.Appointments.AppointmentDate
                                                          .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                                                          .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute);

            //object of Appointment
            Appointments appointments = ShoppingCartVM.Appointments;

            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            // now we get appointment id cz last step we crear an appointment
            int appointmentId = appointments.Id;

            // now use this id inside the product selected for an appointment
            foreach (int productId in listCartItems)
            {
                ProductsSelectedForAppointment psfa = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId     = productId
                };
                _db.ProductsSelectedForAppointment.Add(psfa);
            }
            _db.SaveChanges();
            listCartItems = new List <int>(); // after add empty list
            HttpContext.Session.Set("ssShoppingCart", listCartItems);

            return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
        }
        public async Task <IActionResult> IndexPost()
        {
            List <string> lstSampleCart = HttpContext.Session.Get <List <string> >("ssSampleCart");

            Debug.WriteLine("****************************************" + SampleCartVM.Appointments.CustomerEmail);

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

            Appointments appointments = SampleCartVM.Appointments;

            _db.Appointments.Add(appointments);
            await _db.SaveChangesAsync();

            int appintmentId = appointments.ID;

            foreach (string productId in lstSampleCart)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentID = appintmentId,
                    ProductId     = Convert.ToInt32(productId)
                };

                _db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
            }

            await _db.SaveChangesAsync();

            lstSampleCart = new List <string>();
            HttpContext.Session.Set("ssSampleCart", lstSampleCart);

            return(RedirectToAction("AppointmentConfirmation", "SampleCart", new { Id = appintmentId }));
        }
        public ProductsSelectedForAppointment retpsa_ai_pi(int ai, int pi)
        {
            SqlCommand cmd = new SqlCommand("retpsa_ai_pi", connection);

            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter pmt = new SqlParameter("@pi", SqlDbType.Int);

            pmt.Value = pi;
            SqlParameter pmt2 = new SqlParameter("@ai", SqlDbType.Int);

            pmt2.Value = ai;
            cmd.Parameters.Add(pmt);
            cmd.Parameters.Add(pmt2);
            ProductsSelectedForAppointment item = null;

            connection.Open();
            var reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                item = new ProductsSelectedForAppointment()
                {
                    Id            = Convert.ToInt32(reader[0]),
                    AppointmentId = ai,
                    ProductId     = pi,
                    Count         = Convert.ToInt32(reader[3])
                };
            }
            connection.Close();
            return(item);
        }
        public async Task<IActionResult> IndexPost()
        {
            var shoppingCartList = HttpContext.Session.Get<List<int>>("shoppingCartSession");
            ShoppingCartViewModel.Appointment.AppointmentDate = ShoppingCartViewModel.Appointment.AppointmentDate
                .AddHours(ShoppingCartViewModel.Appointment.AppointmentTime.Hour)
                .AddMinutes(ShoppingCartViewModel.Appointment.AppointmentTime.Minute);

            Appointment appointment = ShoppingCartViewModel.Appointment;
            _context.Appointments.Add(appointment);
            await _context.SaveChangesAsync();

            foreach (int productId in shoppingCartList)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment
                {
                    AppointmentId = appointment.Id,
                    ProductId = productId
                };
                _context.ProductsSelectedForAppointments.Add(productsSelectedForAppointment);
            }
            await _context.SaveChangesAsync();
            shoppingCartList = new List<int>();
            HttpContext.Session.Set("shoppingCartSession", shoppingCartList);


            return RedirectToAction("AppointmentConfirm", "ShoppingCart", new { id = appointment.Id });
        }
예제 #11
0
        public async Task <IActionResult> IndexPost()
        {
            List <int> ListShoppingCart = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            if (ListShoppingCart.Count > 0)
            {
                ShoppingCartVM.Appointments.AppointmentDate = ShoppingCartVM.Appointments.AppointmentDate
                                                              .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                                                              .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute);
                Appointments appointments = ShoppingCartVM.Appointments;
                _db.Appointments.Add(appointments);
                _db.SaveChanges();

                int appointmentId = appointments.Id;
                foreach (var productId in ListShoppingCart)
                {
                    ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment
                    {
                        AppointmentId = appointmentId,
                        ProductId     = productId
                    };

                    _db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
                }
                _db.SaveChanges();
                //empty the list and set session of empty list again
                ListShoppingCart = new List <int>();
                HttpContext.Session.Set("ssShoppingCart", ListShoppingCart);


                return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
            }

            return(View(ShoppingCartVM));
        }
        public IActionResult IndexPost()
        {
            List <int> listCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            //Edited jquery-ui.js date format to make it dd/mm/yy

            ShoppingCartVM.Appointment.AppointmentDate = ShoppingCartVM.Appointment.AppointmentDate
                                                         .AddHours(ShoppingCartVM.Appointment.AppointmentTime.Hour)
                                                         .AddMinutes(ShoppingCartVM.Appointment.AppointmentTime.Minute);


            Appointment appointment = ShoppingCartVM.Appointment;

            this.db.Appointments.Add(appointment);
            this.db.SaveChanges();

            int appointmentId = appointment.Id;

            foreach (var productId in listCartItems)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId     = productId
                };
                this.db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
            }
            this.db.SaveChanges();
            listCartItems = new List <int>();
            HttpContext.Session.Set("ssShoppingCart", listCartItems);

            return(this.RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
        }
        public IActionResult IndexPost()
        {
            // Doing validation here since can't do with jquery due to the "Remove Item" button
            // I don't know why I have to rebuild ShoppingCartVM.products -- it shouldn't be null.
            if (ModelState.IsValid == false)
            {
                // need to rebuild shopping cart products.
                List<int> lstShoppingCart = HttpContext.Session.Get<List<int>>("ssShoppingCart");
                ShoppingCartVM = new ShoppingCartViewModel()
                {
                    Products = new List<Products>()
                };
                if (lstShoppingCart != null && lstShoppingCart.Count > 0)
                {
                    foreach (int cartItem in lstShoppingCart)
                    {
                        Products prod = _db.Products
                            .Include(p => p.SpecialTags)
                            .Include(p => p.ProductTypes)
                            .Where(p => p.Id == cartItem).FirstOrDefault();

                        ShoppingCartVM.Products.Add(prod);
                    }
                }
                return View(ShoppingCartVM);
            }


            List<int> lstCartItems = HttpContext.Session.Get<List<int>>("ssShoppingCart");
            ShoppingCartVM.Appointments.AppointmentDate = ShoppingCartVM.Appointments.AppointmentDate
                        .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                        .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute);

            Appointments appointments = ShoppingCartVM.Appointments;
            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            // now fill in ProductsSelectedForAppointment which are in the session object
            int appointmentId = appointments.Id;
            //ProductsSelectedForAppointment prods = new ProductsSelectedForAppointment(); can't have it up here -- always enters the last one!!
            foreach (var item in lstCartItems)
            {
                ProductsSelectedForAppointment prods = new ProductsSelectedForAppointment();
                prods.ProductId = item;
                prods.AppointmentId = appointmentId;
                _db.ProductsSelectedForAppointment.Add(prods);
                
            }
            _db.SaveChanges();
            // clear shopping cart in session
            lstCartItems = new List<int>();
            HttpContext.Session.Set("ssShoppingCart", lstCartItems);

            // return to main page.
            return RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId });

        }
예제 #14
0
        public async Task <IActionResult> Details(int id)
        {
            var menuItemFromDb = await _db.MenuItem.Include(m => m.ThongTinLoaiSanPham).Include(m => m.ThongTinSanPham).Where(m => m.Id == id).FirstOrDefaultAsync();

            ProductsSelectedForAppointment cartObj = new ProductsSelectedForAppointment()
            {
                MenuItem   = menuItemFromDb,
                MenuItemId = menuItemFromDb.Id
            };

            return(View(cartObj));
        }
예제 #15
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 }));
        }
        public IActionResult IndexPost()
        {
            List <int> lstCartItems = new List <int>();

            lstCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            if (lstCartItems != null)
            {
                foreach (int carItem in lstCartItems)
                {
                    Product prod = _db.Products.Include(p => p.Category).Where(p => p.ID == carItem).FirstOrDefault();
                    ShoppingCartVM.Products.Add(prod);
                }
            }


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

            Appointments appointments = ShoppingCartVM.Appointments;

            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            int appointmentId = appointments.ID;

            foreach (int productId in lstCartItems)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductID     = productId
                };
                _db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
            }
            _db.SaveChanges();
            lstCartItems = new List <int>();
            HttpContext.Session.Set("ssShoppingCart", lstCartItems);

            //return RedirectToAction("Index");
            return(RedirectToAction("AppoitmentConfirmation", "ShoppingCart", new { ID = appointmentId }));
        }
        public void inpsa(ProductsSelectedForAppointment input)
        {
            SqlCommand cmd = new SqlCommand("inpsa", connection);

            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter pmt1 = new SqlParameter("@AppointmentId", SqlDbType.Int);

            pmt1.Value = input.AppointmentId;
            SqlParameter pmt2 = new SqlParameter("@ProductId", SqlDbType.Int);

            pmt2.Value = input.ProductId;
            SqlParameter pmt3 = new SqlParameter("@Count", SqlDbType.Int);

            pmt3.Value = input.Count;
            cmd.Parameters.Add(pmt1);
            cmd.Parameters.Add(pmt2);
            cmd.Parameters.Add(pmt3);
            connection.Open();
            cmd.ExecuteNonQuery();
            connection.Close();
        }
        public IActionResult IndexPost()
        {
            //retrieve from session the list of cart items
            List <int> listCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            //merge appointment date and time to the apt object
            ShoppingCartVM.Appointments.AppointmentDate = ShoppingCartVM.Appointments.AppointmentDate
                                                          .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                                                          .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute);

            //create apt obj
            Appointments appointments = ShoppingCartVM.Appointments;

            //add apt to db
            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            //get id, use to insert onto table for products selected for the apt
            int appointmentId = appointments.Id;

            foreach (int productId in listCartItems)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId     = productId
                };

                _db.ProductSelectedForAppointment.Add(productsSelectedForAppointment);
            }

            _db.SaveChanges();

            //empty contents of cart and clear the session
            listCartItems = new List <int>();
            HttpContext.Session.Set("ssShoppingCart", listCartItems);

            return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
        }
예제 #19
0
        public async Task <IActionResult> Details(ProductsSelectedForAppointment CartObject)
        {
            CartObject.Id = 0;
            if (ModelState.IsValid)
            {
                var claimsIdentity = (ClaimsIdentity)this.User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                CartObject.AppointmentId = claim.Value;

                ProductsSelectedForAppointment cartFromDb = await _db.ProductsSelectedForAppointment.Where(c => c.AppointmentId == CartObject.AppointmentId &&
                                                                                                           c.MenuItemId == CartObject.MenuItemId).FirstOrDefaultAsync();

                if (cartFromDb == null)
                {
                    await _db.ProductsSelectedForAppointment.AddAsync(CartObject);
                }
                else
                {
                    cartFromDb.count = cartFromDb.count + CartObject.count;
                }
                await _db.SaveChangesAsync();

                var count = _db.ProductsSelectedForAppointment.Where(c => c.AppointmentId == CartObject.AppointmentId).ToList().Count();
                HttpContext.Session.SetInt32(SD.ssShoppingCartCount, count);
                return(RedirectToAction("Index"));
            }
            else
            {
                var menuItemFromDb = await _db.MenuItem.Include(m => m.ThongTinLoaiSanPham).Include(m => m.ThongTinSanPham).Where(m => m.Id == CartObject.MenuItemId).FirstOrDefaultAsync();

                ProductsSelectedForAppointment cartObj = new ProductsSelectedForAppointment()
                {
                    MenuItem   = menuItemFromDb,
                    MenuItemId = menuItemFromDb.Id
                };
                return(View(cartObj));
            }
        }
예제 #20
0
        public void CreateOrder(Appointments appointments)
        {
            var ShoppingCartItems = _shoppingCart.ShoppingCartItems;

            foreach (var items in ShoppingCartItems)
            {
                decimal newPrice = (items.Products.Price - ((items.Products.Price * items.Products.Discount) / 100));
                decimal Total    = (items.Products.Price * items.Amount);
                decimal newTotal = (newPrice * items.Amount);
                if (items.Products.Price > newPrice)
                {
                    var orderDetails = new ProductsSelectedForAppointment()
                    {
                        quantity      = items.Amount,
                        ProductId     = items.Products.Id,
                        AppointmentId = appointments.Id,
                        productName   = items.Products.Name,
                        price         = newPrice,
                        TotalQuantity = newTotal
                    };
                    _db.ProductsSelectedForAppointment.Add(orderDetails);
                }
                else
                {
                    var orderDetails = new ProductsSelectedForAppointment()
                    {
                        quantity      = items.Amount,
                        ProductId     = items.Products.Id,
                        AppointmentId = appointments.Id,
                        productName   = items.Products.Name,
                        price         = items.Products.Price,
                        TotalQuantity = Total
                    };
                    _db.ProductsSelectedForAppointment.Add(orderDetails);
                }
            }
            _db.SaveChanges();
        }
예제 #21
0
        public async Task <IActionResult> IndexPost()
        {
            Appointments scheduledAppointment = new Appointments
            {
                CustomerName        = ShoppingCartVM.Appointments.CustomerName,
                CustomerEmail       = ShoppingCartVM.Appointments.CustomerEmail,
                CustomerPhoneNumber = ShoppingCartVM.Appointments.CustomerPhoneNumber,
                AppointmentDate     = ShoppingCartVM.Appointments.AppointmentDate
                                      .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                                      .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute),
                IsConfirmed = false,
            };

            _db.Appointments.Add(scheduledAppointment);
            await _db.SaveChangesAsync();

            int appointmentId = scheduledAppointment.Id;

            List <int> lstShoppingCart = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            foreach (var item in lstShoppingCart)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId     = item
                };
                _db.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
            }
            await _db.SaveChangesAsync();

            // Emptying shopping cart list
            lstShoppingCart = new List <int>();

            HttpContext.Session.Set("ssShoppingCart", lstShoppingCart);
            return(RedirectToAction("AppointmentConfirmaion", "ShoppingCart", new { Id = appointmentId }));
        }
        public async Task <IActionResult> IndexPost()
        {
            List <string> lstShoppingCart = HttpContext.Session.Get <List <string> >(SD.SessionShoppingCartName);

            if (lstShoppingCart != null && lstShoppingCart.Count > 0)
            {
                CartsVM.Appointment.AppointmentDate = CartsVM.Appointment.AppointmentDate
                                                      .AddHours(CartsVM.Appointment.AppointmentTime.Hour)
                                                      .AddMinutes(CartsVM.Appointment.AppointmentTime.Minute);

                Appointments appointment = CartsVM.Appointment;
                _db.Appointments.Add(appointment);
                await _db.SaveChangesAsync();

                string appId = appointment.Id;

                foreach (string productId in lstShoppingCart)
                {
                    ProductsSelectedForAppointment selectedProduct = new ProductsSelectedForAppointment()
                    {
                        AppointmentId = appId,
                        ProductId     = productId
                    };

                    _db.ProductsSelectedForAppointment.Add(selectedProduct);
                }

                await _db.SaveChangesAsync();

                lstShoppingCart = new List <string>();
                HttpContext.Session.Set(SD.SessionShoppingCartName, lstShoppingCart);

                return(RedirectToAction("AppointmentConfirmation", "ShoppingCarts", new { id = appId }));
            }

            return(View(CartsVM));
        }
 public void include_pi_ai(ProductsSelectedForAppointment input)
 {
     input.Products     = retProduct(input.ProductId);
     input.Appointments = retAppointment(input.AppointmentId);
 }
예제 #24
0
        public async Task <IActionResult> IndexPost() // no need for parameters because we have already bind it
        {
            //claims
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);



            // retrieve list of items from session
            List <int> lstCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            // appointments time and dte
            ShoppingCartVM.Appointments.AppointmentDate = ShoppingCartVM.Appointments.AppointmentDate
                                                          .AddHours(ShoppingCartVM.Appointments.AppointmentTime.Hour)
                                                          .AddMinutes(ShoppingCartVM.Appointments.AppointmentTime.Minute);



            // create object for appointments
            Appointments appointments = ShoppingCartVM.Appointments;

            // get date from VM for customer to save it for appointment
            appointments.CustomerName        = ShoppingCartVM.CustomerUser.Name;
            appointments.CustomerEmail       = ShoppingCartVM.CustomerUser.Email;
            appointments.CustomerPhoneNumber = ShoppingCartVM.CustomerUser.PhoneNumber;



            // add this appointment to database

            _db.Appointments.Add(appointments);
            _db.SaveChanges();

            // once appointment is saved we will get appointment Id which is created

            int appointmentId = appointments.Id;


            // use Id to insert records inside product selected for appointment
            foreach (int productId in lstCartItems)
            {
                ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                {
                    AppointmentId = appointmentId,
                    ProductId     = productId
                };

                _db.ProductsSelectedForAppointments.Add(productsSelectedForAppointment);
            }


            // email  - Commented out in order not to spam during testing
            //TODO this is commented to prevent sending emails during development - uncomment for production -
            //await _emailSender.SendEmailAsync(_db.Users.Where(u => u.Id == claim.Value).FirstOrDefault().Email,
            //    "Open Properties - Your Appointment",
            //    "Your appointment was submitted successfully, a member of staff will be in touch shortly to confirm your appointment");

            Debug.WriteLine("Email Reached");

            _db.SaveChanges();
            // empty list cart items
            lstCartItems = new List <int>();
            // set session
            HttpContext.Session.Set("ssShoppingCart", lstCartItems);

            // once done redirect to confirmation page , controller is ShoppingCart and we need to pass the the ID of appointment
            return(RedirectToAction("AppointmentConfirmation", "ShoppingCart", new { Id = appointmentId }));
        }
예제 #25
0
        public IActionResult IndexPost()
        {
            // check first, if anything exists in the Session
            // Session Name : "ssScheduling"
            List <int> lstCartItems    = HttpContext.Session.Get <List <int> >("ssScheduling");
            List <int> lstCartServices = HttpContext.Session.Get <List <int> >("userServicesScheduling");

            // get the User's Culture
            int userLangId = CultureInfo.CurrentCulture.LCID;

            // LCID(1031) = DE
            if (userLangId == 1031)
            {
                SchedulingViewModel.Appointments.AppointmentDate = SchedulingViewModel.Appointments.AppointmentTime
                                                                   .AddHours(SchedulingViewModel.Appointments.AppointmentTime.Hour)
                                                                   .AddMinutes(SchedulingViewModel.Appointments.AppointmentTime.Minute);
            }
            else
            {
                // merge (add) the Appointment Date and Time to the Appointment Date itself
                SchedulingViewModel.Appointments.AppointmentDate = SchedulingViewModel.Appointments.AppointmentDate
                                                                   .AddHours(SchedulingViewModel.Appointments.AppointmentTime.Hour)
                                                                   .AddMinutes(SchedulingViewModel.Appointments.AppointmentTime.Minute);
            }


            // Security Claims
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;

            // Claims Identity
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            // add the current User as the Appointments Customer
            SchedulingViewModel.Appointments.CustomerId = claim.Value;
            // get the Customer's Properties
            SchedulingViewModel.Appointments.Customer = _colibriDbContext.ApplicationUsers
                                                        .FirstOrDefault(u => u.Id == SchedulingViewModel.Appointments.CustomerId);

            SchedulingViewModel.Appointments.CustomerName        = SchedulingViewModel.Appointments.Customer.UserName;
            SchedulingViewModel.Appointments.CustomerEmail       = SchedulingViewModel.Appointments.Customer.Email;
            SchedulingViewModel.Appointments.CustomerPhoneNumber = SchedulingViewModel.Appointments.Customer.PhoneNumber;

            // create an Object for the Appointments
            Appointments appointments = SchedulingViewModel.Appointments;

            // add the Appointments to the DB
            _colibriDbContext.Appointments.Add(appointments);
            _colibriDbContext.SaveChanges();

            // by saving one gets the Appointment Id that has been just created
            int appointmentId = appointments.Id;

            // this created Id can be used to insert Records inside the selected Products
            if (lstCartItems != null && lstCartItems.Any())
            {
                foreach (int productId in lstCartItems)
                {
                    // add the Product's Owner
                    SchedulingViewModel.Appointments.AppPersonId = _colibriDbContext.Products
                                                                   .FirstOrDefault(p => p.Id == productId).ApplicationUserId;


                    // everytime a new Object will be created
                    ProductsSelectedForAppointment productsSelectedForAppointment = new ProductsSelectedForAppointment()
                    {
                        AppointmentId = appointmentId,
                        ProductId     = productId
                    };

                    // add to the DB ProductsSelectedForAppointment
                    _colibriDbContext.ProductsSelectedForAppointment.Add(productsSelectedForAppointment);
                }

                // save the Changes all together after the Iteration
                _colibriDbContext.SaveChanges();

                // After adding the Items to the DB, empty the Cart (by creating a new Session)
                lstCartItems = new List <int>();
                HttpContext.Session.Set("ssScheduling", lstCartItems);
            }
            else if (lstCartServices != null && lstCartServices.Any())
            {
                // this created Id can be used to insert Records inside the selected Services
                foreach (int userServiceId in lstCartServices)
                {
                    // add the Product's Owner
                    SchedulingViewModel.Appointments.AppPersonId = _colibriDbContext.UserServices
                                                                   .FirstOrDefault(p => p.Id == userServiceId).ApplicationUserId;


                    // everytime a new Object will be created
                    UserServicesSelectedForAppointment userServicesSelectedForAppointment = new UserServicesSelectedForAppointment()
                    {
                        AppointmentId = appointmentId,
                        UserServiceId = userServiceId
                    };

                    // add to the DB ProductsSelectedForAppointment
                    _colibriDbContext.UserServicesSelectedForAppointment.Add(userServicesSelectedForAppointment);
                }

                // save the Changes all together after the Iteration
                _colibriDbContext.SaveChanges();

                // After adding the Items to the DB, empty the Cart (by creating a new Session)
                //lstCartItems = new List<int>();
                //HttpContext.Session.Set("ssScheduling", lstCartItems);
                lstCartServices = new List <int>();
                HttpContext.Session.Set("userServicesScheduling", lstCartServices);
            }

            // TODO
            // send Email: to the Customer and the Owner
            // build a Template mit Customers Details
            //_emailSender.SendEmailAsync(
            //    SchedulingViewModel.Appointments.CustomerEmail,
            //    "Your Order at Colibri",
            //    $"We are happy to inform you about your Order:" +
            //    $"OrderNo.: " + SchedulingViewModel.Products.FirstOrDefault().Id);

            // redirect to Action:
            // ActionMethod: AppointmentConfirmation
            // Controller: Scheduling
            // pass the Appointment ID
            return(RedirectToAction("AppointmentConfirmation", "Scheduling", new { Id = appointmentId }));
        }
예제 #26
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 }));
        }