Beispiel #1
0
        public async Task <IActionResult> Create(EvenSchedule evenSchedule)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    evenSchedule.Id = Guid.NewGuid();
                    var serviceEvent = _context.ServiceEvents.FirstOrDefaultAsync(x => x.EventId == evenSchedule.EventId && x.ServiceId == evenSchedule.ServiceId);
                    if (serviceEvent == null)
                    {
                        ModelState.AddModelError("", "A kiválasztott esemény nincs a megadott szolgáltatásban.");
                        ViewData["EventId"]        = new SelectList(_context.Events.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.EventId);
                        ViewData["ServiceId"]      = new SelectList(_context.Services.Where(x => x.UserId == CurrentUserId), "Id", "City", evenSchedule.ServiceId);
                        ViewData["ServicePlaceId"] = new SelectList(_context.ServicePlaces.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.ServicePlaceId);
                        return(View(evenSchedule));
                    }
                    evenSchedule.UserId = GetCurrentUserId();
                    _context.Add(evenSchedule);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message, CommonC.ErrorCreate);
                    TempData["ErrorMessage"] = CommonC.ErrorCreate;
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"]        = new SelectList(_context.Events.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.EventId);
            ViewData["ServiceId"]      = new SelectList(_context.Services.Where(x => x.UserId == CurrentUserId), "Id", "City", evenSchedule.ServiceId);
            ViewData["ServicePlaceId"] = new SelectList(_context.ServicePlaces.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.ServicePlaceId);
            return(View(evenSchedule));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(Guid id, EvenSchedule evenSchedule)
        {
            if (id != evenSchedule.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var serviceEvent = _context.ServiceEvents.FirstOrDefaultAsync(x => x.EventId == evenSchedule.EventId && x.ServiceId == evenSchedule.ServiceId);
                    if (serviceEvent == null)
                    {
                        ModelState.AddModelError("", "A kiválasztott esemény nincs a megadott szolgáltatásban.");
                        ViewData["EventId"]        = new SelectList(_context.Events.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.EventId);
                        ViewData["ServiceId"]      = new SelectList(_context.Services.Where(x => x.UserId == CurrentUserId), "Id", "City", evenSchedule.ServiceId);
                        ViewData["ServicePlaceId"] = new SelectList(_context.ServicePlaces.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.ServicePlaceId);
                        return(View(evenSchedule));
                    }
                    _context.Update(evenSchedule);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EvenScheduleExists(evenSchedule.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message, CommonC.ErrorEdit);
                    TempData["ErrorMessage"] = CommonC.ErrorEdit;
                }
                return(RedirectToAction(nameof(Index)));
            }
            try
            {
                ViewData["EventId"]        = new SelectList(_context.Events.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.EventId);
                ViewData["ServiceId"]      = new SelectList(_context.Services.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.ServiceId);
                ViewData["ServicePlaceId"] = new SelectList(_context.ServicePlaces.Where(x => x.UserId == CurrentUserId), "Id", "Name", evenSchedule.ServicePlaceId);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, CommonC.ErrorLoad);
                TempData["ErrorMessage"] = CommonC.ErrorLoad;
            }
            return(View(evenSchedule));
        }