Beispiel #1
0
        public ActionResult Edit(ArticleViewModel article, HttpPostedFileBase[] uploads)
        {
            CheckFiles(uploads);

            if (ModelState.IsValid)
            {
                var instance = db.Article.FirstOrDefault(x => x.ID == article.ID);

                instance.CategoryID  = article.CategoryID;
                instance.Subject     = article.Subject;
                instance.Summary     = article.Summary;
                instance.ContentText = article.ContentText;
                instance.IsPublish   = article.IsPublish;
                instance.PublishDate = article.PublishDate;
                instance.UpdateUser  = WebSiteHelper.CurrentUserID;
                instance.UpdateDate  = DateTime.Now;

                HandleFiles(instance, uploads);

                db.Entry(instance).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryID = new SelectList(db.Category, "ID", "Name", article.CategoryID);
            return(View(article));
        }
        public ActionResult Edit(SystemUser systemuser)
        {
            //檢查登入帳號是否重複
            if (db.SystemUser.Any(x => x.ID != systemuser.ID && x.Account == systemuser.Account))
            {
                ModelState.AddModelError("Account", "登入帳號不可重複");
                return(View(systemuser));
            }

            if (ModelState.IsValid)
            {
                SystemUser user = db.SystemUser.FirstOrDefault(x => x.ID == systemuser.ID);

                if (!string.IsNullOrWhiteSpace(systemuser.Password))
                {
                    user.Salt     = GenerateSalt();
                    user.Password = CryptographyPassword(systemuser.Password, systemuser.Salt);
                }

                user.Name    = systemuser.Name;
                user.Account = systemuser.Account;
                user.Email   = systemuser.Email;

                user.UpdateUser = WebSiteHelper.CurrentUserID;
                user.UpdateDate = DateTime.Now;

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(systemuser));
        }
Beispiel #3
0
        public ActionResult Edit(Category category)
        {
            if (db.Category.Any(x => x.ID != category.ID && x.Name == category.Name))
            {
                ModelState.AddModelError("Name", "文章分類名稱不可重複");
                return(View(category));
            }

            if (ModelState.IsValid)
            {
                var original = db.Category.FirstOrDefault(x => x.ID == category.ID);

                original.Name       = category.Name;
                original.UpdateUser = WebSiteHelper.CurrentUserID;
                original.UpdateDate = DateTime.Now;

                db.Entry(original).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
 /// <summary>
 /// 增加文章瀏覽次數
 /// </summary>
 /// <param name="article">The article.</param>
 private void IncreaseViewCount(Article article)
 {
     article.ViewCount      += 1;
     db.Entry(article).State = EntityState.Modified;
     db.SaveChanges();
 }