Ejemplo n.º 1
0
        public JsonResult ProcessAdd(string cateName)
        {
            cate mycate = new cate();
            var  result = from c in dbContext.cate
                          where c.catname == cateName
                          select c;

            if (result.Count() > 0)
            {
                return(Json(new { status = 0, data = "该分类已存在,请重新输入!" }));
            }
            else
            {
                mycate.catname = cateName;
                dbContext.cate.Add(mycate);
                if (dbContext.SaveChanges() != 0)
                {
                    return(Json(new { status = 1, data = "添加成功" }));
                }
                else
                {
                    return(Json(new { status = 0, data = "添加失败" }));
                }
            }
        }
Ejemplo n.º 2
0
        public JsonResult ProcessAdd(string title, string url, string desc)
        {
            link mylink = new link();
            var  result = from l in dbContext.link
                          where l.title == title
                          select l;

            if (result.Count() > 0)
            {
                return(Json(new { status = 0, data = "该友情链接已存在,请重新输入!" }));
            }
            else
            {
                mylink.title = title;
                mylink.url   = url;
                mylink.desc  = desc;
                dbContext.link.Add(mylink);
                if (dbContext.SaveChanges() != 0)
                {
                    return(Json(new { status = 1, data = "添加成功" }));
                }
                else
                {
                    return(Json(new { status = 0, data = "添加失败" }));
                }
            }
        }
        public JsonResult ProcessAdd(string title, int catid, string author, string desc, string content)
        {
            article myarticle = new article();

            myarticle.title   = title;
            myarticle.cateid  = catid;
            myarticle.content = content;
            myarticle.desc    = desc;
            myarticle.time    = DateTime.Now;
            var result = from a in dbContext.admin
                         where a.username == author
                         select a;

            foreach (var a in result)
            {
                myarticle.creator = a.id;
            }
            dbContext.article.Add(myarticle);
            if (dbContext.SaveChanges() != 0)
            {
                return(Json(new { status = 1, data = "添加成功!" }));
            }
            else
            {
                return(Json(new { status = 0, data = "添加失败!" }));
            }
        }
Ejemplo n.º 4
0
 public ActionResult Create(int id, Config model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         else
         {
             if (string.IsNullOrEmpty(model.Title) && !string.IsNullOrEmpty(model.Name))
             {
                 model.Title = SEA.Heplers.CreateDefault.CreateDefaultTitle(model.Name);
             }
             var author = Author.GetId(User.Identity.Name);
             model.CreateBy   = author;
             model.EditBy     = author;
             model.CreateDate = DateTime.Now;
             model.EditDate   = DateTime.Now;
             _db.Configs.Add(model);
             _db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(model));
     }
 }
Ejemplo n.º 5
0
        public ActionResult Create(Post post)
        {
            if (ModelState.IsValid)
            {
                db.Posts.Add(post);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "Name", post.AuthorID);
            return(View(post));
        }
Ejemplo n.º 6
0
        public ActionResult Create(Comment comment)
        {
            if (ModelState.IsValid)
            {
                db.Comments.Add(comment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PostID = new SelectList(db.Posts, "PostID", "Username", comment.PostID);
            return(View(comment));
        }
Ejemplo n.º 7
0
        public bool Commit()
        {
            transaction = db.Database.BeginTransaction();
            int affected = db.SaveChanges();

            return(affected > 0);
        }
Ejemplo n.º 8
0
 public ActionResult AddNewUser(string name, string email, string password, string confirm)
 {
     if (IsValidString(name) && IsValidString(password) && IsValidEmail(email) && password == confirm)
     {
         using (var c = new MyBlogEntities())
         {
             byte[] passToByte = StringToBytes(password);
             User newUser = new User
             {
                 Name = name,
                 Email = email,
                 Password = BytesToHash(passToByte),
             };
             User existingUser = c.Users.Where(u => u.Email == email).SingleOrDefault();
             if (existingUser == null)
             {
                 c.Users.Add(newUser);
                 c.SaveChanges();
                 ViewBag.LoginMessage = "User was created successfully.";
                 return View("Index");
             }
             else
             {
                 ViewBag.LoginMessage = "User already exist.";
                 return View("Index");
             }
         }
     }
     else
     {
         ViewBag.LoginMessage = "Invalid data format.";
         return View("Index");
     }
 }
Ejemplo n.º 9
0
 public static void ManyDelete(int idStr)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         link link = db.link.Find(idStr);
         db.link.Remove(link);
         db.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public static void SelectAllDelete(int idStr)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         cate cate = db.cate.Find(idStr);
         db.cate.Remove(cate);
         db.SaveChanges();
     }
 }
Ejemplo n.º 11
0
 public static int IsCheckArticleUpdate(article article)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         db.Entry(article).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(1);
     }
 }
Ejemplo n.º 12
0
 public static void ArticleAllDelete(int ids)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         article article = db.article.Find(ids);
         db.article.Remove(article);
         db.SaveChanges();
     }
 }
Ejemplo n.º 13
0
 public static void CheckDeleteUser(int id)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         var result = db.admin.Find(id);
         db.admin.Remove(result);
         db.SaveChanges();
     }
 }
        public JsonResult CheckModifyPasswd(string user, string pwd, string pwdd)
        {
            var result = from u in dbContext.admin
                         where u.username == user
                         select u;

            foreach (var u in result)
            {
                u.password = pwd;
            }
            if (dbContext.SaveChanges() != 0)
            {
                Session["username"] = null;
                return(Json(new { status = 1, data = "修改成功" }));
            }
            else
            {
                return(Json(new { status = 0, data = "修改失败" }));
            }
        }
Ejemplo n.º 15
0
        public ActionResult Create(Post model, string ListTopic)
        {
            try
            {
                List <Topic> list = ListTopicFromScript(ListTopic);
                if (string.IsNullOrEmpty(model.Title) && !string.IsNullOrEmpty(model.Name))
                {
                    model.Title = SEA.Heplers.CreateDefault.CreateDefaultTitle(model.Name);
                }
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                else
                {
                    var author = Author.GetId(User.Identity.Name);
                    model.CreateBy   = author;
                    model.CreateDate = DateTime.Now;
                    model.EditBy     = author;
                    model.EditDate   = DateTime.Now;
                    _db.Posts.Add(model);
                    _db.SaveChanges();
                    var post = _db.Posts.SingleOrDefault(x => x.Title == model.Title);
                    if (post != null)
                    {
                        foreach (var item in list)
                        {
                            post.Topics.Add(item);
                        }
                    }
                    _db.SaveChanges();
                }
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(model));
            }
        }
Ejemplo n.º 16
0
 public ActionResult DeletePost(int blogId, string blogtitle, int postId)
 {
     using (MyBlogEntities entities = new MyBlogEntities())
     {
         BlogPost blogPost = entities.BlogPosts.Where(e => e.PostID == postId).Select(e => e).First();
         if (blogPost != null)
         {
             entities.BlogPosts.Remove(blogPost);
             entities.SaveChanges();
         }
     }
     return RedirectToAction("GetAllPost", "Post", new { blogId = blogId, blogtitle = blogtitle });
 }
Ejemplo n.º 17
0
 public static int UserAdd(string userName, string pwd)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         admin admin = new admin()
         {
             username = userName,
             password = pwd
         };
         db.admin.Add(admin);
         return(db.SaveChanges());
     }
 }
Ejemplo n.º 18
0
 public static int IsCheckedAddArticle(article article, string author)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         var result = from a in db.admin where a.username == author select a;
         foreach (var item in result)
         {
             article.creator = item.id;
         }
         db.article.Add(article);
         db.SaveChanges();
         return(1);
     }
 }
Ejemplo n.º 19
0
 public static int IsCheckAddCate(cate cate)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         try
         {
             db.cate.Add(cate);
             db.SaveChanges();
             return(1);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Ejemplo n.º 20
0
 public static int CheckUpdateUser(int userId, string pwd)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         try
         {
             var result = db.admin.Find(userId);
             result.password = pwd;
             db.SaveChanges();
             return(1);
         }
         catch (System.Exception)
         {
             throw;
         }
     }
 }
Ejemplo n.º 21
0
 public static int IsCheckLinkAdd(link link)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         var result = from l in db.link where l.title == link.title select l;
         if (result.Count() > 0)
         {
             return(0);
         }
         else
         {
             db.link.Add(link);
             db.SaveChanges();
             return(1);
         }
     }
 }
Ejemplo n.º 22
0
 public static int IsCheckUpdateCate(int cateId, string cateName)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         try
         {
             var result = db.cate.Find(cateId);
             result.catname = cateName;
             db.SaveChanges();
             return(1);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Ejemplo n.º 23
0
 public static void DeleteCate(int id)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         var result  = db.cate.Find(id);
         int cid     = result.id;
         var article = from ar in db.article where ar.cateid == cid select ar;
         if (article.Count() > 0)
         {
             foreach (var item in article)
             {
                 item.cateid = 1;
             }
         }
         db.cate.Remove(result);
         db.SaveChanges();
     }
 }
Ejemplo n.º 24
0
        public ActionResult ÜyeOl(UyeModel model)
        {
            var sn = db.Üye.Where(h => h.KullaniciAdi == model.KullaniciAdi).ToList();

            if (sn.Count() > 0)
            {
                ViewBag.KayıtHata = "Girilen Kullanıcı Adı Kayıtlıdır";
                return(View());
            }
            Üye yeniüye = new Üye();

            if (model.Foto != null && model.Foto.ContentLength > 0)
            {
                string uzanti = Path.GetExtension(model.Foto.FileName).ToLower();
                string dosya  = Guid.NewGuid().ToString();
                if (uzanti != ".jpg" && uzanti != ".jpeg" && uzanti != ".png")
                {
                    ModelState.AddModelError("Foto", "Dosya uzantısı JPG,JPEG veya PNG Olmalıdır!");
                    return(View());
                }
                string dosyaAdi = dosya + uzanti;
                model.Foto.SaveAs(Server.MapPath("~/Content/ÜyeFoto/" + dosyaAdi));
                yeniüye.AdSoyad      = model.AdSoyad;
                yeniüye.Email        = model.Email;
                yeniüye.KullaniciAdi = model.KullaniciAdi;
                yeniüye.Sifre        = model.Sifre;
                yeniüye.Foto         = dosyaAdi;
                yeniüye.UyeId        = new Guid();
            }
            db.Üye.Add(yeniüye);
            db.SaveChanges();

            Üye üye = db.Üye.OrderByDescending(a => a.UyeId).FirstOrDefault();

            Session["UyeOturum"] = true;
            Session["UyeId"]     = üye.UyeId;
            Session["UyeAdi"]    = üye.KullaniciAdi;
            Session["UyeSifre"]  = üye.Sifre;
            Session["UyeAdmin"]  = üye.UyeAdmin;
            Session[",0"]        = üye.Foto;

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 25
0
        public Datacontract.BlogResponse DeleteBlog(Datacontract.BlogRequest request)
        {
            bool result = false;
            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {

                Blog deleteBlog = blog.Blogs.Where(e => e.BlogID == request.Delete.BlogId).Select(e => e).First();
                blog.Blogs.Remove(deleteBlog);
                try
                {
                    blog.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return new Datacontract.BlogResponse() { Result = result ? Datacontract.DBResult.Success : Datacontract.DBResult.Fail };
        }
Ejemplo n.º 26
0
 public static int IsCheckUpdateLinks(int linkId, string title, string url, string desc)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         var result = from l in db.link where l.title == title select l;
         if (result.Count() > 0)
         {
             return(0);
         }
         else
         {
             link link = db.link.Find(linkId);
             link.title           = title;
             link.url             = url;
             link.desc            = desc;
             db.Entry(link).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(1);
         }
     }
 }
Ejemplo n.º 27
0
        public Datacontract.BlogResponse InsertBlog(Datacontract.BlogRequest request)
        {
            bool result = false;

            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {

                foreach (Datacontract.Blog blg in request.Blog)
                {
                    blog.Blogs.Add(new Blog() { Title = blg.Title, Description = blg.Description, TStamp = DateTime.Now });
                }
                try
                {
                    blog.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return new Datacontract.BlogResponse() { Result = result ? Datacontract.DBResult.Success : Datacontract.DBResult.Fail };
        }
Ejemplo n.º 28
0
        public ActionResult InsertPost(Models.Post post, int blogId, string blogtitle)
        {
            using (MyBlogEntities entities = new MyBlogEntities())
            {
                entities.BlogPosts.Add(new BlogPost()
                {
                    BlogID = blogId,
                    Email = post.Email,
                    Name = post.Name,
                    Post = post.BlogPost,
                    TStamp = DateTime.Now
                });

                try
                {
                    entities.SaveChanges();
                    return RedirectToAction("GetAllPost", new { blogId = blogId, blogtitle = blogtitle });
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 29
0
        public Datacontract.PostResponse InsertPost(Datacontract.PostRequest request)
        {
            bool result = false;

            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {
                Datacontract.Post cPost = request.InsertPost;
                BlogPost post = new BlogPost();
                post.BlogID = cPost.BlogID;
                post.Email = cPost.Email;
                post.Name = cPost.Name;
                post.TStamp = DateTime.Now;
                post.Post = cPost.PostDetail;

                blog.BlogPosts.Add(post);

                try
                {
                    blog.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return new Datacontract.PostResponse() { Result = result ? Datacontract.DBResult.Success : Datacontract.DBResult.Fail };

        }
Ejemplo n.º 30
0
        public Datacontract.PostResponse DeletePost(Datacontract.PostRequest request)
        {
            bool result = false;
            if (request.DeletePost.PostID == null && request.DeletePost.PostID.HasValue)
                throw new Exception("Post Id cannot be null");
            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {
                Datacontract.IPost cPost = request.DeletePost;

                BlogPost post = blog.BlogPosts.Where(e => e.BlogID == cPost.PostID).Select(e => e).FirstOrDefault();
                blog.BlogPosts.Remove(post);
                try
                {
                    blog.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return new Datacontract.PostResponse() { Result = result ? Datacontract.DBResult.Success : Datacontract.DBResult.Fail };
        }
Ejemplo n.º 31
0
        public Datacontract.PostResponse UpdatePost(Datacontract.PostRequest request)
        {
            bool result = false;

            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {
                Datacontract.Post cPost = request.UpdatePost;
                BlogPost post = blog.BlogPosts.Where(e => e.BlogID == cPost.BlogID).Select(e => e).FirstOrDefault();
                if (post != null)
                {
                    post.BlogID = cPost.BlogID;
                    post.Email = cPost.Email;
                    post.Name = cPost.Name;
                    post.TStamp = DateTime.Now;
                    post.Post = cPost.PostDetail;
                }
                try
                {
                    blog.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return new Datacontract.PostResponse() { Result = result ? Datacontract.DBResult.Success : Datacontract.DBResult.Fail };
        }