public async Task <IActionResult> Add([Bind("")] PersonAddModel personAddModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Your information is don't valid");
                return(View("Add"));
            }

            personAddModel.Person.IsPersonActive = true;
            // IsActivePerson'a özel güzel bir süreç oluştur.

            try
            {
                var result = await _schoolDataDbContext.AddAsync(personAddModel.Person);

                await _schoolDataDbContext.SaveChangesAsync();

                return(RedirectToAction("List"));
            }
            catch (DbUpdateException error)
            {
                ModelState.AddModelError(string.Empty, "Unable to save changes" + "\n Message:" + error.Message.ToString() + "Inner Exception:" + error.InnerException.ToString());
            }
            return(View(personAddModel));
        }
Пример #2
0
        public async Task <IActionResult> Add([Bind("Name")] LessonManagerModel lessonAddModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Your information is don't valid");
                return(View("Add"));
            }
            try
            {
                var result = await _schoolDataDbContext.AddAsync(lessonAddModel.Lesson);

                await _schoolDataDbContext.SaveChangesAsync();

                return(RedirectToAction("List"));
            }
            catch (DbUpdateException error)
            {
                ModelState.AddModelError(string.Empty, "Unable to save changes" + "\n Message:" + error.Message.ToString() + "Inner Exception:" + error.InnerException.ToString());
            }
            return(View(lessonAddModel));
        }
        public async Task <IActionResult> Add(HomeworkManagerModel homeworkManagerModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Validation is not reasonable");
                return(View(homeworkManagerModel));
            }

            try
            {
                await _schoolDataDbContext.HomeworkDescriptions.AddAsync(homeworkManagerModel.Homework);

                await _schoolDataDbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(RedirectToAction("List"));
        }