Beispiel #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(TrainingPartner).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TrainingPartnerExists(TrainingPartner.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync(int?id, string[]
                                                      selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var AntrenorToUpdate = await _context.Antrenor
                                   .Include(i => i.TrainingPartner)
                                   .Include(i => i.AntrenorCategories)
                                   .ThenInclude(i => i.Category)
                                   .FirstOrDefaultAsync(s => s.ID == id);

            if (AntrenorToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Antrenor>(
                    AntrenorToUpdate,
                    "Antrenor",
                    i => i.Name, i => i.Workout,
                    i => i.Price, i => i.PublishingDate, i => i.TrainingPartner))
            {
                UpdateAntrenorCategories(_context, selectedCategories, AntrenorToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateAntrenorCategories pentru a aplica informatiile din checkboxuri la entitatea Antrenors care
            //este editata
            UpdateAntrenorCategories(_context, selectedCategories, AntrenorToUpdate);
            PopulateAssignedCategoryData(_context, AntrenorToUpdate);
            return(Page());
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newAntrenor = new Antrenor();

            if (selectedCategories != null)
            {
                newAntrenor.AntrenorCategories = new List <AntrenorCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new AntrenorCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newAntrenor.AntrenorCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Antrenor>(
                    newAntrenor,
                    "Antrenor",
                    i => i.Name, i => i.Workout,
                    i => i.Price, i => i.PublishingDate, i => i.TrainingPartnerID))
            {
                _context.Antrenor.Add(newAntrenor);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newAntrenor);
            return(Page());
        }
Beispiel #4
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.TrainingPartner.Add(TrainingPartner);
            await _context.SaveChangesAsync();

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

            TrainingPartner = await _context.TrainingPartner.FindAsync(id);

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

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

            Category = await _context.Category.FindAsync(id);

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

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

            Antrenor = await _context.Antrenor.FindAsync(id);

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

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