public async Task <IActionResult> Details(Guid?serviceId, Guid?eventId)
        {
            if (serviceId == null || eventId == null)
            {
                return(NotFound());
            }
            try
            {
                var serviceEvent = await _context.ServiceEvents
                                   .Include(x => x.Event)
                                   .FirstOrDefaultAsync(x => x.EventId == eventId.Value && x.ServiceId == serviceId.Value);

                if (serviceEvent == null)
                {
                    return(NotFound());
                }
                var vm = new ServiceEventViewModel();
                vm = Mapper.Map(serviceEvent, vm);
                vm.EvenSchedule = await _context.EvenSchedules
                                  .Include(x => x.ServicePlace)
                                  .Where(x => x.EventId == vm.EventId && x.ServiceId == vm.ServiceId && x.UserId == GetCurrentUserId()).ToListAsync();

                return(View(vm));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, CommonC.ErrorLoad);
                TempData["ErrorMessage"] = CommonC.ErrorLoad;
            }
            return(RedirectToAction("Details", "Services", new { @id = serviceId }));
        }
 public async Task <IActionResult> Create(ServiceEventViewModel serviceEventViewModel)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var serviceEvent = Mapper.Map <ServiceEventViewModel, ServiceEvent>(serviceEventViewModel);
             _context.Add(serviceEvent);
             await _context.SaveChangesAsync();
         }
         catch (Exception e)
         {
             _logger.LogError(e.Message, CommonC.ErrorCreate);
             TempData["ErrorMessage"] = CommonC.ErrorCreate;
         }
         return(RedirectToAction("Details", "Services", new { @id = serviceEventViewModel.ServiceId }));
     }
     try
     {
         ViewData["EventId"] = new SelectList(
             _context.Events.Where(x => x.UserId == GetCurrentUserId() && !x.ServiceEvents.Any(y => y.ServiceId == serviceEventViewModel.ServiceId)),
             "Id", "Name", serviceEventViewModel.EventId);
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message, CommonC.ErrorLoad);
         TempData["ErrorMessage"] = CommonC.ErrorLoad;
     }
     return(View(serviceEventViewModel));
 }
        public void SaveServiceEvent(ServiceEventViewModel model)
        {
            var se  = model.GetServiceEvent();
            var car = GetCarByIdWithLists(model.CarId);

            car.ServiceEvents.Add(se);
            Context.SaveChanges();
        }
Beispiel #4
0
        public IActionResult ServiceEventDetail(int id)
        {
            var s = new ServiceEventViewModel()
            {
                CarId = id
            };

            return(View(s));
        }
Beispiel #5
0
        public IActionResult ServiceEventDetail(ServiceEventViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _unitOfWork.SaveServiceEvent(model);
            return(View("ServiceEventList", _unitOfWork.GetCarByIdWithLists(model.CarId)));
        }
        public IActionResult Create(Guid serviceId)
        {
            ViewData["EventId"] = new SelectList(
                _context.Events.Where(x => x.UserId == GetCurrentUserId() && !x.ServiceEvents.Any(y => y.ServiceId == serviceId))
                , "Id", "Name");
            var viewModel = new ServiceEventViewModel()
            {
                ServiceId = serviceId
            };

            return(View(viewModel));
        }