Ejemplo n.º 1
0
        public ActionResult AddGr(AddGroupsViewModel model, int?gid)
        {
            string          selU  = Request.Form["selUser"].ToString();
            ApplicationUser user  = db.Users.Where(u => u.Id == selU).Single();
            string          role  = Request.Form["roleSel"].ToString();
            Group           addGr = db.Groups.Where(g => g.GId == gid).Single();

            if (db.GroupPersons.Where(gg => gg.Group.GId == addGr.GId && gg.User.Id == user.Id).SingleOrDefault() != null)
            {
                return(RedirectToAction("AddGroupsParam", "Home", new { @gid = gid }));
            }

            GroupPerson gp = new GroupPerson();

            if (!db.GroupPersons.Any())
            {
                gp.Gpid = 1;
            }
            if (db.GroupPersons.Any())
            {
                gp.Gpid = db.GroupPersons.Max(grp => grp.Gpid) + 1;
            }
            gp.Group  = addGr;
            gp.User   = user;
            gp.Role   = role;
            gp.Status = "Invitation";
            user.Groups.Add(gp);
            addGr.Users.Add(gp);
            db.Users.Attach(user);
            db.Groups.Attach(addGr);
            db.GroupPersons.Add(gp);
            db.SaveChanges();
            return(RedirectToAction("GroupManagement", "Home", new { @gid = gid }));
        }
Ejemplo n.º 2
0
        public virtual async Task <ActionResult> Create(AddGroupsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var adv = new Groups
                    {
                        Name    = viewModel.Name,
                        Manager = viewModel.Manager
                    };
                    _GroupsService.Insert(adv);
                    await _unitOfWork.SaveChangesAsync();

                    CacheManager.InvalidateChildActionsCache();
                    return(RedirectToAction("Index", "Department"));
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException e)
                {
                    string s = "";
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        s += String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                           eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            s += String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                               ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    ViewBag.err = s;
                }
            }
            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult AddGroups(int?gid)
        {
            var model = new AddGroupsViewModel();

            model.Users   = db.Users.ToList();
            model.GroupId = (int)gid;
            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult AddGroupsParam(int?gid)
        {
            var model = new AddGroupsViewModel();

            model.Users   = db.Users.ToList();
            model.GroupId = (int)gid;
            ModelState.AddModelError("Error", @"This person is already in this group, invited to this group, or recently refused invite to this group");
            return(View("addGroups", model));
        }