Inheritance: System.Web.UI.Page
示例#1
0
        [Route("Read/{id}")] // Set the ID parameter
        public ActionResult Read(int id)
        {
            // Read one single blog
            LoginDatabaseEntites db = new LoginDatabaseEntites();
            var   blogs             = db.blogs;
            blogs post = null;

            if (blogs != null && blogs.Count() > 0)
            {
                post = blogs.Where(x => x.blogid == id).FirstOrDefault();
            }

            if (post == null)
            {
                ViewBag.PostFound = false;
                return(View());
            }
            else
            {
                var    categId    = post.kategorija;
                string kategorija = db.categories.Where(x => x.CatId == categId).Select(x => x.naslov_kategorije).Single();
                ViewBag.Categories = kategorija;
                ViewBag.PostFound  = true;
                return(View(post));
            }
        }
示例#2
0
        // GET: Posts/Create
        public ActionResult Create()
        {
            LoginDatabaseEntites db = new LoginDatabaseEntites();

            if (Request.HttpMethod == "POST")
            {
                var naslov   = Request.Form["title"].ToString();
                var vsebina  = Request.Form["content"].ToString();
                var category = Convert.ToInt32(Request.Form["kategorija"]);
                var path     = Path.Combine("/assets/images", "wha.jpg");
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    var fileName            = Guid.NewGuid().ToString() + Path.GetFileName(file.FileName);
                    path = Path.Combine("/assets/images", fileName);
                    path.ToList();
                    file.SaveAs(Server.MapPath(path));
                }
                DateTime date2 = (DateTime) new SqlDateTime(DateTime.Now);
                var      temp  = new DateTime().Date.ToString("yyyy-MM-dd HH:mm:ss");
                blogs    novi  = new blogs()
                {
                    title      = naslov,
                    content    = vsebina,
                    kategorija = category,
                    Imagepath  = path
                };

                db.blogs.Add(novi);
                db.SaveChanges();
                return(RedirectToAction("Index", "cms"));
            }
            ViewBag.AppDataApplicationType = new SelectList(db.categories, "CatId", "naslov_kategorije");
            return(View());
        }
示例#3
0
        // PUT: api/BlogDetails/5
        public void Put(int id, [FromBody] blogs value)
        {
            var posodobi = db.blogs.FirstOrDefault(x => x.blogid == id);
            var naslov   = value.title;
            var vsebina  = value.content;
            var category = value.kategorija;

            posodobi.content    = vsebina;
            posodobi.title      = naslov;
            posodobi.kategorija = category;
            db.SaveChanges();
        }
示例#4
0
        public void TestHelperGetEntityEntryKeyPairs1()
        {
            blogs _blogs = samplemodel.Blogs.FirstOrDefault(a => a.blogs_title == "Blog1");

            IDictionary <string, object> expected = new Dictionary <string, object>()
            {
                { "blogs_id", _blogs.blogs_id }
            };
            IDictionary <string, object> actual = samplemodel.Blogs.Helper.GetKeyPairs(_blogs);

            Assert.That(expected, Is.EqualTo(actual));
        }
示例#5
0
        public void AddTestData()
        {
            ClearData();

            blogs _blogs = null;

            //add blog
            _blogs                   = new blogs();
            _blogs.blogs_title       = "Blog1";
            _blogs.blogs_description = "test description";
            samplemodel.Blogs.Add(_blogs);
        }
示例#6
0
        // POST: api/BlogDetails
        public void Post([FromBody] blogs value)
        {
            var   naslov    = value.title;
            var   vsebina   = value.content;
            var   category  = value.kategorija;
            var   imagepath = (value.Imagepath != null) ? value.Imagepath : "https://workhardanywhere.com/wp-content/uploads/2014/11/WHA_marvin_king_ashore.jpg";
            blogs novi      = new blogs()
            {
                title      = naslov,
                content    = vsebina,
                kategorija = category,
                Imagepath  = imagepath
            };

            db.blogs.Add(novi);
            db.SaveChanges();
        }