Beispiel #1
0
        public async Task <IActionResult> Create(NurserySchool school)
        {
            if (this.ModelState.IsValid)
            {
                await this.schoolsRepository.AddAsync(school);

                await this.schoolsRepository.SaveChangesAsync();

                return(this.RedirectToAction(nameof(this.Index)));
            }

            return(this.View(school));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, SchoolInputModel input)
        {
            if (id != input.Id)
            {
                return(this.NotFound());
            }

            var currentSchool = this.schoolsRepository.AllAsNoTracking()
                                .FirstOrDefault(x => x.Id == id);

            var school = new NurserySchool
            {
                Id         = id,
                Name       = input.Name,
                Address    = input.Address,
                CreatedOn  = currentSchool.CreatedOn,
                ModifiedOn = input.ModifiedOn,
                DeletedOn  = currentSchool.DeletedOn,
                IsDeleted  = currentSchool.IsDeleted,
            };

            if (this.ModelState.IsValid)
            {
                try
                {
                    this.schoolsRepository.Update(school);
                    await this.schoolsRepository.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!this.SchoolExists(input.Id))
                    {
                        return(this.NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(this.RedirectToAction(nameof(this.Index)));
            }

            return(this.View(school));
        }