示例#1
0
        public async Task <ActionResult> Create([Bind(Include = "LastName, FirstMidName, EnrollmentDate")] Student student, HttpPostedFileBase picture)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var userPicture = await userPictureService.CreateUserPictureAsync(picture);

                    if (userPicture != null)
                    {
                        student.UserPicture = userPicture;
                    }

                    db.Students.Add(student);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(student));
        }
示例#2
0
        public async Task <IActionResult> Create(
            [Bind("EnrollmentDate,FirstMidName,LastName")] Student student, IFormFile picture)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var userPicture = await userPictureService.CreateUserPictureAsync(picture);

                    if (userPicture != null)
                    {
                        student.UserPicture = userPicture;
                    }

                    context.Add(student);
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(student));
        }