Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            PortInfomaitonElectric portInfomaitonElectric = db.PortInfomaitonElectrics.Find(id);

            db.PortInfomaitonElectrics.Remove(portInfomaitonElectric);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            var context = new ApplicationDbContext();

            if (!context.PortInfomaitonElectrics.Any(n => n.Name == "Meditech"))
            {
                PortInfomaitonElectric portInfomaitonElectric = new PortInfomaitonElectric();
                portInfomaitonElectric.Name        = "Meditech";
                portInfomaitonElectric.Url         = "http://meditech.vn/";
                portInfomaitonElectric.IsPublic    = true;
                portInfomaitonElectric.Datecreated = DateTime.Now;
                context.PortInfomaitonElectrics.Add(portInfomaitonElectric);
                context.SaveChanges();
            }
            if (!context.Roles.Any(role => role.Name == "SuperAdmin"))
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);
                roleManager.Create(new IdentityRole("SuperAdmin"));
            }
            if (!context.Roles.Any(role => role.Name == "Admin"))
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);
                roleManager.Create(new IdentityRole("Admin"));
            }

            int idPort = context.PortInfomaitonElectrics.Where(n => n.Name == "Meditech").Select(p => p.ID).FirstOrDefault();

            if (!context.Users.Any(user => user.UserName == "*****@*****.**"))
            {
                var UserManagerFactory = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                var user = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", PortInfomaitonElectricID = idPort
                };
                var result = UserManagerFactory.Create(user, "admin123");
                UserManagerFactory.AddToRole(user.Id, "SuperAdmin");
            }
            if (!context.Users.Any(user => user.UserName == "*****@*****.**"))
            {
                var UserManagerFactory = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                var user = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", PortInfomaitonElectricID = idPort
                };
                var result = UserManagerFactory.Create(user, "admin123");
                UserManagerFactory.AddToRole(user.Id, "Admin");
            }

            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AutoMapperConfiguration.Configure();
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "ID,Url,Name,Phone,Datecreated,IsPublic")] PortInfomaitonElectric portInfomaitonElectric)
 {
     if (ModelState.IsValid)
     {
         portInfomaitonElectric.Datecreated     = DateTime.Now;
         db.Entry(portInfomaitonElectric).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(portInfomaitonElectric));
 }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ID,Url,Name,Phone,Datecreated,IsPublic")] PortInfomaitonElectric portInfomaitonElectric)
        {
            if (ModelState.IsValid)
            {
                portInfomaitonElectric.Datecreated = DateTime.Now;
                db.PortInfomaitonElectrics.Add(portInfomaitonElectric);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(portInfomaitonElectric));
        }
Ejemplo n.º 5
0
        public ActionResult Acpactive(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PortInfomaitonElectric portInfomaitonElectric = db.PortInfomaitonElectrics.Find(id);

            portInfomaitonElectric.IsPublic        = true;
            db.Entry(portInfomaitonElectric).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Active"));
        }
Ejemplo n.º 6
0
        // GET: PortInfomaitonElectrics/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PortInfomaitonElectric portInfomaitonElectric = db.PortInfomaitonElectrics.Find(id);

            if (portInfomaitonElectric == null)
            {
                return(HttpNotFound());
            }
            return(View(portInfomaitonElectric));
        }