예제 #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Tag).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TagExists(Tag.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
예제 #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Course = await _context.Courses.Include(x => x.Tags).FirstOrDefaultAsync(m => m.Id == FormCourse.Id);

            Course.Name        = FormCourse.Name;
            Course.Price       = FormCourse.Price;
            Course.Description = FormCourse.Description;

            Course.Tags.Clear();

            Course.Tags.Add(_context.Tags.Where(x => x.Name == "Default").First());
            foreach (int id in FormCourse.SelectedTags)
            {
                var tag = _context.Tags.Find(id);
                Course.Tags.Add(tag);
            }

            _context.Attach(Course).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(Course.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Index"));
        }