コード例 #1
0
        public async Task <IActionResult> Create(JoinClassInfor joinClassInfor)
        {
            if (ModelState.IsValid)
            {
                AppUser currentUser = await userManager.FindByNameAsync(HttpContext.User.Identity.Name);

                joinClassInfor.NewClass.User = currentUser;

                joinClassInfor.NewClass.isActive = true;
                //joinClassInfor.NewClass.HOC = hoc;
                _context.Classes.Add(joinClassInfor.NewClass);
                RoomDocument roomD = new RoomDocument
                {
                    ClassInfoID = joinClassInfor.NewClass.ClassID
                };
                _context.RoomDocuments.Add(roomD);
                RoomMember roomM = new RoomMember
                {
                    ClassID = joinClassInfor.NewClass.ClassID
                };
                _context.RoomMembers.Add(roomM);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Room", "Room", joinClassInfor.NewClass));
            }
            return(View());
        }
コード例 #2
0
        public IActionResult Create()
        {
            IEnumerable <Classes> classes        = _context.Classes;
            JoinClassInfor        joinClassInfor = new JoinClassInfor();

            joinClassInfor.AvailableClasses = classes.Where(c => c.isActive == true);
            joinClassInfor.AvailableClasses.ToList().ForEach(c =>
            {
                c.User = _context.Users.SingleOrDefault(u => u.Id == c.UserId);
            });
            return(View(joinClassInfor));
        }
コード例 #3
0
 public IActionResult Join(JoinClassInfor joinClassInfor)
 {
     if (ModelState.IsValid)
     {
         Classes cls = _context.Classes.Find(joinClassInfor.NewClass.ClassID);
         if (cls == null)
         {
             return(RedirectToAction("Create", "JoinClass", joinClassInfor));
         }
         else
         {
             return(RedirectToAction("Room", "Room", cls));
         }
     }
     return(View(joinClassInfor));
 }