Пример #1
0
        public IActionResult Create(AppointmentCreateVM model)
        {
            model.Clients  = new SelectList(GetClients(), "ClientId", "FirstName");
            model.Services = new SelectList(GetServices(), "ServiceId", "Name");

            if (!ModelState.IsValid)
            {
                return(View("Create", model));
            }
            try
            {
                Appointment appointment = new Appointment
                {
                    ApplicationUserId   = _userManager.GetUserId(HttpContext.User),
                    AppointmentStatusId = _context.AppointmentStatuses.Where(x => x.Name == "InProcess").FirstOrDefault().AppointmentStatusId,
                    ClientId            = model.ClientId,
                    SaloonId            = GetUserSalonId(),
                    StartTime           = model.StartTime,
                    EndTime             = model.EndTime,
                    Remark    = model.Remark,
                    IsDeleted = false
                };

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

                if (appointment.AppointmentId != 0)
                {
                    AppointmentService appointmentService = new AppointmentService
                    {
                        AppointmentId = appointment.AppointmentId,
                        ServiceId     = model.ServiceId,
                        Total         = SumTotal(model.ServiceId),
                        IsDeleted     = false
                    };

                    _context.AppointmentsServices.Add(appointmentService);
                    _context.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                throw;
            }


            return(RedirectToAction("Index"));
        }
Пример #2
0
        public IActionResult Create()
        {
            AppointmentCreateVM model = new AppointmentCreateVM
            {
                UserId              = _userManager.GetUserId(HttpContext.User),
                SalonName           = GetSalonName(),
                AppointmentStatusId = _context.AppointmentStatuses.Where(x => x.Name == "InProcess").FirstOrDefault().AppointmentStatusId,

                Clients   = new SelectList(GetClients(), "ClientId", "FirstName"),
                Services  = new SelectList(GetServices(), "ServiceId", "Name"),
                IsDeleted = false
            };

            return(View(model));
        }