Esempio n. 1
0
 public FileResult Get(long id)
 {
     using (tskmContainer db = new tskmContainer())
     {
         File file = db.Files.Find(id);
         return new FilePathResult(System.IO.Path.Combine(Server.MapPath("~/App_Data/uploads"), file.fileName), file.ContentType);
     }
 }
Esempio n. 2
0
 public static void RefreshCache()
 {
     using (tskmContainer db = new tskmContainer())
     {
         if (HttpContext.Current.User != null)
         {
             _user = db.Users.SingleOrDefault(x => x.username == HttpContext.Current.User.Identity.Name);
             if (_user != null)
             {
                 _user.Roles.ToList();
             }
         }
     }
 }
Esempio n. 3
0
        public static Models.File Save(HttpPostedFileBase fileUpload, string targetPath)
        {
            using (tskmContainer db = new tskmContainer())
            {
                Models.File file = new Models.File();
                file.fileName = Guid.NewGuid().ToString();
                file.ContentType = fileUpload.ContentType;

                fileUpload.SaveAs(Path.Combine(targetPath, file.fileName));

                db.Files.Add(file);
                db.SaveChanges();

                return file;
            }
        }
Esempio n. 4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            PostAuthenticateRequest += Application_PostAuthenticateRequest;

            using (tskmContainer db = new tskmContainer())
            {
                if (!db.Catagories.Any())
                {
                    db.Catagories.Add(new Catagory
                    {
                        catagoryName = "Hardware"
                    });
                    db.Catagories.Add(new Catagory
                    {
                        catagoryName = "Software"
                    });
                    db.Catagories.Add(new Catagory
                    {
                        catagoryName = "Others"
                    });
                }

                if (!db.Roles.Any())
                {
                    db.Roles.Add(new Role
                    {
                        Name = "Admin",
                        Description = "ผู้ดูแลระบบ"
                    });

                    db.Roles.Add(new Role
                    {
                        Name = "IT Manager",
                        Description = "ผู้จัดการแผนก IT"
                    });

                    db.Roles.Add(new Role
                    {
                        Name = "IT User",
                        Description = "เจ้าหน้าที่ IT"
                    });

                    db.Roles.Add(new Role
                    {
                        Name = "User",
                        Description = "ผู้ใช้งาน"
                    });
                }

                if (!db.Departments.Any())
                {
                    db.Departments.Add(new Department
                    {
                        departmentName = "Admin"
                    });
                }

                if (!db.Status.Any())
                {
                    db.Status.Add(new Status
                    {
                        statusName = "Opened"
                    });

                    db.Status.Add(new Status
                    {
                        statusName = "In Progress"
                    });

                    db.Status.Add(new Status
                    {
                        statusName = "Waiting for closing"
                    });

                    db.Status.Add(new Status
                    {
                        statusName = "Closed"
                    });
                }

                db.SaveChanges();

                if (!db.Users.Any())
                {
                    User user = new User
                    {
                        userFname = "Admin",
                        userLname = "Admin",
                        username = "******",
                        password = "******",
                        userTel = "1111",
                        userEmail = "*****@*****.**",
                        Department = db.Departments.First(),
                        userCode = "1111",
                        userPosition = "Admin"
                    };
                    user.Roles.Add(db.Roles.Single(x=>x.Name == "Admin"));

                    db.Users.Add(user);
                }

                db.SaveChanges();
            }
        }
Esempio n. 5
0
        protected void Application_PostAuthenticateRequest(object serder, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                using (tskmContainer db = new tskmContainer())
                {
                    var roles = (from us in db.Users
                                 where us.username == User.Identity.Name
                                 select us).SingleOrDefault().Roles.Select(x => x.Name);

                    GenericIdentity Identity = new GenericIdentity(User.Identity.Name);
                    GenericPrincipal Principal = new GenericPrincipal(Identity, roles.ToArray());
                    Context.User = Principal;
                    System.Threading.Thread.CurrentPrincipal = Principal;
                }
            }

            // Udpate CurrentUser
            CurrentUser.RefreshCache();
        }