コード例 #1
0
ファイル: UserController.cs プロジェクト: yudhasatria0808/TMS
        public async Task <ActionResult> Add(User model)
        {
            if (ModelState.IsValid)
            {
                //more validation
                bool IsExist = RepoUser.IsExist(model.Username);

                if (IsExist)
                {
                    ModelState.AddModelError("Nik", "Nik & Username sudah terdaftar.");
                    ModelState.AddModelError("Username", "Nik & Username sudah terdaftar");
                    initRole(model);
                    return(View("Form", model));
                }

                if (!model.ListRole.Any(d => d.isselect.Equals(true)))
                {
                    ModelState.AddModelError("roles", "Pilih salah satu atau lebih.");
                    initRole(model);
                    return(View("Form", model));
                }

                Context.User dbitem = new Context.User();
                model.setDb(dbitem);
                dbitem.Password = Encrypt(model.Password);
                //tambahan default menu user
                foreach (var item in RepoMenu.FindAll())
                {
                    dbitem.UserMenus.Add(new Context.UserMenus()
                    {
                        IdMenu = item.Id
                    });
                }
                RepoUser.save(dbitem, UserPrincipal.id);
                string BodyEmail = string.Format("<BR/><BR/>Thank you for your registration," +
                                                 "<p>You already have an account with TMS. You can access  TMS any time by visiting:</p>" +
                                                 "<a href='" + Url.Action("Index", "User", new object { }, Request.Url.Scheme) + "'> TMS MKA</a>" +
                                                 "<p> Username : "******"</p>" +
                                                 "<p> Password : "******"</p>" +
                                                 "<BR/><BR/><BR/> Regards,<BR/><BR/> TMS MKA Team");

                EmailHelper.SendEmail(model.Email, "Email Registration TMS MKA", BodyEmail);

                return(RedirectToAction("EditAkses", "User", new { @id = dbitem.Id }));
            }
            initRole(model);
            return(View("Form", model));
        }
コード例 #2
0
ファイル: MenuController.cs プロジェクト: yudhasatria0808/TMS
        public string Binding(string modul, int role_id)
        {
            Context.Role        role  = RepoRole.FindByPK(role_id);
            List <Context.Menu> items = RepoMenu.FindAll().Where(d => d.Modul == modul && !role.RoleMenus.Select(f => f.IdMenu).Contains(d.Id)).ToList();

            List <RoleMenu> ListModel = new List <RoleMenu>();

            foreach (Context.Menu item in items)
            {
                ListModel.Add(new RoleMenu(item));
            }

            foreach (Context.RoleMenus item in role.RoleMenus.Where(d => RepoMenu.FindAll().Where(f => f.Modul == modul).Select(e => e.Id).ToList().Contains(d.IdMenu.Value)))
            {
                ListModel.Add(new RoleMenu(item));
            }

            return(new JavaScriptSerializer().Serialize(new { total = ListModel.Count(), data = ListModel }));
        }