예제 #1
0
        private CalcViewModel InitCalcViewModel()
        {
            var parts = new CalcViewModel {
                Parts = _buildingPartRepository.GetAll(),
                DefectDescriptions = _defectDescriptionRepository.GetAll(),
                DefectImportances  = _defectImportanceRepository.GetAll(),
                DefectIntencities  = _defectIntencityRepository.GetAll(),
                DefectExtents      = _defectExtentRepository.GetAll(),
                Actions            = _actionRepository.GetAll(),
                StartYear          = 2014
            };

            // Eenh enum
            IEnumerable <Eenh> eenhsTypes = Enum.GetValues(typeof(Eenh)).Cast <Eenh>();

            parts.EenhList = from eenh in eenhsTypes
                             select new SelectListItem
            {
                Text  = eenh.ToString(),
                Value = ((int)eenh).ToString()
            };

            // Taxes enum
            IEnumerable <Taxe> taxeTypes = Enum.GetValues(typeof(Taxe)).Cast <Taxe>();

            parts.TaxeList = from taxe in taxeTypes
                             select new SelectListItem
            {
                Text  = taxe.ToString(),
                Value = ((int)taxe).ToString()
            };

            return(parts);
        }
예제 #2
0
        public ActionResult New()
        {
            ScriptViewModel vmPlane = new ScriptViewModel();

            vmPlane.AllActions = _ActionRepository.GetAll(true);
            _PreferenceRepository.LoadBasePreferences(vmPlane);
            return(View(vmPlane));
        }
        public void TestActionRepo_GetAll()
        {
            var actions = _actionRepository.GetAll();

            //  actions dans le jeu de données de test
            Assert.AreEqual(27, actions.Count);
            var actual = actions.Select(action => action.Nom).ToList();
            // Nom des actions
            var expected = new List <string> {
                "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjouterSouhait", "AjouterSouhait", "AjouterSouhait", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché", "AjoutMarché"
            };

            CollectionAssert.AreEquivalent(actual, expected);
        }
예제 #4
0
        public ActionResult CreateUserPermission(NewAppUserPermissionViewModel model)
        {
            using (var context = new AppSecurityContext())
            {
                var actionRepository         = new ActionRepository(context);
                var permissionRepository     = new PermissionRepository(context);
                var userPermissionRepository = new UserPermissionRepository(context);
                var userRepository           = new UserRepository(context);

                try
                {
                    var actions    = actionRepository.Query(x => model.SelectedActions.Contains(x.Key)).Select(x => x.Key);
                    var permission = permissionRepository
                                     .GetAll()
                                     .Where(x => x.ResourceKey == model.SelectedResource)
                                     .Where(x => actions.Contains(x.ActionKey));

                    userPermissionRepository.AddPermissionsByUserId(model.User.Id, permission.Select(x => x.Id).ToArray());
                    context.SaveChanges();
                    return(RedirectToAction("UserPermission", new { id = model.User.Id }));
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                    var actions = actionRepository.GetAll().OrderBy(x => x.Name);
                    var user    = userRepository.Find(model.User.Id);
                    model.User             = mapper.Map <AppUserViewModel>(user);
                    model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);
                    model.ResourcesList    = PopulateResourceFromNewUserPermission(model.SelectedResource);
                    return(View(model));
                }
            }
        }
예제 #5
0
        public ActionResult CreateUserPermission(string id)
        {
            var model = new NewAppUserPermissionViewModel();

            using (var context = new AppSecurityContext())
            {
                var resourcesRepository    = new ResourceRepository(context);
                var userPermissionRository = new UserPermissionRepository(context);
                var userRepository         = new UserRepository(context);
                var actionRepository       = new ActionRepository(context);

                var user = userRepository.Find(id);
                if (user == null)
                {
                    RedirectToAction("Users");
                }

                var actions = actionRepository.GetAll().OrderBy(x => x.Name);
                model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);
                model.User             = mapper.Map <AppUserViewModel>(user);
                model.ResourcesList    = PopulateResourceFromNewUserPermission(id);

                return(View(model));
            }
        }
예제 #6
0
        public ActionResult EditPermission(string id)
        { //Clave del resource
            var model = new EditAppPermissionViewModel();

            using (var context = new AppSecurityContext())
            {
                var actionRepository     = new ActionRepository(context);
                var resourceRepository   = new ResourceRepository(context);
                var permissionRepository = new PermissionRepository(context);
                try
                {
                    var actions     = actionRepository.GetAll();
                    var resource    = resourceRepository.Find(id);
                    var permissions = permissionRepository.GetAll().Where(x => x.ResourceKey == resource.Key);
                    var actionKeys  = permissions.Select(x => x.ActionKey).ToArray();
                    model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);
                    model.SelectedActions  = actionKeys;
                    model.ResourceKey      = resource.Key;
                    model.ResourceName     = resource.Name;

                    return(View(model));
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                    return(View(model));
                }
            }
        }
예제 #7
0
 public ActionResult CreatePermission(NewAppPermissionViewModel model)
 {
     using (var context = new AppSecurityContext())
     {
         var actionRepository     = new ActionRepository(context);
         var resourceRepository   = new ResourceRepository(context);
         var permissionRepository = new PermissionRepository(context);
         try
         {
             var resource = resourceRepository.Find(model.SelectedResource);
             var actions  = actionRepository.Query(x => model.SelectedActions.Contains(x.Key));
             foreach (var action in actions)
             {
                 var permission = new AppPermission();
                 permission.Action   = action;
                 permission.Resource = resource;
                 permissionRepository.Add(permission);
             }
             context.SaveChanges();
             return(RedirectToAction("Permissions"));
         }
         catch (Exception ex)
         {
             ViewBag.Error = ex.Message;
             var actions = actionRepository.GetAll().OrderBy(x => x.Name);
             model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);
             model.ResourcesList    = PopulateResourcesForNewPermission(model.SelectedResource);
             return(View(model));
         }
     }
 }
예제 #8
0
 public ActionResult Actions()
 {
     using (var context = new AppSecurityContext())
     {
         var repository = new ActionRepository(context);
         var actions    = repository.GetAll();
         var model      = mapper.Map <IEnumerable <AppActionViewModel> >(actions);
         return(View(model));
     }
 }
예제 #9
0
        public ActionResult EditPermission(string id, EditAppPermissionViewModel model)
        { //Clave del resource
            using (var context = new AppSecurityContext())
            {
                var actionRepository     = new ActionRepository(context);
                var resourceRepository   = new ResourceRepository(context);
                var permissionRepository = new PermissionRepository(context);
                try
                {
                    var actions     = actionRepository.GetAll();
                    var resource    = resourceRepository.Find(id);
                    var permissions = permissionRepository.GetAll().Where(x => x.ResourceKey == resource.Key);
                    var actionKeys  = permissions.Select(x => x.ActionKey).ToArray();
                    model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);

                    //Se eliminan los permisos anteriores
                    foreach (var perm in permissions)
                    {
                        permissionRepository.Delete(perm);
                    }

                    if (model.SelectedActions != null)
                    {
                        //Se agregan los nuevos
                        var actionsForInsert = actionRepository.Query(x => model.SelectedActions.Contains(x.Key));
                        foreach (var action in actionsForInsert)
                        {
                            var permission = new AppPermission();
                            permission.Action   = action;
                            permission.Resource = resource;
                            permissionRepository.Add(permission);
                        }
                        model.SelectedActions = actionKeys;
                        model.ResourceKey     = resource.Key;
                        model.ResourceName    = resource.Name;
                    }
                    context.SaveChanges();
                    return(RedirectToAction("Permissions"));
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                    if (ex.InnerException != null)
                    {
                        ViewBag.Error += ex.InnerException.Message;
                    }
                    return(View(model));
                }
            }
        }
예제 #10
0
        public ActionResult CreatePermission()
        {
            var model = new NewAppPermissionViewModel();

            using (var context = new AppSecurityContext())
            {
                var actionRepository = new ActionRepository(context);
                var actions          = actionRepository.GetAll().OrderBy(x => x.Name);

                model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);
                model.ResourcesList    = PopulateResourcesForNewPermission(model.SelectedResource);
                return(View(model));
            }
        }
예제 #11
0
        public ActionResult EditUserPermission(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("DetailsUserPermission"));
            }

            var model = new EditAppUserPermissionViewModel();

            using (var context = new AppSecurityContext())
            {
                var actionRepository       = new ActionRepository(context);
                var resourceRepository     = new ResourceRepository(context);
                var userPermissionRository = new UserPermissionRepository(context);
                var userRepository         = new UserRepository(context);

                var userPermision = userPermissionRository.GetAll().Where(x => x.Id == id).FirstOrDefault();
                var resource      = resourceRepository.Find(userPermision.Permission.ResourceKey);

                var userPermissions = userPermissionRository.GetAll()
                                      .Where(x => x.UserId == userPermision.UserId)
                                      .Where(x => x.Permission.ResourceKey == resource.Key)
                                      .ToList();


                var actionKeys = userPermissions.Select(x => x.Permission.ActionKey).ToArray();
                var actions    = actionRepository.GetAll();

                model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);
                model.SelectedActions  = actionKeys;
                model.ResourceKey      = resource.Key;
                model.ResourceName     = resource.Name;
                model.User             = mapper.Map <AppUserViewModel>(userRepository.Find(userPermision.UserId));

                return(View(model));
            }
        }
예제 #12
0
 public IActionResult Get()
 {
     return(Ok(_actionRepository.GetAll()));
 }
예제 #13
0
        public ActionResult EditUserPermission(int id, EditAppUserPermissionViewModel model)
        { //Clave del resource
            using (var context = new AppSecurityContext())
            {
                var actionRepository       = new ActionRepository(context);
                var resourceRepository     = new ResourceRepository(context);
                var permissionRepository   = new PermissionRepository(context);
                var userPermissionRository = new UserPermissionRepository(context);
                try
                {
                    var userPermision = userPermissionRository.GetAll().Where(x => x.Id == id).FirstOrDefault();

                    var actions  = actionRepository.GetAll();
                    var resource = resourceRepository.Find(userPermision.Permission.ResourceKey);

                    var permissions = userPermissionRository.GetAll()
                                      .Where(x => x.Permission.ResourceKey == resource.Key)
                                      .Where(x => x.UserId == userPermision.UserId);

                    var actionKeys = permissions.Select(x => x.Permission.ActionKey).ToArray();
                    model.AvailableActions = mapper.Map <ICollection <AppActionViewModel> >(actions);

                    //Se eliminan los permisos anteriores
                    foreach (var perm in permissions)
                    {
                        userPermissionRository.Delete(perm);
                    }

                    if (model.SelectedActions != null)
                    {
                        //Se agregan los nuevos
                        var permissionForInsert = permissionRepository
                                                  .GetAll()
                                                  .Where(x => x.ResourceKey == resource.Key)
                                                  .Where(x => model.SelectedActions.Contains(x.ActionKey));

                        foreach (var p in permissionForInsert)
                        {
                            var permission = new AppUserPermission();
                            permission.UserId       = userPermision.UserId;
                            permission.PermissionId = p.Id;
                            userPermissionRository.Insert(permission);
                        }
                        model.SelectedActions = actionKeys;
                        model.ResourceKey     = resource.Key;
                        model.ResourceName    = resource.Name;
                    }
                    context.SaveChanges();
                    return(RedirectToAction("UserPermission", new { id = model.User.Id }));
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                    if (ex.InnerException != null)
                    {
                        ViewBag.Error += ex.InnerException.Message;
                    }
                    return(View(model));
                }
            }
        }
예제 #14
0
 public void GetAll()
 {
     Assert.IsTrue(myActionRepository.GetAll(true).Count > 0);
 }