示例#1
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,Location,Image")] Event @event)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
        public async Task <IActionResult> Create([Bind("Id,AdminID,Title,Date,Message")] Notification notification)
        {
            if (ModelState.IsValid)
            {
                _context.Add(notification);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(notification));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Course,Password,Email")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("Id,StudentID,EventID,Date,Title,PostMessage")] Post post)
        {
            if (ModelState.IsValid)
            {
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventID"]   = new SelectList(_context.Events, "Id", "Id", post.EventID);
            ViewData["StudentID"] = new SelectList(_context.Students, "Id", "Course", post.StudentID);
            return(View(post));
        }
示例#5
0
        [ValidateAntiForgeryToken]              //took out AdminID
        public async Task <IActionResult> Create([Bind("Name,Chairperson,Secretary,Treasurer,Phone,Email,Description")] ClubsAndSociety clubsAndSociety)
        {
            /*
             * This try catch adds the ClubsAndSocieties entity created by the ASP.NET MVC
             * model binder to the ClubsAndSocieties entity set and then saves the
             * changes to the database. (Model binder refers to the ASP.NET
             * MVC functionality that makes it easier for you to work with
             * data submitted by a form; a model binder converts posted
             * form values to CLR types and passes them to the action
             * method in parameters. In this case, the model binder
             * instantiates a ClubsAndSociety entity for you using property values
             * from the Form collection.)
             */
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(clubsAndSociety);
                    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.");
            }
            if (ModelState.IsValid)
            {
                _context.Add(clubsAndSociety);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clubsAndSociety));
        }