コード例 #1
0
 public ActionResult Create([Bind(Exclude = "BlogId")] BlogPostModel post, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         //BlogManager.Create(JsonConvert.SerializeObject(post));
         WebsiteDatabase db = new WebsiteDatabase();
         BlogPostModel   b  = new BlogPostModel();
         if (image != null)
         {
             post.Image = Guid.NewGuid().ToString() + Path.GetExtension(image.FileName);
             image.SaveAs(Server.MapPath(@"~\img\" + @"\" + post.Image));
             ViewBag.Pic = image;
             post.Date   = DateTime.Now;
             db.BlogPostModels.Add(post);
             db.SaveChanges();
             return(RedirectToAction("BlogIndex"));
         }
         else
         {
             post.Date = DateTime.Now;
             db.BlogPostModels.Add(post);
             db.SaveChanges();
             return(RedirectToAction("BlogIndex"));
         }
     }
     else
     {
         return(View(post));
     }
 }
コード例 #2
0
        public ActionResult Create([Bind(Include = "ProjectId,ClientId,TypeOfWork,Cost,Date,Duration,Address,City,State,Zip")] Project project)
        {
            if (ModelState.IsValid)
            {
                db.Projects.Add(project);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(project));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "ClientId,FirstName,LastName,Address,City,State,Zip,PhoneNumber,email")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
コード例 #4
0
        public ActionResult Delete(int id)
        {
            WebsiteDatabase db   = new WebsiteDatabase();
            var             blog = from b in db.BlogPostModels
                                   where b.BlogId.Equals(id)
                                   select b;

            foreach (var b in blog)
            {
                db.BlogPostModels.Remove(b);
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(RedirectToAction("BlogIndex"));
        }
コード例 #5
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            BlogPostModel blog = db.BlogPostModels.Find(id);

            try
            {
                UpdateModel(blog);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = blog.BlogId }));
            }
            catch
            {
                return(View("BlogIndex"));
            }

            /*if (ModelState.IsValid)
             * {
             *  UpdateModel(blog);
             *  db.SaveChanges();
             *  return RedirectToAction("BlogIndex");
             * }
             * return View(blog);*/
        }