예제 #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, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Course course = new()
            {
                Id          = Course.Id,
                Name        = Course.Name,
                Price       = Course.Price,
                Description = Course.Description
            };

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

            _context.Courses.Add(course);
            await _context.SaveChangesAsync();

            return(RedirectToPage("/Index"));
        }
    }
예제 #3
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Tags.Add(Tag);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Tag = await _context.Tags.FindAsync(id);

            if (Tag != null)
            {
                _context.Tags.Remove(Tag);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Course = await _context.Courses.FindAsync(id);

            if (Course != null)
            {
                _context.Courses.Remove(Course);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/Index"));
        }
예제 #6
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"));
        }