Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Url")] Blogs blogs)
        {
            if (id != blogs.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blogs);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlogsExists(blogs.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blogs));
        }
Exemple #2
0
        public HttpResponseMessage CreateBlog(Blogs model)
        {
            BlogsService blogSvc = new BlogsService();
            int          id      = blogSvc.CreateBlog(model);

            return(Request.CreateResponse(HttpStatusCode.OK, id));
        }
Exemple #3
0
        public HttpResponseMessage UpdateBlog([FromUri] int id, [FromBody] Blogs model)
        {
            BlogsService blogSvc = new BlogsService();

            blogSvc.UpdateBlog(id, model);
            return(Request.CreateResponse(HttpStatusCode.OK, id));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,Url")] Blogs blogs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blogs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blogs));
        }
Exemple #5
0
        public ActionResult Create(BlogViewModel model, HttpPostedFileBase photoFile)
        {
            var _blog = new Blogs();

            _blog.Title    = model.Title;
            _blog.Content  = model.Content;
            _blog.PostDate = DateTime.Now;

            if (photoFile != null)
            {
                _blog.Photo = $@"{DateTime.UtcNow.Ticks}_{photoFile.FileName}";
                //_blog.Photo = $@"{Guid.NewGuid()}{photoFile.FileName}";

                var path = Path.Combine(Server.MapPath("~/Content/Upload/Photos"), _blog.Photo);
                photoFile.SaveAs(path);
            }

            BlogDataContext _context = new BlogDataContext();

            _context.Blogs.Add(_blog);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }