public async Task <IActionResult> Edit(int id, [Bind("Id,Text,Date,Sender,Receiver")] Messages messages)
        {
            if (id != messages.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(messages);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MessagesExists(messages.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Receiver"] = new SelectList(_context.UserLocator, "Id", "UserLoginEmail", messages.Receiver);
            ViewData["Sender"]   = new SelectList(_context.UserLocator, "Id", "UserLoginEmail", messages.Sender);
            return(View(messages));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("Loid,Name,Description,CourseInstanceId")] LearningOutcomes learningOutcomes)
        {
            if (id != learningOutcomes.Loid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try {
                    _context.Update(learningOutcomes);
                    await _context.SaveChangesAsync();
                } catch (DbUpdateConcurrencyException) {
                    if (!LearningOutcomesExists(learningOutcomes.Loid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseInstanceId"] = new SelectList(_context.CourseInstance, "CourseInstanceId", "Department", learningOutcomes.CourseInstanceId);
            return(View(learningOutcomes));
        }
 public async Task <IActionResult> Edit(int id, [Bind("CourseInstanceId,Name,Description,Department,Number,Semester,Year,StatusId,DueDate")] CourseInstance courseInstance, string[] newInstructors)
 {
     if (id != courseInstance.CourseInstanceId)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         try {
             if (newInstructors != null)
             {
                 List <Instructors> currentCourseInstructors = _context.Instructors.Include(i => i.User).Where(i => i.CourseInstanceId == courseInstance.CourseInstanceId).ToList();
                 //Remove current instructors
                 foreach (Instructors currentInst in currentCourseInstructors)
                 {
                     _context.Instructors.Remove(currentInst);
                 }
                 foreach (string newInstructor in newInstructors)
                 {
                     //Find selected instructor
                     UserLocator instructorUserLoc = _context.UserLocator.Where(u => u.UserLoginEmail == newInstructor).FirstOrDefault();
                     if (instructorUserLoc != null)   //User must exist
                     {
                         Instructors newInst = new Instructors()
                         {
                             CourseInstanceId = courseInstance.CourseInstanceId,
                             UserId           = instructorUserLoc.Id
                         };
                         _context.Instructors.Add(newInst);
                     }
                 }
             }
             _context.Update(courseInstance);
             await _context.SaveChangesAsync();
         } catch (DbUpdateConcurrencyException) {
             if (!CourseInstanceExists(courseInstance.CourseInstanceId))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     //ViewData["CourseInstanceId"] = new SelectList(_context.CourseInstance, "CourseInstanceId", "Department", courseInstance.CourseInstanceId);
     //return View(courseInstance);
     return(View(new CourseEditData()
     {
         Course = _context.CourseInstance.Where(c => c.CourseInstanceId == id).Include(c => c.Instructors).ThenInclude(i => i.User).FirstOrDefault(),
         Departments = _context.Departments,
         CourseStatus = _context.CourseStatus,
         Professors = GetInstructors()
     }));
 }
示例#4
0
        public async Task <IActionResult> Edit(string code, string name)
        {
            if (code == null)
            {
                return(NotFound());
            }
            var dept = _context.Departments.Where(d => d.Code == code).FirstOrDefault();

            if (dept == null)
            {
                return(NotFound());
            }
            dept.Name = name;
            _context.Update(dept);
            _context.SaveChanges();
            return(RedirectToAction("Edit", new { code = code }));
        }