Пример #1
0
        private async Task AddEventAsync()
        {
            var maxEventNumber = Events
                                 .Select(eventVm => Constants.Events.NewEventNameRegex.Match(eventVm.Event.Name))
                                 .Where(match => match.Success)
                                 .Select(match => int.Parse(match.Groups[1].Value))
                                 .DefaultIfEmpty(0)
                                 .Max();
            var nextAvailableNumber = maxEventNumber + 1;
            var @event = new Event($"{Constants.Events.NewEventNameBase}{nextAvailableNumber}");
            await _eventsRepository.AddEventAsync(@event).ConfigureAwait(true);

            var eventVm = new EventViewModel(@event);

            Events.Add(eventVm);
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Date,SemesterId,IsSpecial")] Event @event)
        {
            if (!ModelState.IsValid)
            {
                ViewData["SemestersSelectList"] = await CreateSemestersSelectList(@event.SemesterId);

                return(View(@event));
            }

            IActionResult result;

            try
            {
                await eventsRepository.AddEventAsync(@event);

                result = RedirectToAction(nameof(Index));
            }
            catch (Exception ex)
            {
                result = StatusCode(StatusCodes.Status500InternalServerError, ex);
            }
            return(result);
        }