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 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.º 4
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);
        }