Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
 public FreeTimeViewModel FromFreeTime(FreeTime f)
 {
     Id        = f.Id;
     Name      = f.Name;
     DayOfWeek = f.DayOfWeek;
     HourStart = f.HourStart;
     HourEnd   = f.HourEnd;
     return(this);
 }
Ejemplo n.º 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));
        }