예제 #1
0
        // GET: Rutas/Create
        public ActionResult Create()
        {
            Ruta ruta = new Ruta()
            {
                usr_crea   = UtilAut.GetUserId(),
                fec_crea   = DateTime.Now,
                Direccione = new Direccione()
                {
                    usr_crea = UtilAut.GetUserId(),
                    fec_crea = DateTime.Now,
                    activo   = true
                },
                Direccione1 = new Direccione()
                {
                    usr_crea = UtilAut.GetUserId(),
                    fec_crea = DateTime.Now,
                    activo   = true
                }
            };

            return(View("Create", ruta));
        }
예제 #2
0
        public async Task <ActionResult> Create(AppRole appRole)
        {
            if (!ValidateModel(appRole, ModelState))
            {
                return(View(appRole));
            }
            var role = RoleManager.FindByName(appRole.Name);

            if (role != null)
            {
                ModelState.AddModelError(UtilGral.ERROR_FROM_CONTROLLER, "El Área ya existe");
                return(View(appRole));
            }
            var result = await RoleManager.CreateAsync(new AppRole {
                activo           = appRole.activo,
                CreationDate     = DateTime.Now,
                CreationUserName = UtilAut.GetUserId(),
                Name             = appRole.Name
            });

            return(RedirectToAction("Index"));
        }
예제 #3
0
        public async Task <ActionResult> Edit(Menu menuView)
        {
            if (string.IsNullOrEmpty(menuView.name) ||
                string.IsNullOrEmpty(menuView.url))
            {
                return(View(menuView));
            }
            Menu menu = await db.Menus.FindAsync(menuView.id);

            if (menu == null)
            {
                ModelState.AddModelError(UtilGral.ERROR_FROM_CONTROLLER, "El Menú no existe");
                return(View(menuView));
            }
            menu.usr_modif = UtilAut.GetUserId();
            menu.fec_modif = DateTime.Now;
            Menu.UpdateMenus(menu, menuView.MenuByAreas);
            db.Entry(menu).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #4
0
        public async Task <ActionResult> Create(AppUser appUser)
        {
            if (InValidUser(appUser))
            {
                return(View(appUser));
            }
            var user = UserManager.FindByName(appUser.User);

            if (user != null)
            {
                ModelState.AddModelError(UtilGral.ERROR_FROM_CONTROLLER, "El usuario ya existe");
                return(View(appUser));
            }

            user = new AppUser()
            {
                UserName         = appUser.User,
                Email            = appUser.Email,
                EmailConfirmed   = true,
                FirstName        = appUser.FirstName,
                LastName         = appUser.LastName,
                CreationDate     = DateTime.Now,
                CreationUserName = UtilAut.GetUserId(),
                Password         = appUser.Password,
                User             = appUser.User,
                PhoneNumber      = appUser.PhoneNumber,
                activo           = appUser.activo
            };
            var result = await UserManager.CreateAsync(user, appUser.Password);

            var roles = appUser.RolesByUser.Where(role => role.Asignado).Select(role => role.Name).ToArray();

            if (roles.Length > 0)
            {
                UserManager.AddToRoles(user.Id, roles);
            }
            return(RedirectToAction("Index"));
        }
예제 #5
0
        public async Task <ActionResult> Edit(Ruta ruta)
        {
            ruta.Direccione.Estado = await db.Estados.FindAsync(ruta.Direccione.id_estado);

            ruta.Direccione1.Estado = await db.Estados.FindAsync(ruta.Direccione1.id_estado);

            ruta.fec_modif             = DateTime.Now;
            ruta.usr_modif             = UtilAut.GetUserId();
            ruta.Direccione.fec_modif  = DateTime.Now;
            ruta.Direccione.usr_modif  = UtilAut.GetUserId();
            ruta.Direccione1.fec_modif = DateTime.Now;
            ruta.Direccione1.usr_modif = UtilAut.GetUserId();
            if (ModelState.IsValid)
            {
                db.Entry(ruta.Direccione1).State = EntityState.Modified;
                db.Entry(ruta.Direccione).State  = EntityState.Modified;
                db.Entry(ruta).State             = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View("Create", ruta));
        }