public ActionResult Search(string teg)
 {
     if (teg == "")
         return null;
     var db = new FileContext();
     var sorted = db.StoredFiles.Where(f => f.UserName == User.Identity.Name.ToString() && f.Name.StartsWith(teg));
     return PartialView(sorted);
 }
 public ActionResult DelFile(StoredFile file)
 {
     var db = new FileContext();
     var fl = db.StoredFiles.Single(f => f.Id == file.Id);
     db.StoredFiles.Remove(fl);
     db.SaveChanges();
     return RedirectToAction("AllFiles");
 }
        public ActionResult OrderFiles(int n1 = 0, int n2 = 0)
        {
            int n = 0;
            if (n1 == 0)
                n = n2;
            else
                n = n1;
            if (n == 0)
                ViewBag.Page = 1;
            else
                ViewBag.Page = n;
            if (n > 0)
            {
                n--;
                n *= 10;
            }

            var db = new FileContext();
            List<StoredFile> to10el = new List<StoredFile>();
            List<StoredFile> allsfs = new List<StoredFile>(db.StoredFiles.Where(f => f.UserName == User.Identity.Name.ToString()));
            if (n < allsfs.Count)
            {
                for (int i = n; i < allsfs.Count && to10el.Count < 10; i++)
                {
                    to10el.Add(allsfs[i]);
                }
                return PartialView(to10el);
            }
            return Redirect("AllFiles");
        }
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if (file != null)
            {
                string fileName = System.IO.Path.GetFileName(file.FileName);
                string extention = Path.GetExtension(file.FileName);
                List<string> extentions = new List<string>() { ".txt", ".png", ".jpg", ".pdf", ".zip" };

                if (extentions.Contains(extention))
                {
                    string path = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "\\Image\\Files\\" + User.Identity.Name.ToString();
                    Directory.CreateDirectory(path);
                    file.SaveAs(Server.MapPath("~/Image/Files/" + User.Identity.Name.ToString() + "/" + fileName));
                    var db = new FileContext();
                    var role = db.StoredFiles.Where(f => f.Name == fileName).FirstOrDefault();
                    if (role != null)
                    {
                        Session["Lastfilename"] = "";
                        return View();
                    }
                    Session["Lastfilename"] = "Last uploaded file"+fileName;
                    db.StoredFiles.Add(new StoredFile() { Name = fileName, UserName = User.Identity.Name.ToString() });
                    db.SaveChanges();
                }
                else
                {
                    Session["Lastfilename"] = "Extetion is not supported. You can upload only: .txt, .png, .jpg, .pdf, .zip";
                }
            }
                return View();
        }