Esempio n. 1
0
        public ActionResult Edit(VaultViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var transaction = DbSession.BeginTransaction())
                    {
                        var vault = DbSession.Get <Vault>(model.Id);
                        vault.Name = model.Name;

                        DbSession.Save(vault);

                        transaction.Commit();
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "Неизвестная ошибка");
                }
            }

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Create(VaultViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var transaction = DbSession.BeginTransaction())
                    {
                        var admin = DbSession.Get <ApplicationUser>(model.AdminId);
                        var vault = new Vault {
                            Name = model.Name, Admin = admin
                        };
                        DbSession.Save(vault);

                        transaction.Commit();
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "Неизвестная ошибка");
                }
            }

            return(View(model));
        }
Esempio n. 3
0
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     if (DataContext != null && DataContext is CustomerViewModel)
     {
         var customer = DataContext as CustomerViewModel;
         if (customer.Customer != null)
         {
             VaultViewModel vm = new VaultViewModel(customer.Customer.Id);
             DataContext = vm;
         }
     }
 }
Esempio n. 4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _model        = MainGrid.DataContext as VaultViewModel;
            _searchHelper = new SearchExt(MainGrid);
            _searchHelper.SetSearch(_currSearchType);
            MainGrid.SearchHelper           = _searchHelper;
            MainGrid.CurrentCellValidating += MainGrid_CurrentCellValidating;

            var cmdline = Environment.GetCommandLineArgs();

            if (cmdline.Length == 2 && File.Exists(cmdline[1]))
            {
                LoadVault(cmdline[1]);
            }
#if DEBUG
            else
            {
                LoadVault(@"online_players.vault");
            }
#endif
        }
Esempio n. 5
0
        public async Task <IActionResult> ViewVault(string id)
        {
            Models.Vault foundVault = _dbContext.Vaults.Where(v => v.Url == id).FirstOrDefault();
            if (foundVault != null)
            {
                // Update view count
                foundVault.Views += 1;
                _dbContext.Entry(foundVault).State = EntityState.Modified;
                _dbContext.SaveChanges();

                ViewBag.Title = foundVault.Title + " | Vault";

                VaultViewModel model = new VaultViewModel();
                model.CurrentSub = Subdomain;

                model.Url         = foundVault.Url;
                model.UserId      = foundVault.UserId;
                model.User        = foundVault.User;
                model.Title       = foundVault.Title;
                model.Description = foundVault.Description;
                model.DateCreated = foundVault.DateCreated;
                model.DateEdited  = foundVault.DateEdited;

                if (foundVault.VaultItems.Any())
                {
                    foreach (VaultItem item in foundVault.VaultItems.OrderBy(v => v.Index))
                    {
                        if (item.GetType().BaseType == typeof(UploadVaultItem))
                        {
                            UploadVaultItem upload = (UploadVaultItem)item;
                            // Increment Views
                            upload.Upload.Downloads += 1;
                            _dbContext.Entry(upload.Upload).State = EntityState.Modified;
                            _dbContext.SaveChanges();

                            UploadItemViewModel uploadModel = new UploadItemViewModel();
                            uploadModel.VaultItemId = item.VaultItemId;
                            uploadModel.Title       = item.Title;
                            uploadModel.Description = item.Description;
                            uploadModel.DateAdded   = item.DateAdded;
                            uploadModel.Upload      = upload.Upload;
                            model.Items.Add(uploadModel);
                        }
                        else if (item.GetType().BaseType == typeof(PasteVaultItem))
                        {
                            PasteVaultItem paste = (PasteVaultItem)item;
                            // Increment Views
                            paste.Paste.Views += 1;
                            _dbContext.Entry(paste.Paste).State = EntityState.Modified;
                            _dbContext.SaveChanges();

                            // Check Expiration
                            if (PasteHelper.CheckExpiration(paste.Paste))
                            {
                                _dbContext.Pastes.Remove(paste.Paste);
                                _dbContext.SaveChanges();
                                break;
                            }

                            PasteItemViewModel pasteModel = new PasteItemViewModel();
                            pasteModel.VaultItemId = item.VaultItemId;
                            pasteModel.Title       = item.Title;
                            pasteModel.Description = item.Description;
                            pasteModel.DateAdded   = item.DateAdded;

                            pasteModel.PasteId     = paste.Paste.PasteId;
                            pasteModel.Url         = paste.Paste.Url;
                            pasteModel.DatePosted  = paste.Paste.DatePosted;
                            pasteModel.Syntax      = paste.Paste.Syntax;
                            pasteModel.HasPassword = !string.IsNullOrEmpty(paste.Paste.HashedPassword);

                            if (!pasteModel.HasPassword)
                            {
                                // Read in the file
                                string subDir   = paste.Paste.FileName[0].ToString();
                                string filePath = Path.Combine(_config.PasteConfig.PasteDirectory, subDir, paste.Paste.FileName);
                                if (!System.IO.File.Exists(filePath))
                                {
                                    continue;
                                }

                                byte[] ivBytes  = Encoding.Unicode.GetBytes(paste.Paste.IV);
                                byte[] keyBytes = AesCounterManaged.CreateKey(paste.Paste.Key, ivBytes, paste.Paste.KeySize);
                                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                                    using (AesCounterStream cs = new AesCounterStream(fs, false, keyBytes, ivBytes))
                                        using (StreamReader sr = new StreamReader(cs, Encoding.Unicode))
                                        {
                                            pasteModel.Content = await sr.ReadToEndAsync();
                                        }
                            }

                            model.Items.Add(pasteModel);
                        }
                    }
                }

                return(View(model));
            }
            return(new StatusCodeResult(StatusCodes.Status404NotFound));
        }