Пример #1
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,DayOfWeek,HourStart,HourEnd")] FreeTime freeTime)
        {
            if (id != freeTime.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    freeTime.Name = $"Day {freeTime.DayOfWeek}, {freeTime.HourStart}-{freeTime.HourEnd}";
                    _context.Update(freeTime);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FreeTimeExists(freeTime.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(freeTime));
        }
Пример #2
0
 public FreeTimeViewModel FromFreeTime(FreeTime f)
 {
     Id        = f.Id;
     Name      = f.Name;
     DayOfWeek = f.DayOfWeek;
     HourStart = f.HourStart;
     HourEnd   = f.HourEnd;
     return(this);
 }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,DayOfWeek,HourStart,HourEnd,CreatedAt,CreatedBy,UpdatedAt,UpdatedBy")] FreeTime freeTime)
        {
            if (ModelState.IsValid)
            {
                freeTime.Name = $"Day {freeTime.DayOfWeek}, {freeTime.HourStart}-{freeTime.HourEnd}";
                _context.Add(freeTime);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(freeTime));
        }