public ActionResult DeleteAll(int[] ids) { //1. Requirement when opening a transaction: Connection has to be opened FilesRepository fr = new FilesRepository(); fr.MyConnection.Open(); fr.MyTransaction = fr.MyConnection.BeginTransaction(); //from this point onwards all code executed against the db will remain pending try { new LoggingRepository().Logging("Deleting multiple elements"); foreach (int id in ids) { fr.DeleteFile(id); } fr.MyTransaction.Commit(); //Commit: you are confirming the changes in the db } catch (Exception ex) { //Log the exception on the cloud new LoggingRepository().ErrorLogging(ex); fr.MyTransaction.Rollback(); //Rollback: it will reverse all the changes done within the try-clause in the db } fr.MyConnection.Close(); CacheRepository cr = new CacheRepository(); cr.UpdateCache(fr.GetFiles(User.Identity.Name)); return(RedirectToAction("Index")); }
public ActionResult Files() { FilesRepository fr = new FilesRepository(); var listOfFiles = fr.GetFiles(); return(View(listOfFiles)); }
public ActionResult Files(string sortOrder, string currentFilter, string search, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParam = sortOrder == "Name" ? "NameDesc" : "Name"; ViewBag.PageSortParam = sortOrder == "Page" ? "PageDesc" : "Page"; if (search != null) { page = 1; } else { search = currentFilter; } ViewBag.CurrentFilter = search; List <DescriptionFile> files = _fileRepo.GetFiles(sortOrder); if (!String.IsNullOrEmpty(search)) { files = files.Where(d => d.Name == search || d.NominationPage == search).ToList(); } int pageSize = 7; int pageNumber = (page ?? 1); if (files != null) { return(View(files.ToPagedList(pageNumber, pageSize))); } return(View()); }
public ActionResult Upload(Guid id) { //shows the page FilesRepository fr = new FilesRepository(); var file = fr.GetFiles().SingleOrDefault(x => x.id == id); return(View(file)); }
public ActionResult Search(string keyword) { FilesRepository ir = new FilesRepository(); var filteredList = ir.GetFiles().Where(File => File.Title.Contains(keyword)); return(View("Files", filteredList)); //metids list and search }
public IActionResult GetFiles(int accountId) { try { var result = fileRepository.GetFiles(accountId); return(Ok(result)); } catch (Exception ex) { return(HandleException(ex)); } }
public ActionResult Details(Guid id) { try { FilesRepository ir = new FilesRepository(); //encryption.decryptquerystring var myItem = ir.GetFiles().SingleOrDefault(x => x.id == id); return(View(myItem)); } catch { TempData["error"] = "Value is not valid"; return(RedirectToAction("List")); } }
public ActionResult Delete(int id) { try { new LoggingRepository().Logging("Deleting one element"); FilesRepository fr = new FilesRepository(); fr.DeleteFile(id); CacheRepository cr = new CacheRepository(); cr.UpdateCache(fr.GetFiles(User.Identity.Name)); } catch (Exception ex) { new LoggingRepository().ErrorLogging(ex); } return(RedirectToAction("Index")); }
public ActionResult Upload(Guid id, HttpPostedFileBase file) { FilesRepository fr = new FilesRepository(); if (file != null) { byte[] readBytes = new byte[2]; file.InputStream.Read(readBytes, 0, 2); file.InputStream.Position = 0; /*if ( * (readBytes[0] == 80 & readBytes[1] == 75) || //zip * (readBytes[0] == 82 & readBytes[1] == 97) || //rar * (readBytes[0] == 137 & readBytes[1] == 80) || //png * (readBytes[0] == 105 & readBytes[1] == 115)//mp4 * ) * * {*/ if (file.ContentLength <= 104857600) { //string Path = Server.MapPath("//FileStorage") + "//" + newFilename; string name = Path.GetFileName(file.FileName); string path = Path.Combine(Server.MapPath("~/FileStorage") + "//" + name); file.SaveAs(path); ViewBag.Message = "File uploaded"; Upload u = new Upload(); u.File_id = id; u.Path = name; fr.AddUpload(u); ViewBag.Message = "File is uploaded successfully"; } else { ViewBag.Error = "File should be smaller than 2 GB"; } /*} * else ViewBag.Error = "File type not allowed";*/ } var fails = fr.GetFiles().SingleOrDefault(x => x.id == id); return(View(fails)); }
public ActionResult Index() { try { new LoggingRepository().Logging("Getting Items"); #region get products of db - removed....instead insert next region FilesRepository pr = new FilesRepository(); //var products = pr.GetProducts(); //gets products from db #endregion #region instead of getting products from DB, to make your application faster , you load them from the cache CacheRepository cr = new CacheRepository(); cr.UpdateCache(pr.GetFiles(User.Identity.Name)); //commented var files = cr.GetFilesFromCache(); #endregion return(View("Index", files)); } catch (Exception ex) { new LoggingRepository().ErrorLogging(ex); } return(View("Index")); }
public ActionResult Create(Models.File p, HttpPostedFileBase file) { //upload image related to product on the bucket try { string link = ""; var filename = ""; if (file != null) { #region Uploading file on Cloud Storage var storage = StorageClient.Create(); using (var f = file.InputStream) { filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("programming-for-the-cloud", filename, null, f); //link = storageObject.MediaLink; link = "https://storage.cloud.google.com/programming-for-the-cloud" + "/" + filename; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "programming-for-the-cloud", Entity = $"user-" + "*****@*****.**", Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); } //store details in a relational db including the filename/link #endregion } #region Storing details of product in db [INCOMPLETE] p.OwnerFk = User.Identity.Name; //"*****@*****.**"; ServiceAccountCredential credential; using (var stream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "//jurgen-cloud-project-5f077f2e1ba1.json", FileMode.Open, FileAccess.Read)) { credential = GoogleCredential.FromStream(stream).UnderlyingCredential as ServiceAccountCredential; } UrlSigner urlSigner = UrlSigner.FromServiceAccountCredential(credential); //https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Storage.V1/index.html string signedUrl = urlSigner.Sign("programming-for-the-cloud", filename, TimeSpan.FromDays(365)); p.Link = signedUrl; //p.Link = link; FilesRepository pr = new FilesRepository(); pr.AddFile(p.Name, p.Description, p.OwnerFk, p.Link); #endregion #region Updating Cache with latest list of Products from db //enable: after you switch on db CacheRepository cr = new CacheRepository(); cr.UpdateCache(pr.GetFiles(User.Identity.Name)); #endregion new LoggingRepository().Logging("File Uploaded By: " + User.Identity.Name + " At: " + DateTime.Now); //PubSubRepository psr = new PubSubRepository(); //psr.AddToEmailQueue(p); //adding it to queue to be sent as an email later on. //ViewBag.Message = "Product created successfully"; } catch (Exception ex) { new LoggingRepository().ErrorLogging(ex); ViewBag.Error = "Product failed to be created; " + ex.Message; } return(RedirectToAction("Index")); }