示例#1
0
        public ActionResult AssignPerson([Bind(Include = "ProjectId,UserId,")] AssignPersonViewModel model)
        {
            if (ModelState.IsValid)
            {
                var resource = new ResourcePerson();
                resource.ProjectId = Int32.Parse(model.ProjectId);
                resource.UserId    = model.UserId;

                db.ResourcePersons.Add(resource);
                db.SaveChanges();
                return(RedirectToAction("AssignPerson", "Project"));
            }
            ModelState.AddModelError("", "Unable to assign resource person");
            return(View(model));
        }
示例#2
0
        public ActionResult AssignPerson()
        {
            AssignPersonViewModel model = new AssignPersonViewModel();

            var projects = db.Projects.OrderBy(s => s.Name).ToList();
            List <SelectListItem> projectList = new List <SelectListItem>();

            foreach (var item in projects)
            {
                projectList.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id.ToString()
                });
            }
            model.Projects = projectList;

            var adminRoleId = db.Roles.Where(r => r.Name == "IT Admin").Select(m => m.Id).SingleOrDefault();
            var users       = db.Users.Where(u => u.Roles.Any(r => r.RoleId != adminRoleId)).OrderBy(s => s.Name).ToList();

            List <SelectListItem> userList = new List <SelectListItem>();

            foreach (var item in users)
            {
                userList.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id
                });
            }
            model.Users = userList;

            var projectUserRole = (from project in db.Projects
                                   join resource in db.ResourcePersons on project.Id equals resource.ProjectId
                                   join user in db.Users on resource.UserId equals user.Id
                                   select new ResourcePersonViewModel
            {
                ProjectName = project.Name,
                ResourcePerson = user.Name,
                Designation = db.Roles.Where(s => s.Users.Any(u => u.UserId == user.Id)).FirstOrDefault().Name
            }).ToList();

            model.ResourcePersons = projectUserRole;

            return(View(model));
        }
示例#3
0
        public ActionResult <bool> AsignToGroup(AssignPersonViewModel model)
        {
            var oldperson = _personService.GetPerson(model.PersonId);

            if (oldperson == null)
            {
                return(BadRequest("Таку людину не знайдено"));
            }
            if (model.IsAssigne)
            {
                oldperson.HomeGroupId = model.GroupId;
            }
            else
            {
                oldperson.HomeGroupId = null;
            }

            return(Ok(_personService.UpdatePerson(oldperson)));
        }