Exemplo n.º 1
0
        public ActionResult AddItem(Item item)
        {
            ViewBag.Message = "Add item";

            List<Item> items = new List<Item>();

            using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
            {
                ctx.Items.Add(item);
                ctx.SaveChanges();

                items = ctx.Items.ToList();
            }
            return View("Items", items);
        }
Exemplo n.º 2
0
        public ActionResult CreateFile(HttpPostedFileBase upload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (upload != null && upload.ContentLength > 0)
                    {
                        var file = new File
                        {
                            FileName = System.IO.Path.GetFileName(upload.FileName),
                            FileType = FileType.Avatar,
                            ContentType = upload.ContentType
                        };
                        using (var reader = new System.IO.BinaryReader(upload.InputStream))
                        {
                            file.Content = reader.ReadBytes(upload.ContentLength);
                        }
                        using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
                        {
                            ctx.Files.Add(file);
                            ctx.SaveChanges();
                        }

                        return RedirectToAction("Files");
                    }
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return View(new File());
        }
Exemplo n.º 3
0
        public ActionResult GetFileContent(string id)
        {
            ViewBag.Message = "File";

            File item;

            using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
            {
                item = ctx.Files.Find(int.Parse(id));
            }

            return File(item.Content, item.ContentType);
        }
Exemplo n.º 4
0
 public ActionResult Items(IEnumerable<Item> items)
 {
     ViewBag.Message = "Your items";
     if (items == null)
     {
         using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
         {
             items = ctx.Items.ToList();
         }
     }
     return View(items);
 }
Exemplo n.º 5
0
        public ActionResult GetFile(string id)
        {
            ViewBag.Message = "File";

            File item;

            using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
            {
                item = ctx.Files.Find(int.Parse(id));
            }

            return View(new ViewModelFile
            {
                Id = item.Id,
                FileType = item.FileType,
                FileName = item.FileName
            });
        }
Exemplo n.º 6
0
        //------------ FILES ---------------------------------
        public ActionResult Files([Bind(Include = "FileName, ContentType, FileType")]IEnumerable<ViewModelFile> files)
        {
            ViewBag.Message = "Your files";
            IEnumerable<ViewModelFile> vmfiles;
            if (files == null)
            {
                using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
                {
                    var result = ctx.Files.ToList();

                    vmfiles = result.Select(fi => new ViewModelFile
                    {
                        Id = fi.Id,
                        FileName = fi.FileName,
                        ContentType = fi.ContentType,
                        FileType = fi.FileType
                    });
                }
            }
            else
            {
                vmfiles = files.Select(fi => new ViewModelFile
                {
                    Id = fi.Id,
                    FileName = fi.FileName,
                    ContentType = fi.ContentType,
                    FileType = fi.FileType
                });
            }
            return View(vmfiles);
        }
Exemplo n.º 7
0
        public ActionResult EditItem(Item item)
        {
            using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
            {
                ctx.Entry(item).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
            }

            return View("EditItemConfirm", item);
        }
Exemplo n.º 8
0
        //------------EDIT-----------------------------------
        public ActionResult EditItem(string id)
        {
            ViewBag.Message = "Edit item";

            Item item;

            using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
            {
                item = ctx.Items.Find(int.Parse(id));
            }

            return View(item);
        }
Exemplo n.º 9
0
        public ActionResult DeleteItem(Item item)
        {
            // //set to delete
            // http://stackoverflow.com/questions/15945172/the-object-cannot-be-deleted-because-it-was-not-found-in-the-objectstatemanager
            ViewBag.Message = "Item was deleted.";

            using (var ctx = new HunterDbContext(ConfigurationManager.AppSettings["AzureHunterDatabaseCnn"]))
            {
                ctx.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                ctx.Items.Remove(item);
                ctx.SaveChanges();
            }

            return View("ItemWasDeleted", item);
        }