public ActionResult DeleteConfirmed(int id)
        {
            if (!(AspNetUsersRoles.IsUserInRole("Administrator", User.Identity.Name) || AspNetUsersRoles.IsUserInRole("Editor", User.Identity.Name)))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.ControllerName = "tbNetVirtualCategoryResources";
            tbNetVirtualCategoryResource tbNetVirtualCategoryResource = db.tbNetVirtualCategoryResource.Find(id);

            db.tbNetVirtualCategoryResource.Remove(tbNetVirtualCategoryResource);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: tbNetVirtualCategoryResources/Details/5
        public ActionResult Details(int?id)
        {
            if (!(AspNetUsersRoles.IsUserInRole("Administrator", User.Identity.Name) || AspNetUsersRoles.IsUserInRole("Editor", User.Identity.Name)))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.ControllerName = "tbNetVirtualCategoryResources";
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbNetVirtualCategoryResource tbNetVirtualCategoryResource = db.tbNetVirtualCategoryResource.Find(id);

            if (tbNetVirtualCategoryResource == null)
            {
                return(HttpNotFound());
            }
            return(View(tbNetVirtualCategoryResource));
        }
        public ActionResult Edit([Bind(Include = "id,name")] tbNetVirtualCategoryResource tbNetVirtualCategoryResource)
        {
            if (!(AspNetUsersRoles.IsUserInRole("Administrator", User.Identity.Name) || AspNetUsersRoles.IsUserInRole("Editor", User.Identity.Name)))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.ControllerName = "tbNetVirtualCategoryResources";
            if (ModelState.IsValid)
            {
                var q = (from m in db.tbNetVirtualCategoryResource where m.id == tbNetVirtualCategoryResource.id select new { m.image, m.JsonMetadata }).FirstOrDefault();
                if (q != null)
                {
                    tbNetVirtualCategoryResource.image        = q.image;
                    tbNetVirtualCategoryResource.JsonMetadata = q.JsonMetadata;
                }
                List <FileMetaData> mdfiles = JsonConvert.DeserializeObject <List <FileMetaData> >(tbNetVirtualCategoryResource.JsonMetadata);
                DateTime            dn      = System.DateTime.Now;
                foreach (string item in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
                    int length = file.ContentLength;
                    if (length > 0 && file != null)
                    {
                        byte[] buffer = new byte[length];
                        file.InputStream.Read(buffer, 0, length);
                        PropertyInfo propInfo = typeof(tbNetVirtualCategoryResource).GetProperty(item);
                        propInfo.SetValue(tbNetVirtualCategoryResource, buffer);
                        FileMetaData fmd = mdfiles.Find(m => m.FileId == item);
                        fmd.ModifiedOn  = System.DateTime.Now;
                        fmd.ContentType = file.ContentType;
                        fmd.Size        = length / 1024;
                    }
                }

                tbNetVirtualCategoryResource.JsonMetadata = JsonConvert.SerializeObject(mdfiles);

                db.Entry(tbNetVirtualCategoryResource).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(tbNetVirtualCategoryResource));
        }
        public ActionResult DowloadFile(int?id, string FileId = "")
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbNetVirtualCategoryResource tbNetVirtualCategoryResource = db.tbNetVirtualCategoryResource.Find(id);

            if (tbNetVirtualCategoryResource != null)
            {
                Type                t            = typeof(tbNetVirtualCategoryResource);
                PropertyInfo        pi           = t.GetProperty(FileId);
                byte[]              file         = (byte[])pi.GetValue(tbNetVirtualCategoryResource);
                List <FileMetaData> mdfiles      = JsonConvert.DeserializeObject <List <FileMetaData> >(tbNetVirtualCategoryResource.JsonMetadata);
                string              content_type = mdfiles.Where(m => m.FileId == FileId).Select(m => m.ContentType).First();
                return(File(file, content_type));
            }
            else
            {
                return(null);
            }
        }
        public ActionResult Create([Bind(Include = "id,name")] tbNetVirtualCategoryResource tbNetVirtualCategoryResource)
        {
            if (!(AspNetUsersRoles.IsUserInRole("Administrator", User.Identity.Name) || AspNetUsersRoles.IsUserInRole("Editor", User.Identity.Name)))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.ControllerName = "tbNetVirtualCategoryResources";
            if (ModelState.IsValid)
            {
                List <FileMetaData> mdfiles = new List <FileMetaData>();
                DateTime            dn      = System.DateTime.Now;
                foreach (string item in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
                    int length = file.ContentLength;
                    if (length > 0 && file != null)
                    {
                        byte[] buffer = new byte[length];
                        file.InputStream.Read(buffer, 0, length);
                        PropertyInfo propInfo = typeof(tbNetVirtualCategoryResource).GetProperty(item);
                        propInfo.SetValue(tbNetVirtualCategoryResource, buffer);
                        FileMetaData fmd = new FileMetaData()
                        {
                            FileId = item, CreatedOn = dn, ModifiedOn = dn, ContentType = file.ContentType, Size = length / 1024
                        };
                        mdfiles.Add(fmd);
                    }
                }

                tbNetVirtualCategoryResource.JsonMetadata = JsonConvert.SerializeObject(mdfiles);
                db.tbNetVirtualCategoryResource.Add(tbNetVirtualCategoryResource);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tbNetVirtualCategoryResource));
        }