Example #1
0
        public ActionResult AddCollaborator(CollaborateViewModel collaborate)
        {
            string searchedCollaborator = collaborate.InputCollaborator;

            try
            {
                ApplicationUser       searchedUser          = db.Users.First(x => x.UserName == searchedCollaborator);
                Tutorial              tut                   = db.Tutorials.First(x => x.Title == collaborate.TutorialSelection);
                CollaborativeTutorial collaborativeTutorial = new CollaborativeTutorial()
                {
                    Tutorial   = tut,
                    TutorialId = tut.ID,
                };
                collaborativeTutorial.Collaborators.Add(searchedUser);
                searchedUser.Collaborations.Add(collaborativeTutorial);
                db.Entry(searchedUser).State = EntityState.Modified;
                db.CollaborativeTutorials.Add(collaborativeTutorial);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (InvalidOperationException)
            {
                return(View(collaborate));
            }
        }
        public ActionResult CollaborateEdit(int?id)
        {
            var mpb   = Session["maphongban"] as string;
            var pb    = _dataService.PhongBanOne(mpb);
            var model = new CollaborateViewModel()
            {
                TuNgay          = DateTime.Now,
                DenNgay         = DateTime.Now,
                EmailNguoiDuyet = pb.email
            };

            if (id.HasValue)
            {
                model = _dataService.CollaborateOne(id.Value);
            }


            ViewData["ListCongTruong"] = _dataService.GetListCongTruong(new SearchCongTruongModel());
            return(PartialView("~/Views/Collaborate/Partials/CollaborateEdit.cshtml", model));
        }
Example #3
0
        public async Task <IActionResult> Collaborate(int id)
        {
            var collaborators = await _userProjectService.GetUserCollabsByProjectId(id);

            var nonCollaborators = await _userService.GetAll();

            nonCollaborators = nonCollaborators.Where(x => !collaborators.Contains(x));


            var vm = new CollaborateViewModel
            {
                Collaborators    = collaborators,
                NonCollaborators = nonCollaborators.Select(x => new SelectListItem {
                    Value = x.Id.ToString(), Text = x.LastName + ", " + x.FirstName
                })
                                   .OrderByDescending(x => x.Text),
                ProjectId     = id,
                Notifications = await _notificationService.GetAllByUserId(Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier)))
            };

            return(View(vm));
        }