Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Title,Content,Created")] News news)
        {
            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("index", "home"));
            }
            if (ModelState.IsValid)
            {
                var tc = getTenantControl();
                if (tc.Id != -1)
                {
                    using (var connection = new SqlConnection(tc.TenantConnection))
                    {
                        TenantConnection.ProvisionTenant(tc.TenantSchema, connection);
                        using (var ctx = TenantConnection.Create(tc.TenantSchema, connection))
                        {
                            ctx.News.Add(news);
                            ctx.SaveChanges();
                            return(RedirectToAction("index"));
                        }
                    }
                }
            }

            return(View(news));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("index", "home"));
            }

            var news = new List <News>();
            var tc   = getTenantControl();

            if (tc == null)
            {
                return(RedirectToAction("index", "home"));
            }
            if (tc.Id != -1)
            {
                using (var connection = new SqlConnection(tc.TenantConnection)){
                    TenantConnection.ProvisionTenant(tc.TenantSchema, connection);
                    using (var ctx = TenantConnection.Create(tc.TenantSchema, connection)){
                        news = ctx.News.ToList();
                    }
                }
            }
            return(View(news));
        }
Exemplo n.º 3
0
        public ActionResult Delete(int?id)
        {
            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("index", "home"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            News news = null;

            var tc = getTenantControl();

            if (tc.Id != -1)
            {
                using (var connection = new SqlConnection(tc.TenantConnection))
                {
                    TenantConnection.ProvisionTenant(tc.TenantSchema, connection);
                    using (var db = TenantConnection.Create(tc.TenantSchema, connection))
                    {
                        news = db.News.Find(id);
                    }
                }
            }

            if (news == null)
            {
                return(HttpNotFound());
            }
            return(View(news));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("index", "home"));
            }
            var tc = getTenantControl();

            if (checkNull(tc))
            {
                return(RedirectToAction("index", "home"));
            }


            if (tc.Id != -1)
            {
                using (var connection = new SqlConnection(tc.TenantConnection))
                {
                    TenantConnection.ProvisionTenant(tc.TenantSchema, connection);
                    using (var db = TenantConnection.Create(tc.TenantSchema, connection))
                    {
                        News news = db.News.Find(id);
                        db.News.Remove(news);
                        db.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit([Bind(Include = "Id,Title,Content,Created")] News news)
        {
            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("index", "home"));
            }
            if (ModelState.IsValid)
            {
                var tc = getTenantControl();

                if (tc == null)
                {
                    return(RedirectToAction("index", "home"));
                }

                if (tc.Id != -1)
                {
                    using (var connection = new SqlConnection(tc.TenantConnection))
                    {
                        TenantConnection.ProvisionTenant(tc.TenantSchema, connection);
                        using (var db = TenantConnection.Create(tc.TenantSchema, connection))
                        {
                            db.Entry(news).State = EntityState.Modified;
                            db.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                    }
                }
            }
            return(View(news));
        }
Exemplo n.º 6
0
        /// <summary>
        /// This saves and re-loads a file just like Test1 but it used a TenantConnection for simpler syntax
        /// </summary>
        private static void Test2()
        {
            const string TenantName = "Test1";

            using (var service = new TenantConnection(TenantName, Container))
            {
                service.FileUpload   += (object sender, FileProgressEventArgs e) => Console.WriteLine("Upload " + e.ChunkIndex + " of " + e.TotalChunks);
                service.FileDownload += (object sender, FileProgressEventArgs e) => Console.WriteLine("Download " + e.ChunkIndex);

                //This is the plain text file to test
                var plainFile = @"c:\temp\test.txt";

                //Save the file (the file name is the key)
                service.SaveFile(plainFile);

                //Retrieve the file from storage (file name is just the key)
                var fileResults = service.GetFile(plainFile);

                //Write to decrypted file
                //In the real world you could work with the stream in memory
                //such that the plaintext fiel never touches disk
                var tempFile = fileResults.ToFile();

                //Compare the original and download file
                var isEqual = FileUtilities.FilesAreEqual(plainFile, tempFile);
                if (isEqual)
                {
                    Console.WriteLine("Files match");
                }
                else
                {
                    Console.WriteLine("ERROR: Files do not match!");
                }
                Debug.Assert(isEqual);

                //Remove the file from storage (the file name is the key)
                service.RemoveFile(plainFile);

                //Remove the plaintext temp file
                FileUtilities.WipeFile(tempFile);
            }
        }