Beispiel #1
0
        public async Task <IActionResult> Edit(int id, AppointmentDetailsViewModel appointmentViewModel)
        {
            if (ModelState.IsValid)
            {
                // combine the Appointment Date and Time (inside the Appointment Date)
                appointmentViewModel.Appointment.AppointmentDate = appointmentViewModel.Appointment.AppointmentDate
                                                                   .AddHours(appointmentViewModel.Appointment.AppointmentTime.Hour)
                                                                   .AddMinutes(appointmentViewModel.Appointment.AppointmentTime.Minute);

                // retrieve the Appointment Object from the DB
                var appointmentFromDb = await _colibriDbContext.Appointments
                                        .Where(a => a.Id == appointmentViewModel.Appointment.Id)
                                        .FirstOrDefaultAsync();

                // update individual Properties
                appointmentFromDb.CustomerName        = appointmentViewModel.Appointment.CustomerName;
                appointmentFromDb.CustomerEmail       = appointmentViewModel.Appointment.CustomerEmail;
                appointmentFromDb.CustomerPhoneNumber = appointmentViewModel.Appointment.CustomerPhoneNumber;
                appointmentFromDb.AppointmentDate     = appointmentViewModel.Appointment.AppointmentDate;
                appointmentFromDb.isConfirmed         = appointmentViewModel.Appointment.isConfirmed;

                // only the SuperAdmin can change this Information
                if (User.IsInRole(StaticDetails.SuperAdminEndUser))
                {
                    appointmentFromDb.AppPersonId = appointmentViewModel.Appointment.AppPersonId;
                }

                // save into the DB
                _colibriDbContext.SaveChanges();

                // redirect
                return(RedirectToAction(nameof(Index)));
            }

            // return View
            return(View(appointmentViewModel));
        }
Beispiel #2
0
 public CategoryTypes Add(CategoryTypes categoryTypes)
 {
     _context.CategoryTypes.Add(categoryTypes);
     _context.SaveChanges();
     return(categoryTypes);
 }
Beispiel #3
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 }));
        }