Exemplo n.º 1
0
        public ActionResult Image(AddImageViewModel vm)
        {

            if (ModelState.IsValid)
            {
                var genpath = "~/Content/uploads/";

                // Save Image to System
                string picture = System.IO.Path.GetFileName(vm.Image.FileName);
                string path = System.IO.Path.Combine(Server.MapPath(genpath), picture ?? "");
                // file is uploaded
                vm.Image.SaveAs(path);

                //using (MemoryStream ms = new MemoryStream())
                //{
                //    vm.Image.InputStream.CopyTo(ms);
                //    byte[] array = ms.GetBuffer();
                //}

                Entry entry = new Entry
                {
                    AccountId = GetSUD(),
                    Active = 1,
                    Content = vm.Content,
                    Created = DateTime.Now,
                    TypeId = (int)EntryTypeEnum.Image,
                    MediaURL = picture,
                    SourceURL = vm.SourceURL ?? "",
                    Title = vm.Title
                };

                Rep.AddEntry(entry);
                Rep.Save();

                return RedirectToAction("Access", "Add", entry);
            }

            return View(vm);
        }
        public ActionResult Image(AddImageViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var genpath = "~/Content/uploads/";

                // Save Image to System
                string picture = System.IO.Path.GetFileName(vm.Image.FileName);

                // check image has a valid extension
                if (CheckValidImage(picture))
                {
                    string path = System.IO.Path.Combine(Server.MapPath(genpath), picture ?? "");
                    // file is uploaded
                    vm.Image.SaveAs(path);

                    // Crate new Entry
                    Entry entry = new Entry
                    {
                        AccountId = GetSUD(),
                        Active = 1,
                        Content = vm.Content,
                        Created = DateTime.Now,
                        TypeId = (int)EntryTypeEnum.Image,
                        MediaURL = picture,
                        SourceURL = vm.SourceURL ?? "",
                        Title = vm.Title
                    };

                    Rep.AddEntry(entry);
                    Rep.Save();

                    // return next stage of adding entry: defining access to post
                    return RedirectToAction("Access", "Add", entry);
                }
            }

            return View(vm);
        }