示例#1
0
        public async Task <bool> CreateUserRol(int userId, List <int> rolIds)
        {
            var user = _context.Users.Find(userId);

            if (user == null)
            {
                return(false);
            }

            foreach (var rolId in rolIds)
            {
                var rol = _context.Rols.Find(rolId);

                if (rol == null)
                {
                    return(false);
                }

                var userRol = new UserRol {
                    UserId = userId, RolId = rolId
                };
                _context.Add(userRol);
            }

            var result = await _context.SaveChangesAsync();

            if (result == 0)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public ActionResult Create()
        {
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                var userRolNew = new UserRol
                {
                };
                return(View(userRolNew));
            }
            //verifica el usuario logeado y envia su compania a la vista
            var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var userRol = new UserRol
            {
            };

            return(View(userRol));
        }
示例#3
0
        public async Task <ActionResult> CreateRolForUser(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }

            var user = await _db.Users.FindAsync(id);

            if (user == null)
            {
                return(View("Error"));
            }


            ViewBag.UserId   = new SelectList(_db.Users, "UserId", "FirstName");
            ViewBag.StatusId = new SelectList(_db.Status, "StatusId", "Name");

            ViewBag.RolId = new SelectList(_db.Rols.Where(t => t.AuthorId == user.AuthorId), "RolId", "Name");
            var view = new UserRol {
                UserId = user.UserId,
            };

            return(View(view));
        }
示例#4
0
        public async Task <ActionResult> CreateRolForUser(UserRol userRol)
        {
            if (ModelState.IsValid)
            {
                // var rol = await _db.UserRols.FindAsync(userRol.RolId);
                var userRols = await _db.UserRols.FirstOrDefaultAsync(x => x.UserId == userRol.UserId && x.UserRolId == userRol.RolId);

                if (userRols != null)
                {
                    ModelState.AddModelError(string.Empty,
                                             @"Este Usuario ya tiene asignado este Rol");
                }
                else
                {
                    _db.UserRols.Add(userRol);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("IndexRolForUser/" + userRol.UserId));
                }
            }


            ViewBag.UserId   = new SelectList(_db.Users, "UserId", "FirstName", userRol.UserId);
            ViewBag.StatusId = new SelectList(_db.Status, "StatusId", "Name", userRol.StatusId);
            ViewBag.RolId    = new SelectList(_db.Rols, "RolId", "Name", userRol.RolId);
            //var view = new UserRol { UserId = user.UserId, };

            //return View(view);
            //ViewBag.StatusId = new SelectList(_db.Status, "StatusId", "Name", userRol.StatusId);
            //ViewBag.UserId = new SelectList(_db.Options.OrderBy(t => t.Name), "OptionId", "Name", userRol.UserId);
            //ViewBag.RolId = new SelectList(_db.Rols.Where(t => t.AuthorId == userRol.User.AuthorId).OrderBy(t => t.Name), "RolId", "Name", userRol.UserId);
            return(View(userRol));
        }
示例#5
0
        protected UserRol AdminRol()
        {
            UserRol rolo = new UserRol {
                UType = UserType.Admin
            };

            rolo.ActionOperations.Add(new ActionOperation {
                Name = "Vehicle.Add"
            });

            rolo.ActionOperations.Add(new ActionOperation {
                Name = "User.Add"
            });
            rolo.ActionOperations.Add(new ActionOperation {
                Name = "User.Update"
            });
            rolo.ActionOperations.Add(new ActionOperation {
                Name = "User.UpdateById"
            });
            rolo.ActionOperations.Add(new ActionOperation {
                Name = "Batch.Add"
            });
            rolo.ActionOperations.Add(new ActionOperation {
                Name = "Batch.AddVehicle"
            });
            return(rolo);
        }
示例#6
0
        protected override void Seed(HotelsA.Data.HotelsContext _context)
        {
            UserRol usrr = new UserRol
            {
                UserType = "Administrator"
            };

            _context.UserRols.Add(usrr);

            User user = new User
            {
                FullName  = "Administrator",
                UserName  = "******",
                Password  = "******",
                UserRolId = 1
            };

            _context.Users.Add(user);

            BedType bdty1 = new BedType
            {
                TypeName = "Cüt"
            };

            _context.BedTypes.Add(bdty1);

            BedType bdty2 = new BedType
            {
                TypeName = "Tək"
            };

            _context.BedTypes.Add(bdty2);
            _context.SaveChanges();
        }
示例#7
0
 public PersonUser()
 {
     user     = new User();
     person   = new Person();
     roles    = new Roles();
     userPers = new UserRol();
 }
示例#8
0
        public ActionResult DeleteConfirmed(int id)
        {
            UserRol userRol = db.UserRol.Find(id);

            db.UserRol.Remove(userRol);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#9
0
        public async Task <UserRolOutput> GetUserRolById(int idRol)
        {
            UserRol userRol = await _userRolRepository.GetRolById(idRol);

            UserRolOutput userRolOutput = _mapper.Map <UserRolOutput>(userRol);

            return(userRolOutput);
        }
示例#10
0
        public async Task <ActionResult> Create(Author author)
        {
            if (ModelState.IsValid)
            {
                _db.Authors.Add(author);
                await _db.SaveChangesAsync();

                var user = new User
                {
                    AuthorId   = author.AuthorId,
                    FirstName  = author.Name,
                    LastName   = author.Name,
                    UserTypeId = 1,
                    Email      = author.Email,
                    StatusId   = 1
                };

                _db.Users.Add(user);

                var rol = new Rol
                {
                    AuthorId    = author.AuthorId,
                    Name        = "Admin",
                    Description = "Administrator",
                    Level       = 2,
                    StatusId    = 1
                };

                _db.Rols.Add(rol);

                await _db.SaveChangesAsync();

                UsersHelper.CreateUserAsp(author.Email, "User", "824455");

                var rolForUser = new UserRol
                {
                    UserId    = user.UserId,
                    RolId     = rol.RolId,
                    FromDate  = DateTime.Today,
                    ToDate    = DateTime.Today,
                    Undefined = true,
                    StatusId  = 1
                };

                _db.UserRols.Add(rolForUser);



                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.AuthorPlanId = new SelectList(_db.AuthorPlans, "AuthorPlanId", "Code", author.AuthorPlanId);
            ViewBag.StatusId     = new SelectList(_db.Status, "StatusId", "Name", author.StatusId);
            ViewBag.AuthorTypeId = new SelectList(_db.AuthorTypes, "AuthorTypeId", "Name", author.AuthorTypeId);
            return(View(author));
        }
示例#11
0
        public async Task EliminarRolAsync(int idUserRol)
        {
            UserRol rol = new UserRol()
            {
                IdRol = idUserRol
            };

            _db.Entry(rol).State = EntityState.Deleted;
        }
示例#12
0
 public UsersController(ApplicationDbContext context, UserManager <ApplicationUser> userManager,
                        RoleManager <IdentityRole> roleManager)
 {
     _context     = context;
     _userManager = userManager;
     _roleManager = roleManager;
     _userRol     = new UserRol();
     userRol      = new List <SelectListItem>();
 }
示例#13
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,RowId,Created")] UserRol userRol)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userRol).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userRol));
 }
示例#14
0
        public void selectUserRole()
        {
            UserRol r = new UserRol();

            r.user_id = Convert.ToInt32(Session["UserID"]);
            r.RoleName(r);
            Session["Rolename"]      = r.role_name;
            Session["company_id"]    = r.company_id;
            Session["branch_id"]     = r.branch_id;
            Session["LoginuserName"] = r.loginUsername;
        }
        // POST: api/UserRol
        public async Task <IActionResult> PostUserRol([FromBody] UserRol userRol)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.SG_UserRol.Add(userRol);
            await _context.SaveChangesAsync();

            return(Ok(userRol));
        }
示例#16
0
        public ActionResult Edit(UserRol rol)
        {
            if (ModelState.IsValid)
            {
                _context.Entry(rol).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
                return(RedirectToAction("index"));
            }

            ViewBag.Groups = _context.UserRols.OrderBy(u => u.UserType).ToList();
            return(View(rol));
        }
示例#17
0
        public ActionResult Edit(int id)
        {
            UserRol rol = _context.UserRols.Find(id);

            if (rol == null)
            {
                return(HttpNotFound());
            }

            ViewBag.UserRols = _context.UserRols.ToList();
            return(View(rol));
        }
示例#18
0
        public User GetbyId(int userId)
        {
            User user = unitOfWork.UserRepository.GetByID(userId);

            if (user == null)
            {
                throw new UserNotFoundException(string.Format("No se encontró el usuario con Id: {0}", userId));
            }
            UserRol x = unitOfWork.UserRolRepository.GetByID(user.Rol_Id);

            user.Rol = x;
            return(user);
        }
示例#19
0
        private int AuthenticateUser()
        {
            UserRol r = new UserRol();

            r.user_name = txtEmail.Text;
            string enPswd = GetSwcSHA1(txtPassword.Text);

            r.password = enPswd;
            r.userID(r);
            Session["UserID"]   = r.user_id;
            Session["username"] = txtEmail.Text;
            return(us_ID);
        }
示例#20
0
        public ActionResult Delete(int id)
        {
            UserRol rol = _context.UserRols.Find(id);

            if (rol == null)
            {
                return(HttpNotFound());
            }

            _context.UserRols.Remove(rol);
            _context.SaveChanges();
            return(RedirectToAction("index"));
        }
示例#21
0
        public async Task <ActionResult> RemoverRolUsuario([FromBody] UserRol userRol)
        {
            var usuario = await userManager.FindByIdAsync(userRol.UserId);

            if (usuario == null)
            {
                return(NotFound());
            }
            await userManager.RemoveClaimAsync(usuario, new Claim(ClaimTypes.Role, userRol.RolName));

            await userManager.RemoveFromRoleAsync(usuario, userRol.RolName);

            return(Ok());
        }
示例#22
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,RowId,Created")] UserRol userRol)
        {
            if (ModelState.IsValid)
            {
                userRol.RowId   = new Guid().ToString();
                userRol.Created = DateTime.Now;

                db.UserRol.Add(userRol);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userRol));
        }
示例#23
0
 public ActionResult Edit(UserRol userRol)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userRol).State = EntityState.Modified;
         var responseSave = DBHelper.SaveChanges(db);
         if (responseSave.Succeeded)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, responseSave.Message);
     }
     return(View(userRol));
 }
示例#24
0
        // GET: UserRols/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserRol userRol = db.UserRol.Find(id);

            if (userRol == null)
            {
                return(HttpNotFound());
            }
            return(View(userRol));
        }
示例#25
0
        public ActionResult Create(UserRol userRol)
        {
            if (ModelState.IsValid)
            {
                db.UserRols.Add(userRol);
                var responseSave = DBHelper.SaveChanges(db);
                if (responseSave.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, responseSave.Message);
            }

            return(View(userRol));
        }
示例#26
0
        public async Task AgregarEditarUserRolAsync(UserRolInput rol)
        {
            if (rol.IdRol > 0)
            {
                UserRol userRol = await _userRolRepository.GetRolById(rol.IdRol, trackear : true);

                _mapper.Map <UserRolInput, UserRol>(rol, userRol);
            }
            else
            {
                UserRol userRol = _mapper.Map <UserRol>(rol);
                await _userRolRepository.AgregarEditarRolAsync(userRol);
            }
            await _userRolRepository.SaveChangesAsync();
        }
示例#27
0
        public async Task <ActionResult> EditRolForUser(UserRol userRol)
        {
            if (ModelState.IsValid)
            {
                _db.Entry(userRol).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                return(RedirectToAction($"DetailsUser/{userRol.UserId}"));
            }
            ViewBag.StatusId = new SelectList(_db.Status, "StatusId", "Name", userRol.StatusId);
            ViewBag.UserId   = new SelectList(_db.Options.OrderBy(t => t.Name), "OptionId", "Name", userRol.UserId);
            ViewBag.RolId    = new SelectList(_db.Rols.Where(t => t.AuthorId == userRol.User.AuthorId).OrderBy(t => t.Name), "RolId", "Name", userRol.UserId);

            return(View(userRol));
        }
示例#28
0
 public ActionResult Edit(UserRol userRol)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userRol).State = EntityState.Modified;
         var responseSave = DBHelper.SaveChanges(db);
         if (responseSave.Succeeded)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, responseSave.Message);
     }
     ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", userRol.CompanyId);
     return(View(userRol));
 }
示例#29
0
        public ActionResult Create(UserRol userrol)
        {
            if (_context.UserRols.Any(u => u.UserType == userrol.UserType))
            {
                ModelState.AddModelError("Roles", userrol.UserType + " artıq mövcuddur.");
                return(View(userrol));
            }
            if (ModelState.IsValid)
            {
                _context.UserRols.Add(userrol);
                _context.SaveChanges();
                return(RedirectToAction("index"));
            }


            return(View(userrol));
        }
示例#30
0
        public ActionResult Create()
        {
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
                var userRolNew = new UserRol
                {
                    AccumulatedMobility = 0,
                    BasicJornal         = 0,
                    Buc          = 0,
                    Cts          = 0,
                    Dominical    = 0,
                    Holidays     = 0,
                    HourExtra100 = 0,
                    HourExtra60  = 0,
                    Reward       = 0,
                };
                return(View(userRolNew));
            }
            //verifica el usuario logeado y envia su compania a la vista
            var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var userRol = new UserRol
            {
                CompanyId           = user.CompanyId,
                AccumulatedMobility = 0,
                BasicJornal         = 0,
                Buc          = 0,
                Cts          = 0,
                Dominical    = 0,
                Holidays     = 0,
                HourExtra100 = 0,
                HourExtra60  = 0,
                Reward       = 0,
            };

            return(View(userRol));
        }